| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539 | 
							- <?php
 
- class ContextConditionUserTest extends DrupalWebTestCase {
 
-   protected $profile = 'testing';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: user',
 
-       'description' => 'Test user condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools');
 
-     $this->user1 = $this->drupalCreateUser(array('access content', 'administer site configuration'));
 
-     $this->user2 = $this->drupalCreateUser(array('access content'));
 
-     // The role name is not reliably put on the user object. Retrive from
 
-     // user_roles().
 
-     $role = '';
 
-     foreach (array_keys($this->user1->roles) as $rid) {
 
-       if ($rid !== DRUPAL_AUTHENTICATED_RID) {
 
-         $role = user_role_load($rid)->name;
 
-         break;
 
-       }
 
-     }
 
-     // Create test context.
 
-     ctools_include('export');
 
-     $this->context = ctools_export_new_object('context');
 
-     $this->context->name = 'testcontext';
 
-     $this->context->conditions = array('user' => array('values' => array($role)));
 
-     $this->context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($this->context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-   }
 
-   function test() {
 
-     // User 1 triggers the context.
 
-     $this->drupalLogin($this->user1);
 
-     $this->drupalGet('node');
 
-     $this->assertText('Active context: testcontext');
 
-     // User 2 does not.
 
-     $this->drupalLogin($this->user2);
 
-     $this->drupalGet('node');
 
-     $this->assertNoText('Active context: testcontext');
 
-   }
 
- }
 
- class ContextConditionUserPageTest extends DrupalWebTestCase {
 
-   protected $profile = 'testing';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: user page',
 
-       'description' => 'Test user page condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools');
 
-     $this->user1 = $this->drupalCreateUser(array('access user profiles', 'access content', 'administer site configuration'));
 
-     $this->user2 = $this->drupalCreateUser(array('access user profiles', 'access content'));
 
-     // Create test context.
 
-     ctools_include('export');
 
-     $this->context = ctools_export_new_object('context');
 
-     $this->context->name = 'testcontext';
 
-     $this->context->conditions = array('user_page' => array('values' => array('view' => 'view'), 'options' => array('mode' => 'all')));
 
-     $this->context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($this->context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-   }
 
-   function test() {
 
-     // Viewing any user profile triggers context.
 
-     $this->drupalLogin($this->user1);
 
-     $this->drupalGet("user/{$this->user1->uid}");
 
-     $this->assertText('Active context: testcontext');
 
-     $this->drupalGet("user/{$this->user2->uid}");
 
-     $this->assertText('Active context: testcontext');
 
-     // User form does not.
 
-     $this->drupalGet("user/{$this->user1->uid}/edit");
 
-     $this->assertNoText('Active context: testcontext');
 
-     // Test current user mode
 
-     $this->context->conditions['user_page']['options']['mode'] = 'current';
 
-     $saved = context_save($this->context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet("user/{$this->user1->uid}");
 
-     $this->assertText('Active context: testcontext');
 
-     $this->drupalGet("user/{$this->user2->uid}");
 
-     $this->assertNoText('Active context: testcontext');
 
-     // Test other user mode
 
-     $this->context->conditions['user_page']['options']['mode'] = 'other';
 
-     $saved = context_save($this->context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet("user/{$this->user1->uid}");
 
-     $this->assertNoText('Active context: testcontext');
 
-     $this->drupalGet("user/{$this->user2->uid}");
 
-     $this->assertText('Active context: testcontext');
 
-   }
 
- }
 
- class ContextConditionNodeTaxonomyTest extends DrupalWebTestCase {
 
-   // We want the default taxonomy and content types created
 
-   protected $profile = 'standard';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: taxonomy',
 
-       'description' => 'Test taxonomy condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools', 'taxonomy');
 
-     $admin_user = $this->drupalCreateUser(array('administer site configuration', 'create article content'));
 
-     $this->drupalLogin($admin_user);
 
-     // Create test terms.
 
-     $this->vocab = taxonomy_vocabulary_machine_name_load('tags');
 
-     $this->terms = array();
 
-     $this->terms['apples'] = (object)array('name' => 'apples', 'vid' => $this->vocab->vid);
 
-     $this->terms['oranges'] = (object)array('name' => 'oranges', 'vid' => $this->vocab->vid);
 
-     taxonomy_term_save($this->terms['apples']);
 
-     taxonomy_term_save($this->terms['oranges']);
 
-     // Create test context.
 
-     ctools_include('export');
 
-     $this->context = ctools_export_new_object('context');
 
-     $this->context->name = 'testcontext';
 
-     $this->context->conditions = array('node_taxonomy' => array('values' => array($this->terms['apples']->tid)));
 
-     $this->context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($this->context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-   }
 
-   function test() {
 
-     // Apples does trigger the context.
 
-     $edit = array(
 
-       'title' => 'Apples', 
 
-       'field_tags[und]' => $this->terms['apples']->name
 
-     );
 
-     $this->drupalPost('node/add/article', $edit, t('Save'));
 
-     $node = $this->drupalGetNodeByTitle($edit['title']);
 
-     $this->drupalGet('node/' . $node->nid);
 
-     $this->assertText('Active context: testcontext');
 
-     // Oranges does not trigger the context.
 
-     $edit = array(
 
-       'title' => 'Oranges', 
 
-       'field_tags[und]' => $this->terms['oranges']->name
 
-     );
 
-     $this->drupalPost('node/add/article', $edit, t('Save'));
 
-     $node = $this->drupalGetNodeByTitle($edit['title']);
 
-     $this->drupalGet('node/' . $node->nid);
 
-     $this->assertNoText('Active context: testcontext');
 
-   }
 
- }
 
