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