blob: 4dd717ff7d72d98054ebf61c6324482af41db77c [file] [log] [blame]
Greg Akerb5679472011-04-21 14:34:31 -05001<?php
2
Taufan Adityae1dc9ea2012-03-28 16:49:49 +07003class Html_helper_test extends CI_TestCase {
Greg Akerb5679472011-04-21 14:34:31 -05004
Taufan Adityae1dc9ea2012-03-28 16:49:49 +07005 public function set_up()
6 {
7 $this->helper('html');
8 }
Andrey Andreev99b782d2012-06-09 22:24:46 +03009
Eric Barnes68286a42011-04-21 22:00:33 -040010 // ------------------------------------------------------------------------
Andrey Andreev99b782d2012-06-09 22:24:46 +030011
Eric Barnes68286a42011-04-21 22:00:33 -040012 public function test_br()
13 {
14 $this->assertEquals('<br /><br />', br(2));
15 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030016
Eric Barnes68286a42011-04-21 22:00:33 -040017 // ------------------------------------------------------------------------
Andrey Andreev99b782d2012-06-09 22:24:46 +030018
Eric Barnes68286a42011-04-21 22:00:33 -040019 public function test_heading()
Greg Akerb5679472011-04-21 14:34:31 -050020 {
21 $this->assertEquals('<h1>foobar</h1>', heading('foobar'));
Eric Barnes68286a42011-04-21 22:00:33 -040022 $this->assertEquals('<h2 class="bar">foobar</h2>', heading('foobar', 2, 'class="bar"'));
Greg Akerb5679472011-04-21 14:34:31 -050023 }
24
Eric Barnes62ab8b22012-07-28 14:57:04 -040025 public function test_heading_array_attributes()
26 {
27 // Test array of attributes
28 $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, array('class' => 'bar', 'id' => 'foo')));
29 }
30
31 public function test_heading_object_attributes()
32 {
33 // Test array of attributes
34 $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, array('class' => 'bar', 'id' => 'foo')));
35 $test = new stdClass;
36 $test->class = "bar";
37 $test->id = "foo";
38 $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, $test));
39 }
40
Greg Akerb5679472011-04-21 14:34:31 -050041 // ------------------------------------------------------------------------
Andrey Andreev99b782d2012-06-09 22:24:46 +030042
Eric Barnes68286a42011-04-21 22:00:33 -040043 public function test_Ul()
Greg Akerb5679472011-04-21 14:34:31 -050044 {
45 $expect = <<<EOH
46<ul>
47 <li>foo</li>
48 <li>bar</li>
49</ul>
50
51EOH;
52
53 $expect = ltrim($expect);
Greg Akerb5679472011-04-21 14:34:31 -050054 $list = array('foo', 'bar');
Greg Akerb5679472011-04-21 14:34:31 -050055
Andrey Andreev99b782d2012-06-09 22:24:46 +030056 $this->assertEquals(ltrim($expect), ul($list));
Greg Akerb5679472011-04-21 14:34:31 -050057
58 $expect = <<<EOH
59<ul class="test">
60 <li>foo</li>
61 <li>bar</li>
62</ul>
63
64EOH;
65
66 $expect = ltrim($expect);
67
Greg Aker92ff07e2011-08-20 16:57:48 -050068 $this->assertEquals($expect, ul($list, 'class="test"'));
Greg Akerb5679472011-04-21 14:34:31 -050069
70 $this->assertEquals($expect, ul($list, array('class' => 'test')));
71 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030072
Greg Akerb5679472011-04-21 14:34:31 -050073 // ------------------------------------------------------------------------
74
Eric Barnes68286a42011-04-21 22:00:33 -040075 public function test_NBS()
Greg Akerb5679472011-04-21 14:34:31 -050076 {
77 $this->assertEquals('&nbsp;&nbsp;&nbsp;', nbs(3));
78 }
79
80 // ------------------------------------------------------------------------
Andrey Andreev99b782d2012-06-09 22:24:46 +030081
Eric Barnes68286a42011-04-21 22:00:33 -040082 public function test_meta()
Greg Akerb5679472011-04-21 14:34:31 -050083 {
84 $this->assertEquals("<meta name=\"test\" content=\"foo\" />\n", meta('test', 'foo'));
Andrey Andreev99b782d2012-06-09 22:24:46 +030085
Greg Akerb5679472011-04-21 14:34:31 -050086 $expect = "<meta name=\"foo\" content=\"\" />\n";
Andrey Andreev99b782d2012-06-09 22:24:46 +030087
Greg Akerb5679472011-04-21 14:34:31 -050088 $this->assertEquals($expect, meta(array('name' => 'foo')));
Andrey Andreev99b782d2012-06-09 22:24:46 +030089
Greg Akerb5679472011-04-21 14:34:31 -050090 }
Greg Akerb5679472011-04-21 14:34:31 -050091}