class ContextConditionBookroot

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

Hierarchy

Expanded class hierarchy of ContextConditionBookroot

Members

Contains filters are case sensitive

File

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

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