You are here

function ContextConditionBookTest::test in Context 7.3

Same name and namespace in other branches
  1. 6.3 tests/context.conditions.test \ContextConditionBookTest::test()
  2. 6 tests/context.conditions.test \ContextConditionBookTest::test()

File

tests/context.conditions.test, line 487

Class

ContextConditionBookTest

Code

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