Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 1 | <?php |
| 2 | |
Taufan Aditya | e1dc9ea | 2012-03-28 16:49:49 +0700 | [diff] [blame] | 3 | class Html_helper_test extends CI_TestCase { |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 4 | |
Taufan Aditya | e1dc9ea | 2012-03-28 16:49:49 +0700 | [diff] [blame] | 5 | public function set_up() |
| 6 | { |
| 7 | $this->helper('html'); |
| 8 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 9 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 10 | // ------------------------------------------------------------------------ |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 11 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 12 | public function test_br() |
| 13 | { |
| 14 | $this->assertEquals('<br /><br />', br(2)); |
| 15 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 16 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 17 | // ------------------------------------------------------------------------ |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 18 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 19 | public function test_heading() |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 20 | { |
| 21 | $this->assertEquals('<h1>foobar</h1>', heading('foobar')); |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 22 | $this->assertEquals('<h2 class="bar">foobar</h2>', heading('foobar', 2, 'class="bar"')); |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 23 | } |
| 24 | |
Eric Barnes | 62ab8b2 | 2012-07-28 14:57:04 -0400 | [diff] [blame] | 25 | 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 Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 41 | // ------------------------------------------------------------------------ |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 42 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 43 | public function test_Ul() |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 44 | { |
| 45 | $expect = <<<EOH |
| 46 | <ul> |
| 47 | <li>foo</li> |
| 48 | <li>bar</li> |
| 49 | </ul> |
| 50 | |
| 51 | EOH; |
| 52 | |
| 53 | $expect = ltrim($expect); |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 54 | $list = array('foo', 'bar'); |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 55 | |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 56 | $this->assertEquals(ltrim($expect), ul($list)); |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 57 | |
| 58 | $expect = <<<EOH |
| 59 | <ul class="test"> |
| 60 | <li>foo</li> |
| 61 | <li>bar</li> |
| 62 | </ul> |
| 63 | |
| 64 | EOH; |
| 65 | |
| 66 | $expect = ltrim($expect); |
| 67 | |
Greg Aker | 92ff07e | 2011-08-20 16:57:48 -0500 | [diff] [blame] | 68 | $this->assertEquals($expect, ul($list, 'class="test"')); |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 69 | |
| 70 | $this->assertEquals($expect, ul($list, array('class' => 'test'))); |
| 71 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 72 | |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 73 | // ------------------------------------------------------------------------ |
| 74 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 75 | public function test_NBS() |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 76 | { |
| 77 | $this->assertEquals(' ', nbs(3)); |
| 78 | } |
| 79 | |
| 80 | // ------------------------------------------------------------------------ |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 81 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 82 | public function test_meta() |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 83 | { |
| 84 | $this->assertEquals("<meta name=\"test\" content=\"foo\" />\n", meta('test', 'foo')); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 85 | |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 86 | $expect = "<meta name=\"foo\" content=\"\" />\n"; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 87 | |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 88 | $this->assertEquals($expect, meta(array('name' => 'foo'))); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 89 | |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 90 | } |
Greg Aker | b567947 | 2011-04-21 14:34:31 -0500 | [diff] [blame] | 91 | } |