1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fwk\Xml; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Test class for XmlFile. |
7
|
|
|
* Generated by PHPUnit on 2012-07-25 at 22:30:05. |
8
|
|
|
*/ |
9
|
|
|
class MapTest extends \PHPUnit_Framework_TestCase { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var Map |
13
|
|
|
*/ |
14
|
|
|
protected $object; |
15
|
|
|
|
16
|
|
|
public function testInvalidAddArgument() { |
17
|
|
|
$this->object = new Map(); |
18
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
19
|
|
|
$this->object->add(array(new \stdClass())); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testRemovePath() { |
23
|
|
|
$this->object = new Map(); |
24
|
|
|
$path = Path::factory('/test/description', 'description'); |
25
|
|
|
$path2 = Path::factory('/test/properties/property', 'props') |
26
|
|
|
->loop(true, '@inexistant'); |
27
|
|
|
|
28
|
|
|
$this->object->add(array($path, $path2)); |
29
|
|
|
$this->assertEquals(2, count($this->object->getPaths())); |
30
|
|
|
$this->object->remove($path); |
31
|
|
|
$this->assertEquals(1, count($this->object->getPaths())); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testNamedPropertiesWithWrongIdentifier() |
35
|
|
|
{ |
36
|
|
|
$map = new Map(); |
37
|
|
|
$map->add(Path::factory('/test/properties/property', 'props') |
38
|
|
|
->loop(true, '@inexistant')); |
39
|
|
|
|
40
|
|
|
$result = $map->execute(new XmlFile(__DIR__ .'/test.xml')); |
41
|
|
|
|
42
|
|
|
$this->assertTrue(is_array($result)); |
43
|
|
|
$this->assertArrayHasKey('props', $result); |
44
|
|
|
$this->assertTrue(is_array($result['props'])); |
45
|
|
|
$this->assertEquals(2, count($result['props'])); |
46
|
|
|
$this->assertFalse(isset($result['props']['test'])); |
47
|
|
|
$this->assertEquals('test_value', $result['props'][0]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testInexistantLoopChildrenPathShouldReturnArray() |
51
|
|
|
{ |
52
|
|
|
$map = new Map(); |
53
|
|
|
$map->add(Path::factory('/test/properties', 'props') |
54
|
|
|
->loop(true) |
55
|
|
|
->addChildren(Path::factory('param', 'params')->loop(true))); |
56
|
|
|
|
57
|
|
|
$result = $map->execute(new XmlFile(__DIR__ .'/test.xml')); |
58
|
|
|
|
59
|
|
|
$this->assertTrue(is_array($result)); |
60
|
|
|
$this->assertArrayHasKey('props', $result); |
61
|
|
|
$this->assertTrue(is_array($result['props'][0]['params'])); |
62
|
|
|
$this->assertEquals(0, count($result['props'][0]['params'])); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testWrongPathShouldReturnDefaultValue() |
66
|
|
|
{ |
67
|
|
|
$map = new Map(); |
68
|
|
|
$map->add(Path::factory('/test/inexistant', 'inexist', 'default')); |
69
|
|
|
|
70
|
|
|
$result = $map->execute(new XmlFile(__DIR__ .'/test.xml')); |
71
|
|
|
|
72
|
|
|
$this->assertTrue(is_array($result)); |
73
|
|
|
$this->assertTrue(is_string($result['inexist'])); |
74
|
|
|
$this->assertEquals('default', $result['inexist']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testWrongPath() |
78
|
|
|
{ |
79
|
|
|
$map = new Map(); |
80
|
|
|
$map->add(Path::factory('/test', 'test')->addChildren(Path::factory('wrong>path', 'wrong', 'defaultFalse'))); |
81
|
|
|
|
82
|
|
|
$result = $map->execute(new XmlFile(__DIR__ .'/test.xml')); |
83
|
|
|
|
84
|
|
|
$this->assertTrue(is_array($result)); |
85
|
|
|
$this->assertArrayHasKey('test', $result); |
86
|
|
|
$this->assertTrue(is_array($result['test'])); |
87
|
|
|
$this->assertArrayHasKey('wrong', $result['test']); |
88
|
|
|
$this->assertEquals('defaultFalse', $result['test']['wrong']); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|