You are here

function ContextConditionBookroot::test in Context 7.3

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

File

tests/context.conditions.test, line 537

Class

ContextConditionBookroot

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