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() { // define possible data types $set_types = array( 'bool' => true, 'int' => 1, 'string' => 'lorem', 'array' => array('lorem'), 'object' => new StdClass(), ); $id_types = array('int', 'string'); // NAMESPACE foreach ($set_types as $type => $val) { $set = context_set($val); // Test return value of context_set() if (in_array($type, $id_types)) { // test set integrity $this->assertIdentical(true, $set, 'Space set successful.'); // test get integrity $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(); } // NAMESPACE+ATTRIBUTE foreach ($set_types as $type => $val) { foreach ($set_types as $type2 => $val2) { // test set integrity $set = context_set($val, $val2); if (in_array($type, $id_types)) { // test set integrity if ($type2 != 'bool') { $this->assertIdentical(true, $set, 'Namespace and attribute set successful.'); } else { $this->assertIdentical(false, $set); } // test get + exists integrity 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(); } // NAMESPACE+ATTRIBUTE+VALUE, o lord 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(); } } } } }