- class ContextConditionLanguageTest extends DrupalWebTestCase {
 
-   protected $profile = 'testing';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: language',
 
-       'description' => 'Test language condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools', 'locale');
 
-     $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer languages'));
 
-     $this->drupalLogin($admin_user);
 
-     $this->drupalPost('admin/config/development/performance', array(), t('Clear all caches'));
 
-     // Set up Spanish as second language.
 
-     $this->drupalPost('admin/config/regional/language/add', array('langcode' => 'es'), t('Add language'));
 
-     $this->drupalPost('admin/config/regional/language/configure', array('language[enabled][locale-url]' => 1), t('Save settings'));
 
-   }
 
-   function test() {
 
-     ctools_include('export');
 
-     $context = ctools_export_new_object('context');
 
-     $context->name = 'testcontext';
 
-     $context->conditions = array('language' => array('values' => array('es')));
 
-     $context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet('node');
 
-     $this->assertNoText('Active context: testcontext');
 
-     $this->drupalGet('es/node');
 
-     $this->assertText('Active context: testcontext');
 
-     // Cleanup
 
-     context_delete($context);
 
-   }
 
- }
 
- class ContextConditionSitewideTest extends DrupalWebTestCase {
 
-   protected $profile = 'testing';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: sitewide',
 
-       'description' => 'Test sitewide condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools');
 
-     $admin_user = $this->drupalCreateUser(array('administer site configuration'));
 
-     $this->drupalLogin($admin_user);
 
-   }
 
-   function test() {
 
-     ctools_include('export');
 
-     $context = ctools_export_new_object('context');
 
-     $context->name = 'testcontext';
 
-     $context->conditions = array('sitewide' => array('values' => array(1)));
 
-     $context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet('node');
 
-     $this->assertText('Active context: testcontext');
 
-     // Cleanup
 
-     context_delete($context);
 
-   }
 
- }
 
- class ContextConditionPathTest extends DrupalWebTestCase {
 
-   protected $profile = 'testing';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: path',
 
-       'description' => 'Test path condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools', 'path');
 
-     $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer nodes'));
 
-     $this->drupalLogin($admin_user);
 
-   }
 
