1+ <?php
2+
3+ class HtmlTest extends PHPUnit_Framework_TestCase {
4+
5+ /**
6+ * Setup the test environment
7+ */
8+ public function setUp ()
9+ {
10+ URL ::$ base = null ;
11+ Config::set ('application.url ' , 'http://localhost ' );
12+ Config::set ('application.index ' , 'index.php ' );
13+ Router::$ names = array ();
14+ Router::$ routes = array ();
15+ }
16+
17+ /**
18+ * Destroy the test environment
19+ */
20+ public function tearDown ()
21+ {
22+ Config::set ('application.url ' , '' );
23+ Config::set ('application.index ' , 'index.php ' );
24+ Router::$ names = array ();
25+ Router::$ routes = array ();
26+ }
27+
28+ /**
29+ * Test generating a link to JavaScript files
30+ *
31+ * @group laravel
32+ */
33+ public function testGeneratingScript ()
34+ {
35+ $ html1 = HTML ::script ('foo.js ' );
36+ $ html2 = HTML ::script ('http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js ' );
37+ $ html3 = HTML ::script ('foo.js ' , array ('type ' => 'text/javascript ' ));
38+
39+ $ this ->assertEquals ('<script src="http://localhost/foo.js"></script> ' ."\n" , $ html1 );
40+ $ this ->assertEquals ('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> ' ."\n" , $ html2 );
41+ $ this ->assertEquals ('<script src="http://localhost/foo.js" type="text/javascript"></script> ' ."\n" , $ html3 );
42+ }
43+
44+ /**
45+ * Test generating a link to CSS files
46+ *
47+ * @group laravel
48+ */
49+ public function testGeneratingStyle ()
50+ {
51+ $ html1 = HTML ::style ('foo.css ' );
52+ $ html2 = HTML ::style ('http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js ' );
53+ $ html3 = HTML ::style ('foo.css ' , array ('media ' => 'print ' ));
54+
55+ $ this ->assertEquals ('<link href="http://localhost/foo.css" media="all" type="text/css" rel="stylesheet"> ' ."\n" , $ html1 );
56+ $ this ->assertEquals ('<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js" media="all" type="text/css" rel="stylesheet"> ' ."\n" , $ html2 );
57+ $ this ->assertEquals ('<link href="http://localhost/foo.css" media="print" type="text/css" rel="stylesheet"> ' ."\n" , $ html3 );
58+ }
59+
60+ /**
61+ * Test generating proper span
62+ *
63+ * @group laravel
64+ */
65+ public function testGeneratingSpan ()
66+ {
67+ $ html1 = HTML ::span ('foo ' );
68+ $ html2 = HTML ::span ('foo ' , array ('class ' => 'badge ' ));
69+
70+ $ this ->assertEquals ('<span>foo</span> ' , $ html1 );
71+ $ this ->assertEquals ('<span class="badge">foo</span> ' , $ html2 );
72+ }
73+
74+ /**
75+ * Test generating proper link
76+ *
77+ * @group laravel
78+ */
79+ public function testGeneratingLink ()
80+ {
81+ $ html1 = HTML ::link ('foo ' );
82+ $ html2 = HTML ::link ('foo ' , 'Foobar ' );
83+ $ html3 = HTML ::link ('foo ' , 'Foobar ' , array ('class ' => 'btn ' ));
84+ $ html4 = HTML ::link ('http://google.com ' , 'Google ' );
85+
86+ $ this ->assertEquals ('<a href="http://localhost/index.php/foo">http://localhost/index.php/foo</a> ' , $ html1 );
87+ $ this ->assertEquals ('<a href="http://localhost/index.php/foo">Foobar</a> ' , $ html2 );
88+ $ this ->assertEquals ('<a href="http://localhost/index.php/foo" class="btn">Foobar</a> ' , $ html3 );
89+ $ this ->assertEquals ('<a href="http://google.com">Google</a> ' , $ html4 );
90+ }
91+
92+ /**
93+ * Test generating proper link to secure
94+ *
95+ * @group laravel
96+ */
97+ public function testGeneratingLinkToSecure ()
98+ {
99+ $ html1 = HTML ::link_to_secure ('foo ' );
100+ $ html2 = HTML ::link_to_secure ('foo ' , 'Foobar ' );
101+ $ html3 = HTML ::link_to_secure ('foo ' , 'Foobar ' , array ('class ' => 'btn ' ));
102+ $ html4 = HTML ::link_to_secure ('http://google.com ' , 'Google ' );
103+
104+ $ this ->assertEquals ('<a href="https://localhost/index.php/foo">https://localhost/index.php/foo</a> ' , $ html1 );
105+ $ this ->assertEquals ('<a href="https://localhost/index.php/foo">Foobar</a> ' , $ html2 );
106+ $ this ->assertEquals ('<a href="https://localhost/index.php/foo" class="btn">Foobar</a> ' , $ html3 );
107+ $ this ->assertEquals ('<a href="http://google.com">Google</a> ' , $ html4 );
108+ }
109+
110+ /**
111+ * Test generating proper link to asset
112+ *
113+ * @group laravel
114+ */
115+ public function testGeneratingAssetLink ()
116+ {
117+ $ html1 = HTML ::link_to_asset ('foo.css ' );
118+ $ html2 = HTML ::link_to_asset ('foo.css ' , 'Foobar ' );
119+ $ html3 = HTML ::link_to_asset ('foo.css ' , 'Foobar ' , array ('class ' => 'btn ' ));
120+ $ html4 = HTML ::link_to_asset ('http://google.com/images.jpg ' , 'Google ' );
121+
122+ $ this ->assertEquals ('<a href="http://localhost/foo.css">http://localhost/foo.css</a> ' , $ html1 );
123+ $ this ->assertEquals ('<a href="http://localhost/foo.css">Foobar</a> ' , $ html2 );
124+ $ this ->assertEquals ('<a href="http://localhost/foo.css" class="btn">Foobar</a> ' , $ html3 );
125+ $ this ->assertEquals ('<a href="http://google.com/images.jpg">Google</a> ' , $ html4 );
126+ }
127+
128+ /**
129+ * Test generating proper link to secure asset
130+ *
131+ * @group laravel
132+ */
133+ public function testGeneratingAssetLinkToSecure ()
134+ {
135+ $ html1 = HTML ::link_to_secure_asset ('foo.css ' );
136+ $ html2 = HTML ::link_to_secure_asset ('foo.css ' , 'Foobar ' );
137+ $ html3 = HTML ::link_to_secure_asset ('foo.css ' , 'Foobar ' , array ('class ' => 'btn ' ));
138+ $ html4 = HTML ::link_to_secure_asset ('http://google.com/images.jpg ' , 'Google ' );
139+
140+ $ this ->assertEquals ('<a href="https://localhost/foo.css">https://localhost/foo.css</a> ' , $ html1 );
141+ $ this ->assertEquals ('<a href="https://localhost/foo.css">Foobar</a> ' , $ html2 );
142+ $ this ->assertEquals ('<a href="https://localhost/foo.css" class="btn">Foobar</a> ' , $ html3 );
143+ $ this ->assertEquals ('<a href="http://google.com/images.jpg">Google</a> ' , $ html4 );
144+ }
145+
146+ /**
147+ * Test generating proper link to route
148+ *
149+ * @group laravel
150+ */
151+ public function testGeneratingLinkToRoute ()
152+ {
153+ Route::get ('dashboard ' , array ('as ' => 'foo ' ));
154+
155+ $ html1 = HTML ::link_to_route ('foo ' );
156+ $ html2 = HTML ::link_to_route ('foo ' , 'Foobar ' );
157+ $ html3 = HTML ::link_to_route ('foo ' , 'Foobar ' , array (), array ('class ' => 'btn ' ));
158+
159+ $ this ->assertEquals ('<a href="http://localhost/index.php/dashboard">http://localhost/index.php/dashboard</a> ' , $ html1 );
160+ $ this ->assertEquals ('<a href="http://localhost/index.php/dashboard">Foobar</a> ' , $ html2 );
161+ $ this ->assertEquals ('<a href="http://localhost/index.php/dashboard" class="btn">Foobar</a> ' , $ html3 );
162+ }
163+
164+ /**
165+ * Test generating proper link to action
166+ *
167+ * @group laravel
168+ */
169+ public function testGeneratingLinkToAction ()
170+ {
171+ $ html1 = HTML ::link_to_action ('foo@bar ' );
172+ $ html2 = HTML ::link_to_action ('foo@bar ' , 'Foobar ' );
173+ $ html3 = HTML ::link_to_action ('foo@bar ' , 'Foobar ' , array (), array ('class ' => 'btn ' ));
174+
175+ $ this ->assertEquals ('<a href="http://localhost/index.php/foo/bar">http://localhost/index.php/foo/bar</a> ' , $ html1 );
176+ $ this ->assertEquals ('<a href="http://localhost/index.php/foo/bar">Foobar</a> ' , $ html2 );
177+ $ this ->assertEquals ('<a href="http://localhost/index.php/foo/bar" class="btn">Foobar</a> ' , $ html3 );
178+ }
179+
180+ /**
181+ * Test generating proper listing
182+ *
183+ * @group laravel
184+ */
185+ public function testGeneratingListing ()
186+ {
187+ $ list = array (
188+ 'foo ' ,
189+ 'foobar ' => array (
190+ 'hello ' ,
191+ 'hello world ' ,
192+ ),
193+ );
194+
195+ $ html1 = HTML ::ul ($ list );
196+ $ html2 = HTML ::ul ($ list , array ('class ' => 'nav ' ));
197+ $ html3 = HTML ::ol ($ list );
198+ $ html4 = HTML ::ol ($ list , array ('class ' => 'nav ' ));
199+
200+ $ this ->assertEquals ('<ul><li>foo</li><li>foobar<ul><li>hello</li><li>hello world</li></ul></li></ul> ' , $ html1 );
201+ $ this ->assertEquals ('<ul class="nav"><li>foo</li><li>foobar<ul><li>hello</li><li>hello world</li></ul></li></ul> ' , $ html2 );
202+ $ this ->assertEquals ('<ol><li>foo</li><li>foobar<ol><li>hello</li><li>hello world</li></ol></li></ol> ' , $ html3 );
203+ $ this ->assertEquals ('<ol class="nav"><li>foo</li><li>foobar<ol><li>hello</li><li>hello world</li></ol></li></ol> ' , $ html4 );
204+ }
205+
206+ /**
207+ * Test generating proper listing
208+ *
209+ * @group laravel
210+ */
211+ public function testGeneratingDefinition ()
212+ {
213+ $ definition = array (
214+ 'foo ' => 'foobar ' ,
215+ 'hello ' => 'hello world ' ,
216+ );
217+
218+ $ html1 = HTML ::dl ($ definition );
219+ $ html2 = HTML ::dl ($ definition , array ('class ' => 'nav ' ));
220+
221+ $ this ->assertEquals ('<dl><dt>foo</dt><dd>foobar</dd><dt>hello</dt><dd>hello world</dd></dl> ' , $ html1 );
222+ $ this ->assertEquals ('<dl class="nav"><dt>foo</dt><dd>foobar</dd><dt>hello</dt><dd>hello world</dd></dl> ' , $ html2 );
223+ }
224+
225+ /**
226+ * Test generating proper image link
227+ *
228+ * @group laravel
229+ */
230+ public function testGeneratingAssetLinkImage ()
231+ {
232+ $ html1 = HTML ::image ('foo.jpg ' );
233+ $ html2 = HTML ::image ('foo.jpg ' , 'Foobar ' );
234+ $ html3 = HTML ::image ('foo.jpg ' , 'Foobar ' , array ('class ' => 'btn ' ));
235+ $ html4 = HTML ::image ('http://google.com/images.jpg ' , 'Google ' );
236+
237+ $ this ->assertEquals ('<img src="http://localhost/foo.jpg" alt=""> ' , $ html1 );
238+ $ this ->assertEquals ('<img src="http://localhost/foo.jpg" alt="Foobar"> ' , $ html2 );
239+ $ this ->assertEquals ('<img src="http://localhost/foo.jpg" class="btn" alt="Foobar"> ' , $ html3 );
240+ $ this ->assertEquals ('<img src="http://google.com/images.jpg" alt="Google"> ' , $ html4 );
241+ }
242+ }
0 commit comments