1: <?php
2:
3: namespace Alchemy\tests;
4:
5: use Alchemy\core\Element;
6:
7:
8: class ElementTest extends BaseTest {
9:
10: public function testIDsDistinct() {
11: $objA = new Element();
12: $objB = new Element();
13:
14: $this->assertEquals($objA->getID(), $objA->getID());
15: $this->assertEquals($objB->getID(), $objB->getID());
16: $this->assertNotEquals($objA->getID(), $objB->getID());
17: }
18:
19: public function testTagQueries() {
20: $obj = new Element();
21: $obj->addTag("a.b");
22: $obj->addTag("a.b.c", 'value');
23: $obj->addTags(array(
24: "a.b.c" => true,
25: "b.c" => "value2"));
26:
27: $this->assertEquals(array("a.b", "a.b.c", "b.c"), $obj->listTags());
28:
29: $this->assertEquals(true, $obj->getTag('a.b'));
30: $this->assertEquals("value", $obj->getTag('a.b.c'));
31: $this->assertEquals("value2", $obj->getTag('b.c'));
32:
33: $this->assertThrows('Exception', array($obj, 'addTag'), 'a.b.c', 'value2');
34: }
35:
36: public function testDefinitionInheritance() {
37:
38: $this->assertThrows('Exception', array("Element", "define"), "Type", null);
39: $this->assertThrows('Exception', array("Element", "define"), "Type", "Unknown");
40:
41:
42: Element::define(null, null, array('key' => 'element'));
43:
44: $expected = array('key' => 'element',
45: 'tags' => array(
46: 'element.type' => 'Element',
47: 'element.class' => 'Alchemy\core\Element'));
48: $this->assertEquals($expected, Element::get_definition('Element'));
49:
50:
51: Element::define('Type', null, array('key' => 'type', 'a' => array(1, 'k' => 'v')));
52: Element::define('Subtype', 'Type', array('a' => array(2)));
53:
54: $expected = array('key' => 'type',
55: 'a' => array(2, 'k' => 'v'),
56: 'tags' => array(
57: 'element.type' => 'Subtype',
58: 'element.class' => 'Alchemy\core\Element'));
59: $this->assertEquals($expected, Element::get_definition('Subtype'));
60:
61:
62: $this->assertThrows('Exception', array("Element", "get_definition"), "Unknown");
63:
64: $obj = Element::Subtype();
65: $this->assertInstanceOf('Alchemy\core\Element', $obj);
66: $this->assertEquals('Subtype', $obj->getType());
67: }
68:
69: public function testDefinitionAliases() {
70:
71: Element::define('Type', 'Type', array('key' => 'type'));
72: MockElement::define('Mock', 'Element::Type', array('key2' => 'mock'));
73: Element::define_alias('Mock', 'MockElement::Mock');
74:
75: $expected = array('key' => 'type',
76: 'key2' => 'mock',
77: 'tags' => array(
78: 'element.type' => 'Mock',
79: 'element.class' => 'Alchemy\tests\MockElement'));
80: $this->assertEquals($expected, Element::get_definition('Mock'));
81:
82: $obj = Element::Mock();
83: $this->assertInstanceOf('Alchemy\tests\MockElement', $obj);
84: $this->assertEquals('Mock', $obj->getType());
85: }
86: }
87:
88:
89: class MockElement extends Element {}
90: