|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Malezha\Menu\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Malezha\Menu\Entity\Attributes; |
|
6
|
|
|
|
|
7
|
|
|
class AttributesTest extends TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
protected function attributeFactory() |
|
10
|
|
|
{ |
|
11
|
|
|
return new Attributes([ |
|
12
|
|
|
'class' => 'some-style', |
|
13
|
|
|
'id' => 'test', |
|
14
|
|
|
]); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function testGet() |
|
18
|
|
|
{ |
|
19
|
|
|
$attributes = $this->attributeFactory(); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertEquals('some-style', $attributes->get('class')); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testSet() |
|
25
|
|
|
{ |
|
26
|
|
|
$attributes = $this->attributeFactory(); |
|
27
|
|
|
$subset = ['class' => 'new-style', 'id' => 'link']; |
|
28
|
|
|
|
|
29
|
|
|
$attributes->set($subset); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertArraySubset($subset, $attributes->all()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testForget() |
|
35
|
|
|
{ |
|
36
|
|
|
$attributes = $this->attributeFactory(); |
|
37
|
|
|
|
|
38
|
|
|
$attributes->forget('id'); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertEquals(null, $attributes->get('id')); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testPut() |
|
44
|
|
|
{ |
|
45
|
|
|
$attributes = $this->attributeFactory(); |
|
46
|
|
|
|
|
47
|
|
|
$attributes->put('data-test', 'value'); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertEquals('value', $attributes->get('data-test')); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testPush() |
|
53
|
|
|
{ |
|
54
|
|
|
$attributes = $this->attributeFactory(); |
|
55
|
|
|
|
|
56
|
|
|
$subset = $attributes->all(); |
|
57
|
|
|
$push = ['data-value' => 'some']; |
|
58
|
|
|
|
|
59
|
|
|
$attributes->push($push); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertArraySubset(array_merge($subset, $push), $attributes->all()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testHas() |
|
65
|
|
|
{ |
|
66
|
|
|
$attributes = $this->attributeFactory(); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertTrue($attributes->has('class')); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testMerge() |
|
72
|
|
|
{ |
|
73
|
|
|
$attributes = $this->attributeFactory(); |
|
74
|
|
|
|
|
75
|
|
|
$attributes->merge([ |
|
76
|
|
|
'class' => 'another-style', |
|
77
|
|
|
]); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertArraySubset([ |
|
80
|
|
|
'class' => 'some-style another-style', |
|
81
|
|
|
'id' => 'test', |
|
82
|
|
|
], $attributes->all()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testBuild() |
|
86
|
|
|
{ |
|
87
|
|
|
$attributes = $this->attributeFactory(); |
|
88
|
|
|
$expected = ' class="some-style active" id="test"'; |
|
89
|
|
|
$expectedString = ' class="some-style" id="test"'; |
|
90
|
|
|
|
|
91
|
|
|
$this->assertEquals($expected, $attributes->build(['class' => 'active'])); |
|
92
|
|
|
$this->assertEquals($expectedString, (string) $attributes); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @expectedException \RuntimeException |
|
97
|
|
|
*/ |
|
98
|
|
|
public function testMergeArrayValuesException() |
|
99
|
|
|
{ |
|
100
|
|
|
Attributes::mergeArrayValues(); |
|
101
|
|
|
} |
|
102
|
|
|
} |