1
|
|
|
<?php |
2
|
|
|
namespace Malezha\Menu\Tests\ElementTests; |
3
|
|
|
|
4
|
|
|
use Malezha\Menu\Contracts\Attributes; |
5
|
|
|
use Malezha\Menu\Factory\LinkFactory; |
6
|
|
|
use Malezha\Menu\Tests\TestCase; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class LinkTest |
10
|
|
|
* @package Malezha\Menu\Tests\ElementTests |
11
|
|
|
*/ |
12
|
|
|
class LinkTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @return LinkFactory |
16
|
|
|
*/ |
17
|
|
|
protected function factory() |
18
|
|
|
{ |
19
|
|
|
return new LinkFactory($this->app); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function elementRender() |
23
|
|
|
{ |
24
|
|
|
return "<li class=\"link\"><a href=\"/news\">News</a></li>\n"; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function serializeStub() |
28
|
|
|
{ |
29
|
|
|
return $this->getStub('serialized/link_element.txt'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testFactory() |
33
|
|
|
{ |
34
|
|
|
$factory = $this->factory(); |
35
|
|
|
$factory->title = 'Title'; |
36
|
|
|
|
37
|
|
|
$this->assertEquals('Title', $factory->title); |
38
|
|
|
$this->assertInstanceOf(Attributes::class, $factory->attributes); |
39
|
|
|
|
40
|
|
|
$link = $factory->build(['title' => 'New title']); |
41
|
|
|
$this->assertEquals('New title', $link->title); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testElement() |
45
|
|
|
{ |
46
|
|
|
$factory = $this->factory(); |
47
|
|
|
$factory->title = 'News'; |
48
|
|
|
$factory->url = '/news'; |
49
|
|
|
$link = $factory->build(); |
50
|
|
|
$link->attributes->put('class', 'link'); |
51
|
|
|
|
52
|
|
|
$html = $link->render(); |
53
|
|
|
$this->assertEquals($this->elementRender(), $html); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testSerialization() |
57
|
|
|
{ |
58
|
|
|
$factory = $this->factory(); |
59
|
|
|
$factory->title = 'Serialize'; |
60
|
|
|
$factory->url = '/s'; |
61
|
|
|
$factory->attributes->put('class', 'serialized'); |
62
|
|
|
$link = $factory->build(); |
63
|
|
|
|
64
|
|
|
$this->assertEquals($this->serializeStub(), serialize($link)); |
65
|
|
|
$this->assertEquals($link, unserialize($this->serializeStub())); |
66
|
|
|
} |
67
|
|
|
} |