1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yceruto\Bundle\BreadcrumbsBundle\Tests; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; |
6
|
|
|
use Yceruto\Bundle\BreadcrumbsBundle\Breadcrumbs; |
7
|
|
|
use Yceruto\Bundle\BreadcrumbsBundle\BreadcrumbsNode; |
8
|
|
|
|
9
|
|
|
class BreadcrumbsTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var Breadcrumbs |
13
|
|
|
*/ |
14
|
|
|
private $breadcrumbs; |
15
|
|
|
|
16
|
|
|
public function setUp() |
17
|
|
|
{ |
18
|
|
|
$this->breadcrumbs = new Breadcrumbs(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testAdd() |
22
|
|
|
{ |
23
|
|
|
$node = $this->breadcrumbs->add('/', 'index'); |
24
|
|
|
|
25
|
|
|
$this->assertInstanceOf('Yceruto\Bundle\BreadcrumbsBundle\BreadcrumbsNode', $node); |
26
|
|
|
$this->assertEquals('/', $node->getPath()); |
27
|
|
|
$this->assertEquals('index', $node->getLabel()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testAddNode() |
31
|
|
|
{ |
32
|
|
|
$node = new BreadcrumbsNode(); |
33
|
|
|
$node->setPath('/'); |
34
|
|
|
$node->setLabel('index'); |
35
|
|
|
|
36
|
|
|
$this->breadcrumbs->addNode($node); |
37
|
|
|
$nodes = $this->breadcrumbs->getNodes(); |
38
|
|
|
|
39
|
|
|
$this->assertCount(1, $nodes); |
40
|
|
|
$this->assertEquals($node, $nodes[0]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testRemove() |
44
|
|
|
{ |
45
|
|
|
$node = new BreadcrumbsNode(); |
46
|
|
|
$node->setPath('/'); |
47
|
|
|
$node->setLabel('index'); |
48
|
|
|
|
49
|
|
|
$this->breadcrumbs->addNode($node); |
50
|
|
|
|
51
|
|
|
$this->assertCount(1, $this->breadcrumbs->getNodes()); |
52
|
|
|
$this->breadcrumbs->remove(0); |
53
|
|
|
$this->assertCount(0, $this->breadcrumbs->getNodes()); |
54
|
|
|
$this->assertNull($this->breadcrumbs->remove(0)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testRemoveNode() |
58
|
|
|
{ |
59
|
|
|
$node = $this->breadcrumbs->add('/', 'index'); |
60
|
|
|
|
61
|
|
|
$this->assertCount(1, $this->breadcrumbs->getNodes()); |
62
|
|
|
$this->breadcrumbs->removeNode($node); |
63
|
|
|
$this->assertCount(0, $this->breadcrumbs->getNodes()); |
64
|
|
|
$this->assertFalse($this->breadcrumbs->removeNode($node)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testContainNode() |
68
|
|
|
{ |
69
|
|
|
$node = $this->breadcrumbs->add('/', 'index'); |
70
|
|
|
$this->assertTrue($this->breadcrumbs->containsNode($node)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testCountable() |
74
|
|
|
{ |
75
|
|
|
$this->breadcrumbs->add('/', 'index'); |
76
|
|
|
$this->assertEquals(1, $this->breadcrumbs->count()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testIteratorAggregate() |
80
|
|
|
{ |
81
|
|
|
$this->breadcrumbs->add('/', 'index'); |
82
|
|
|
$this->assertInstanceOf('\ArrayIterator', $this->breadcrumbs->getIterator()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testArrayAccess() |
86
|
|
|
{ |
87
|
|
|
$node1 = new BreadcrumbsNode(); |
88
|
|
|
$node1->setPath('/'); |
89
|
|
|
$node1->setLabel('index'); |
90
|
|
|
$node2 = new BreadcrumbsNode(); |
91
|
|
|
$node2->setPath('/foo'); |
92
|
|
|
$node2->setLabel('foo'); |
93
|
|
|
|
94
|
|
|
$this->breadcrumbs[] = $node1; |
95
|
|
|
$this->breadcrumbs[23] = $node2; |
96
|
|
|
|
97
|
|
|
$this->assertCount(2, $this->breadcrumbs); |
98
|
|
|
$this->assertTrue(isset($this->breadcrumbs[0])); |
99
|
|
|
$this->assertEquals($node1, $this->breadcrumbs[0]); |
100
|
|
|
$this->assertEquals($node2, $this->breadcrumbs[23]); |
101
|
|
|
$this->assertNull($this->breadcrumbs[1]); |
102
|
|
|
|
103
|
|
|
unset($this->breadcrumbs[0]); |
104
|
|
|
$this->assertCount(1, $this->breadcrumbs); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testPositionMethods() |
108
|
|
|
{ |
109
|
|
|
$node1 = $this->breadcrumbs->add('/', 'index'); |
110
|
|
|
$node2 = $this->breadcrumbs->add('/foo', 'foo'); |
111
|
|
|
|
112
|
|
|
$this->assertEquals($node1, $this->breadcrumbs->current()); |
113
|
|
|
$this->assertEquals($node2, $this->breadcrumbs->next()); |
114
|
|
|
$this->assertEquals($node1, $this->breadcrumbs->first()); |
115
|
|
|
$this->assertEquals($node2, $this->breadcrumbs->last()); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|