| 1 |
<?php
|
| 2 |
// $Id: context.test,v 1.2 2008/07/17 16:57:19 jmiccolis Exp $
|
| 3 |
|
| 4 |
class ContextUnitTestCase extends DrupalWebTestCase {
|
| 5 |
/**
|
| 6 |
* Implementation of get_info() for information
|
| 7 |
*/
|
| 8 |
function getInfo() {
|
| 9 |
return array(
|
| 10 |
'name' => t('context_get(), context_exists() unit tests'),
|
| 11 |
'description' => t('Sets all possible context types and checks for integrity.') ,
|
| 12 |
'group' => t('Context'),
|
| 13 |
);
|
| 14 |
}
|
| 15 |
|
| 16 |
function setUp() {
|
| 17 |
return;
|
| 18 |
}
|
| 19 |
|
| 20 |
function tearDown() {
|
| 21 |
return;
|
| 22 |
}
|
| 23 |
|
| 24 |
function testContextGet() {
|
| 25 |
// define possible data types
|
| 26 |
$set_types = array(
|
| 27 |
'bool' => true,
|
| 28 |
'int' => 1,
|
| 29 |
'string' => 'lorem',
|
| 30 |
'array' => array('lorem'),
|
| 31 |
'object' => new StdClass(),
|
| 32 |
);
|
| 33 |
$id_types = array('int', 'string');
|
| 34 |
|
| 35 |
// NAMESPACE
|
| 36 |
foreach ($set_types as $type => $val) {
|
| 37 |
$set = context_set($val);
|
| 38 |
// Test return value of context_set()
|
| 39 |
if (in_array($type, $id_types)) {
|
| 40 |
// test set integrity
|
| 41 |
$this->assertIdentical(true, $set, 'Space set successful.');
|
| 42 |
// test get integrity
|
| 43 |
$this->assertIdentical(array(), context_get($val), 'Namespace get successful.');
|
| 44 |
$this->assertIdentical(true, context_exists($val), 'Namespace exists successful.');
|
| 45 |
}
|
| 46 |
else {
|
| 47 |
$this->assertIdentical(false, $set, 'Prohibited namespace not established.');
|
| 48 |
}
|
| 49 |
context_clear();
|
| 50 |
}
|
| 51 |
|
| 52 |
// NAMESPACE+ATTRIBUTE
|
| 53 |
foreach ($set_types as $type => $val) {
|
| 54 |
foreach ($set_types as $type2 => $val2) {
|
| 55 |
// test set integrity
|
| 56 |
$set = context_set($val, $val2);
|
| 57 |
if (in_array($type, $id_types)) {
|
| 58 |
// test set integrity
|
| 59 |
if ($type2 != 'bool') {
|
| 60 |
$this->assertIdentical(true, $set, 'Namespace and attribute set successful.');
|
| 61 |
}
|
| 62 |
else {
|
| 63 |
$this->assertIdentical(false, $set);
|
| 64 |
}
|
| 65 |
// test get + exists integrity
|
| 66 |
if (in_array($type2, $id_types)) {
|
| 67 |
$this->assertIdentical(true, (context_get($val, $val2) == $val2), 'Namespace and attribute get successful.');
|
| 68 |
$this->assertIdentical(true, context_exists($val, $val2), 'Namespace and attribute exists.');
|
| 69 |
}
|
| 70 |
else if (in_array($type2, array('array', 'object'))) {
|
| 71 |
$this->assertIdentical(true, (context_get($val) == $val2), 'Namespace and attribute get successful.');
|
| 72 |
$this->assertIdentical(true, context_exists($val), 'Namespace and attribute exists.');
|
| 73 |
}
|
| 74 |
}
|
| 75 |
}
|
| 76 |
context_clear();
|
| 77 |
}
|
| 78 |
|
| 79 |
// NAMESPACE+ATTRIBUTE+VALUE, o lord
|
| 80 |
foreach ($set_types as $type => $val) {
|
| 81 |
foreach ($set_types as $type2 => $val2) {
|
| 82 |
foreach ($set_types as $type3 => $val3) {
|
| 83 |
$set = context_set($val, $val2, $val3);
|
| 84 |
if (in_array($type, $id_types)) {
|
| 85 |
if(in_array($type2, $id_types)) {
|
| 86 |
$this->assertIdentical(true, (context_get($val, $val2, $val3) == $val3), 'Namespace, attribute and value get successful.');
|
| 87 |
$this->assertIdentical(true, context_exists($val, $val2, $val3), 'Namespace, attribute and value exists.');
|
| 88 |
}
|
| 89 |
}
|
| 90 |
context_clear();
|
| 91 |
}
|
| 92 |
}
|
| 93 |
}
|
| 94 |
}
|
| 95 |
}
|