You are here

function ContextUiTest::testCreateContext in Context 5

File

context_ui/tests/context_ui.test, line 48

Class

ContextUiTest
Functional Test for Context UI

Code

function testCreateContext() {

  // User setup
  $user = $this
    ->drupalCreateUserRolePerm(array(
    'administer site configuration',
    'access content',
    'create page content',
  ));
  $this
    ->drupalLoginUser($user);

  // Create context
  $context = new stdClass();
  $context->namespace = $this
    ->randomID(15);
  $context->attribute = $this
    ->randomID(15);
  $context->value = $this
    ->randomID(15);
  $this->context = $context;
  $edit = array(
    'namespace' => $context->namespace,
    'attribute' => $context->attribute,
    'value' => $context->value,
  );
  $edit['items-node-page'] = 'page';
  $this
    ->drupalPostRequest('admin/build/context/add', $edit, 'Save');
  $this
    ->assertWantedRaw(t('The context %title was saved successfully.', array(
    '%title' => $edit['value'],
  )), 'Context saved');

  // Create Page content
  $edit = array();
  $edit['title'] = $this
    ->randomName(32);
  $edit['body'] = $this
    ->randomName(32);
  $this
    ->drupalPostRequest('node/add/page', $edit, 'Submit');

  // View context and test context setting
  node_view(node_load(array(
    'title' => $edit['title'],
  )), FALSE, TRUE);
  $this
    ->assertIdentical(context_get($context->namespace, $context->attribute), $context->value, 'Custom context was set');
}