-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathHtmlBuilderTest.php
More file actions
150 lines (129 loc) · 3.79 KB
/
HtmlBuilderTest.php
File metadata and controls
150 lines (129 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace Styde\Html\Tests;
use Illuminate\Support\Facades\Route;
use Styde\Html\Facades\Html;
use Styde\Html\Htmltag;
class HtmlBuilderTest extends TestCase
{
/** @test */
function it_generates_html_tags()
{
$this->assertEquals(
'<span id="my-span">This is a span</span>',
Html::tag('span', 'This is a span', ['id' => 'my-span'])->render()
);
$this->assertEquals(
'<input type="text" readonly>',
Html::tag('input', ['type' => 'text', 'readonly'])->render()
);
}
/** @test */
function it_escapes_the_attributes_of_generated_tags()
{
$this->assertEquals(
'<span id="<my-span>">Span</span>',
Html::tag('span', 'Span', ['id' => '<my-span>'])->render()
);
}
/** @test */
function remove_attribute_from_tag()
{
$this->assertEquals(
'<input name="test">',
Html::tag('input', ['name' => 'test', 'required'])->removeAttr('required')->render()
);
}
/** @test */
function it_generates_html_tags_with_dynamic_methods()
{
$this->assertEquals(
'<span id="my-span">This is a span</span>',
Html::span('This is a span')->id('my-span')
);
}
/** @test */
function it_generates_links()
{
$this->assertHtmlEquals(
'<a href="http://localhost/url">Text</a>',
Html::link('url', 'Text')
);
}
/** @test */
function it_generates_a_secure_link()
{
$this->assertHtmlEquals(
'<a href="https://localhost/url">Text</a>',
Html::Securelink('url', 'Text')
);
}
/** @test */
function it_generates_links_with_additional_attributes()
{
$this->assertHtmlEquals(
'<a target="_blank" href="http://localhost/url">Text</a>',
Html::link('url', 'Text', ['target' => '_blank'])
);
}
/** @test */
function it_generates_a_style_sheet_link()
{
$this->assertHtmlEquals(
'<link type="text/css" rel="stylesheet" href="http://localhost/css/app.css">',
Html::style('css/app.css')
);
}
/** @test */
function it_generates_a_javascript_tag()
{
$this->assertHtmlEquals(
'<script src="http://localhost/js/app.js"></script>',
Html::script('js/app.js')
);
}
/** @test */
function it_generates_a_link_from_asset()
{
$this->assertHtmlEquals(
'<a href="http://localhost/user/avatar">Avatar</a>',
Html::linkAsset('user/avatar', 'Avatar')
);
}
/** @test */
function it_generates_a_link_from_a_route()
{
Route::get('dashboard', ['as' => 'dashboard']);
Route::get('edit/{page}', ['as' => 'pages.edit']);
$this->assertHtmlEquals(
'<a href="http://localhost/dashboard">Control Panel</a>',
Html::linkRoute('dashboard', 'Control Panel')
);
$this->assertHtmlEquals(
'<a href="http://localhost/edit/profile">Edit profile</a>',
Html::linkRoute('pages.edit', 'Edit profile', ['profile'])
);
}
/** @test */
function it_generates_the_html_class_attribute()
{
$html = Html::classes([
'home' => true,
'main',
'dont-use-this' => false,
]);
$this->assertEquals(' class="home main"', $html);
}
/** @test */
function it_has_a_helper()
{
return $this->assertSame(app('html'), html());
}
/** @test */
function it_is_macroable()
{
Html::macro('myCustomMethod', function () {
return 'my-custom-tag';
});
$this->assertSame('my-custom-tag', Html::myCustomMethod());
}
}