1 | <?php |
||
22 | class BreadcrumbsBuilderTest extends TestCase |
||
23 | { |
||
24 | public function testCreate() |
||
25 | { |
||
26 | $breadcrumbs = $this->createBreadcrumbsBuilder('/', new RouteCollection()) |
||
27 | ->create(); |
||
28 | |||
29 | $this->assertInstanceOf('Yceruto\Bundle\BreadcrumbsBundle\Breadcrumbs', $breadcrumbs); |
||
30 | $this->assertEquals(0, $breadcrumbs->count()); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @dataProvider getCreateFromRequestData |
||
35 | */ |
||
36 | public function testCreateFromRequest($path, $result) |
||
37 | { |
||
38 | $routeCollection = new RouteCollection(); |
||
39 | $routeCollection->add('_index', new Route('/')); |
||
40 | $routeCollection->add('_foo', new Route('/foo', array('breadcrumbs_label' => 'Foo'))); |
||
41 | $routeCollection->add('_foo_bar', new Route('/foo/bar')); |
||
42 | $routeCollection->add('_bar', new Route('/bar/')); |
||
43 | $routeCollection->add('_bar_show', new Route('/bar/{id}')); |
||
44 | $routeCollection->add('_bar_action', new Route('/bar/{id}/{action}')); |
||
45 | |||
46 | $breadcrumbs = $this->createBreadcrumbsBuilder($path, $routeCollection) |
||
47 | ->createFromRequest(); |
||
48 | |||
49 | $this->assertCount(count($result['nodes']), $breadcrumbs->getNodes()); |
||
50 | $nodes = $breadcrumbs->getNodes(); |
||
51 | $node = current($nodes); |
||
52 | foreach ($result['nodes'] as $path => $label) { |
||
53 | $this->assertEquals($path, $node->getPath()); |
||
54 | $this->assertEquals($label, $node->getLabel()); |
||
55 | $node = next($nodes); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | public function getCreateFromRequestData() |
||
60 | { |
||
61 | return array( |
||
62 | 'index' => array( |
||
63 | '/', |
||
64 | array('nodes' => array('/' => 'breadcrumbs._index')), |
||
65 | ), |
||
66 | 'foo' => array( |
||
67 | '/foo', |
||
68 | array( |
||
69 | 'nodes' => array( |
||
70 | '/' => 'breadcrumbs._index', |
||
71 | '/foo' => 'Foo', |
||
72 | ), |
||
73 | ), |
||
74 | ), |
||
75 | 'foo_bar' => array( |
||
76 | '/foo/bar', |
||
77 | array( |
||
78 | 'nodes' => array( |
||
79 | '/' => 'breadcrumbs._index', |
||
80 | '/foo' => 'Foo', |
||
81 | '/foo/bar' => 'bar', |
||
82 | ), |
||
83 | ), |
||
84 | ), |
||
85 | 'bar' => array( |
||
86 | '/bar/', |
||
87 | array( |
||
88 | 'nodes' => array( |
||
89 | '/' => 'breadcrumbs._index', |
||
90 | '/bar/' => 'bar', |
||
91 | ), |
||
92 | ), |
||
93 | ), |
||
94 | 'bar_show' => array( |
||
95 | '/bar/baz', |
||
96 | array( |
||
97 | 'nodes' => array( |
||
98 | '/' => 'breadcrumbs._index', |
||
99 | '/bar/' => 'bar', |
||
100 | '/bar/baz' => 'baz', |
||
101 | ), |
||
102 | ), |
||
103 | ), |
||
104 | 'bar_int_show' => array( |
||
105 | '/bar/1', |
||
106 | array( |
||
107 | 'nodes' => array( |
||
108 | '/' => 'breadcrumbs._index', |
||
109 | '/bar/' => 'bar', |
||
110 | '/bar/1' => 'breadcrumbs._bar_show', |
||
111 | ), |
||
112 | ), |
||
113 | ), |
||
114 | 'bar_action' => array( |
||
115 | '/bar/baz/edit', |
||
116 | array( |
||
117 | 'nodes' => array( |
||
118 | '/' => 'breadcrumbs._index', |
||
119 | '/bar/' => 'bar', |
||
120 | '/bar/baz' => 'baz', |
||
121 | '/bar/baz/edit' => 'edit', |
||
122 | ), |
||
123 | ), |
||
124 | ), |
||
125 | 'bar_int_action' => array( |
||
126 | '/bar/1/edit', |
||
127 | array( |
||
128 | 'nodes' => array( |
||
129 | '/' => 'breadcrumbs._index', |
||
130 | '/bar/' => 'bar', |
||
131 | '/bar/1' => 'breadcrumbs._bar_show', |
||
132 | '/bar/1/edit' => 'edit', |
||
133 | ), |
||
134 | ), |
||
135 | ), |
||
136 | 'bar_int2_action' => array( |
||
137 | '/bar/1/2', |
||
138 | array( |
||
139 | 'nodes' => array( |
||
140 | '/' => 'breadcrumbs._index', |
||
141 | '/bar/' => 'bar', |
||
142 | '/bar/1' => 'breadcrumbs._bar_show', |
||
143 | '/bar/1/2' => 'breadcrumbs._bar_action', |
||
144 | ), |
||
145 | ), |
||
146 | ), |
||
147 | ); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * Create a Breadcrumbs Builder. |
||
152 | * |
||
153 | * @param string $path |
||
154 | * @param RouteCollection $collection |
||
155 | * |
||
156 | * @return BreadcrumbsBuilder |
||
157 | */ |
||
158 | private function createBreadcrumbsBuilder($path, RouteCollection $collection) |
||
187 | } |
||
188 |