View source
<?php
class ContextUnitTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('context_get(), context_exists() unit tests'),
'description' => t('Sets all possible context types and checks for integrity.'),
'group' => t('Context'),
);
}
function setUp() {
return;
}
function tearDown() {
return;
}
function testContextGet() {
$set_types = array(
'bool' => true,
'int' => 1,
'string' => 'lorem',
'array' => array(
'lorem',
),
'object' => new StdClass(),
);
$id_types = array(
'int',
'string',
);
foreach ($set_types as $type => $val) {
$set = context_set($val);
if (in_array($type, $id_types)) {
$this
->assertIdentical(true, $set, 'Space set successful.');
$this
->assertIdentical(array(), context_get($val), 'Namespace get successful.');
$this
->assertIdentical(true, context_exists($val), 'Namespace exists successful.');
}
else {
$this
->assertIdentical(false, $set, 'Prohibited namespace not established.');
}
context_clear();
}
foreach ($set_types as $type => $val) {
foreach ($set_types as $type2 => $val2) {
$set = context_set($val, $val2);
if (in_array($type, $id_types)) {
if ($type2 != 'bool') {
$this
->assertIdentical(true, $set, 'Namespace and attribute set successful.');
}
else {
$this
->assertIdentical(false, $set);
}
if (in_array($type2, $id_types)) {
$this
->assertIdentical(true, context_get($val, $val2) == $val2, 'Namespace and attribute get successful.');
$this
->assertIdentical(true, context_exists($val, $val2), 'Namespace and attribute exists.');
}
else {
if (in_array($type2, array(
'array',
'object',
))) {
$this
->assertIdentical(true, context_get($val) == $val2, 'Namespace and attribute get successful.');
$this
->assertIdentical(true, context_exists($val), 'Namespace and attribute exists.');
}
}
}
}
context_clear();
}
foreach ($set_types as $type => $val) {
foreach ($set_types as $type2 => $val2) {
foreach ($set_types as $type3 => $val3) {
$set = context_set($val, $val2, $val3);
if (in_array($type, $id_types)) {
if (in_array($type2, $id_types)) {
$this
->assertIdentical(true, context_get($val, $val2, $val3) == $val3, 'Namespace, attribute and value get successful.');
$this
->assertIdentical(true, context_exists($val, $val2, $val3), 'Namespace, attribute and value exists.');
}
}
context_clear();
}
}
}
}
}