-   function test() {
 
-     ctools_include('export');
 
-     $context = ctools_export_new_object('context');
 
-     $context->name = 'testcontext';
 
-     $context->conditions = array('path' => array('values' => array('admin', 'node/*')));
 
-     $context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet('admin');
 
-     $this->assertText('Active context: testcontext');
 
-     $node = $this->drupalCreateNode();
 
-     $this->drupalGet("node/{$node->nid}");
 
-     $this->assertText('Active context: testcontext');
 
-     $this->drupalGet('node');
 
-     $this->assertNoText('Active context: testcontext');
 
-     // Cleanup
 
-     context_delete($context);
 
-     // @TODO: Test with path alias
 
-     // @TODO: Test with language prefixes
 
-   }
 
- }
 
- class ContextConditionContextTest extends DrupalWebTestCase {
 
-   protected $profile = 'testing';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: context',
 
-       'description' => 'Test context condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools');
 
-     $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer nodes'));
 
-     $this->drupalLogin($admin_user);
 
-   }
 
-   function test() {
 
-     ctools_include('export');
 
-     $context = ctools_export_new_object('context');
 
-     $context->name = 'testcontext';
 
-     $context->conditions = array('path' => array('values' => array('admin')));
 
-     $context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $subcontext = ctools_export_new_object('context');
 
-     $subcontext->name = 'subcontext';
 
-     $subcontext->conditions = array('context' => array('values' => array('testcontext')));
 
-     $subcontext->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($subcontext);
 
-     $this->assertTrue($saved, "Context 'subcontext' saved.");
 
-     $this->drupalGet('admin');
 
-     $this->assertText('Active context: testcontext');
 
-     $this->assertText('Active context: subcontext');
 
-     // Cleanup
 
-     context_delete($context);
 
-     // @TODO: Test exclusion
 
-   }
 
- }
 
- class ContextConditionNodeTest extends DrupalWebTestCase {
 
-   protected $profile = 'testing';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: node',
 
-       'description' => 'Test node condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools', 'blog', 'book');
 
-     $admin_user = $this->drupalCreateUser(array(
 
-       'administer site configuration',
 
-       'administer nodes',
 
-       'create blog content',
 
-       'create book content'
 
-     ));
 
-     $this->drupalLogin($admin_user);
 
-   }
 
-   function test() {
 
-     ctools_include('export');
 
-     $context = ctools_export_new_object('context');
 
-     $context->name = 'testcontext';
 
-     $context->conditions = array('node' => array('values' => array('blog')));
 
-     $context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet("node/add/blog");
 
-     $this->assertNoText('Active context: testcontext');
 
-     $this->drupalGet("node/add/book");
 
-     $this->assertNoText('Active context: testcontext');
 
-     $node = $this->drupalCreateNode(array('type' => 'blog'));
 
-     $this->drupalGet("node/{$node->nid}");
 
-     $this->assertText('Active context: testcontext');
 
-     $node = $this->drupalCreateNode(array('type' => 'book'));
 
-     $this->drupalGet("node/{$node->nid}");
 
-     $this->assertNoText('Active context: testcontext');
 
-     $context->conditions['node']['options']['node_form'] = 1;
 
-     $saved = context_save($context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet("node/add/blog");
 
-     $this->assertText('Active context: testcontext');
 
-     $this->drupalGet("node/add/book");
 
-     $this->assertNoText('Active context: testcontext');
 
-     // Cleanup
 
-     context_delete($context);
 
-   }
 
- }
 
- class ContextConditionMenuTest extends DrupalWebTestCase {
 
-   protected $profile = 'testing';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: menu',
 
-       'description' => 'Test menu condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools', 'blog', 'menu');
 
-     $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer nodes', 'create blog content'));
 
-     $this->drupalLogin($admin_user);
 
-   }
 
-   function test() {
 
-     ctools_include('export');
 
-     $context = ctools_export_new_object('context');
 
-     $context->name = 'testcontext';
 
-     $context->conditions = array('menu' => array('values' => array('node/add')));
 
-     $context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet("node/add/blog");
 
-     $this->assertText('Active context: testcontext');
 
-     $this->drupalGet("node/add");
 
-     $this->assertText('Active context: testcontext');
 
-     $this->drupalGet("node");
 
-     $this->assertNoText('Active context: testcontext');
 
-     // Cleanup
 
-     context_delete($context);
 
-   }
 
