1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tadcka package. |
5
|
|
|
* |
6
|
|
|
* (c) Tadas Gliaubicas <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tadcka\Component\Breadcrumbs\Tests; |
13
|
|
|
|
14
|
|
|
use Tadcka\Component\Breadcrumbs\Breadcrumb; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Tadas Gliaubicas <[email protected]> |
18
|
|
|
* |
19
|
|
|
* @since 10/30/14 11:29 PM |
20
|
|
|
*/ |
21
|
|
|
class BreadcrumbTest extends \PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Breadcrumb |
25
|
|
|
*/ |
26
|
|
|
private $breadcrumb; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
protected function setUp() |
32
|
|
|
{ |
33
|
|
|
$this->breadcrumb = new Breadcrumb(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Test empty breadcrumb. |
38
|
|
|
*/ |
39
|
|
|
public function testEmpty() |
40
|
|
|
{ |
41
|
|
|
$count = 0; |
42
|
|
|
foreach ($this->breadcrumb as $item) { |
43
|
|
|
$count++; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->assertEquals(0, $count); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Test breadcrumb add method. |
51
|
|
|
*/ |
52
|
|
|
public function testAdd() |
53
|
|
|
{ |
54
|
|
|
$this->breadcrumb->add('title_0', 'url_0'); |
55
|
|
|
$this->breadcrumb->add('title_1', 'url_1'); |
56
|
|
|
$this->breadcrumb->add('title_2', 'url_2'); |
57
|
|
|
|
58
|
|
|
$count = 0; |
59
|
|
View Code Duplication |
foreach ($this->breadcrumb as $key => $item) { |
|
|
|
|
60
|
|
|
$count++; |
61
|
|
|
|
62
|
|
|
$this->assertEquals('title_' . $key, $item['title']); |
63
|
|
|
$this->assertEquals('url_' . $key, $item['url']); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->assertEquals(3, $count); |
67
|
|
|
|
68
|
|
|
// Double iterator. |
69
|
|
View Code Duplication |
foreach ($this->breadcrumb as $key => $item) { |
|
|
|
|
70
|
|
|
$count++; |
71
|
|
|
|
72
|
|
|
$this->assertEquals('title_' . $key, $item['title']); |
73
|
|
|
$this->assertEquals('url_' . $key, $item['url']); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testGet() |
78
|
|
|
{ |
79
|
|
|
$this->breadcrumb->add('title_0', 'url_0'); |
80
|
|
|
$this->breadcrumb->add('title_1', 'url_1'); |
81
|
|
|
|
82
|
|
|
$this->assertEquals($this->breadcrumb->get(0), ['title' => 'title_0', 'url' => 'url_0']); |
83
|
|
|
$this->assertEquals($this->breadcrumb->get(1), ['title' => 'title_1', 'url' => 'url_1']); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.