View source
<?php
class ContextUiTest extends DrupalTestCase {
function get_info() {
return array(
'name' => t('Context UI functional tests'),
'desc' => t('Create a context and test context on node view.'),
'group' => 'Context UI Tests',
);
}
function setUp() {
$this
->drupalModuleEnable('context');
$this
->drupalModuleEnable('context_ui');
parent::setUp();
}
function tearDown() {
include_once drupal_get_path("module", "context_ui") . "/context_ui_admin.inc";
context_ui_context('delete', $this->context);
$this
->drupalModuleDisable('context');
$this
->drupalModuleDisable('context_ui');
parent::tearDown();
}
function randomID($number = 4, $prefix = 'simpletest_') {
$chars = 'abcdefghijklmnopqrstuvwxyz_';
for ($x = 0; $x < $number; $x++) {
$prefix .= $chars[mt_rand(0, strlen($chars) - 1)];
if ($x == 0) {
$chars .= '0123456789';
}
}
return $prefix;
}
function testCreateContext() {
$user = $this
->drupalCreateUserRolePerm(array(
'administer site configuration',
'access content',
'create page content',
));
$this
->drupalLoginUser($user);
$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');
$edit = array();
$edit['title'] = $this
->randomName(32);
$edit['body'] = $this
->randomName(32);
$this
->drupalPostRequest('node/add/page', $edit, 'Submit');
node_view(node_load(array(
'title' => $edit['title'],
)), FALSE, TRUE);
$this
->assertIdentical(context_get($context->namespace, $context->attribute), $context->value, 'Custom context was set');
}
}