class ContextConditionBookTest

  1. nittany7 modules/contrib/context/tests/context.conditions.test ContextConditionBookTest
  2. cis7 modules/contrib/context/tests/context.conditions.test ContextConditionBookTest
  3. mooc7 modules/contrib/context/tests/context.conditions.test ContextConditionBookTest

Hierarchy

Expanded class hierarchy of ContextConditionBookTest

Members

Contains filters are case sensitive

File

modules/contrib/context/tests/context.conditions.test, line 453

View source
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);
  }
}