- }
 
- class ContextConditionBookTest extends DrupalWebTestCase {
 
-   protected $profile = 'testing';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: book',
 
-       'description' => 'Test book condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools', 'book', 'menu');
 
-     $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer nodes'));
 
-     $this->drupalLogin($admin_user);
 
-   }
 
-   function test() {
 
-     $book = $this->drupalCreateNode(array('type' => 'book', 'book' => array('bid' => 'new')));
 
-     $child = $this->drupalCreateNode(array('type' => 'book', 'book' => array('bid' => $book->nid)));
 
-     $dummy = $this->drupalCreateNode(array('type' => 'book'));
 
-     ctools_include('export');
 
-     $context = ctools_export_new_object('context');
 
-     $context->name = 'testcontext';
 
-     $context->conditions = array('book' => array('values' => array(book_menu_name($book->book['bid']))));
 
-     $context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet("node/{$book->nid}");
 
-     $this->assertText('Active context: testcontext');
 
-     $this->drupalGet("node/{$child->nid}");
 
-     $this->assertText('Active context: testcontext');
 
-     $this->drupalGet("node/{$dummy->nid}");
 
-     $this->assertNoText('Active context: testcontext');
 
-     // Cleanup
 
-     context_delete($context);
 
-   }
 
- }
 
- class ContextConditionBookroot extends DrupalWebTestCase {
 
-   protected $profile = 'testing';
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Condition: bookroot',
 
-       'description' => 'Test bookroot condition.',
 
-       'group' => 'Context',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('context', 'ctools', 'book', 'menu');
 
-     $admin_user = $this->drupalCreateUser(array(
 
-       'administer site configuration',
 
-       'administer nodes',
 
-       'create book content',
 
-       'edit any book content',
 
-     ));
 
-     $this->drupalLogin($admin_user);
 
-     variable_set('book_allowed_types', array('book', 'page'));
 
-   }
 
-   function test() {
 
-     $book = $this->drupalCreateNode(array('type' => 'book', 'book' => array('bid' => 'new')));
 
-     $child = $this->drupalCreateNode(array('type' => 'book', 'book' => array('bid' => $book->nid)));
 
-     $dummy = $this->drupalCreateNode(array('type' => 'page', 'book' => array('bid' => 'new')));
 
-     $dummy_child = $this->drupalCreateNode(array('type' => 'page', 'book' => array('bid' => $dummy->nid)));
 
-     ctools_include('export');
 
-     $context = ctools_export_new_object('context');
 
-     $context->name = 'testcontext';
 
-     $context->conditions = array('bookroot' => array('values' => array('book')));
 
-     $context->reactions = array('debug' => array('debug' => TRUE));
 
-     $saved = context_save($context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet("node/{$book->nid}");
 
-     $this->assertText('Active context: testcontext');
 
-     $this->drupalGet("node/{$child->nid}");
 
-     $this->assertText('Active context: testcontext');
 
-     $this->drupalGet("node/{$dummy->nid}");
 
-     $this->assertNoText('Active context: testcontext');
 
-     $this->drupalGet("node/{$dummy_child->nid}");
 
-     $this->assertNoText('Active context: testcontext');
 
-     $this->drupalGet("node/{$book->nid}/edit");
 
-     $this->assertNoText('Active context: testcontext');
 
-     $context->conditions['bookroot']['options']['node_form'] = 1;
 
-     $saved = context_save($context);
 
-     $this->assertTrue($saved, "Context 'testcontext' saved.");
 
-     $this->drupalGet("node/{$book->nid}/edit");
 
-     $this->assertText('Active context: testcontext');
 
-     // Cleanup
 
-     context_delete($context);
 
-   }
 
- }
 
 
  |