blob: 3cf1016ec2d3a62c42c5470334748e6f78625ce1 [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
Andrey Andreev356bc662017-03-06 14:39:28 +020043 public function test_img()
44 {
45 $this->ci_set_config('base_url', 'http://localhost/');
46 $this->assertEquals('<img src="http://localhost/test" alt="" />', img("test"));
47 $this->assertEquals('<img src="data:foo/bar,baz" alt="" />', img("data:foo/bar,baz"));
48 $this->assertEquals('<img src="http://localhost/data://foo" alt="" />', img("data://foo"));
49 $this->assertEquals('<img src="//foo.bar/baz" alt="" />', img("//foo.bar/baz"));
50 $this->assertEquals('<img src="http://foo.bar/baz" alt="" />', img("http://foo.bar/baz"));
51 $this->assertEquals('<img src="https://foo.bar/baz" alt="" />', img("https://foo.bar/baz"));
52 $this->assertEquals('<img src="ftp://foo.bar/baz" alt="" />', img("ftp://foo.bar/baz"));
53 }
54
55 // ------------------------------------------------------------------------
56
Eric Barnes68286a42011-04-21 22:00:33 -040057 public function test_Ul()
Greg Akerb5679472011-04-21 14:34:31 -050058 {
59 $expect = <<<EOH
60<ul>
61 <li>foo</li>
62 <li>bar</li>
63</ul>
64
65EOH;
66
67 $expect = ltrim($expect);
Greg Akerb5679472011-04-21 14:34:31 -050068 $list = array('foo', 'bar');
Greg Akerb5679472011-04-21 14:34:31 -050069
Andrey Andreev99b782d2012-06-09 22:24:46 +030070 $this->assertEquals(ltrim($expect), ul($list));
Greg Akerb5679472011-04-21 14:34:31 -050071
72 $expect = <<<EOH
73<ul class="test">
74 <li>foo</li>
75 <li>bar</li>
76</ul>
77
78EOH;
79
80 $expect = ltrim($expect);
81
Greg Aker92ff07e2011-08-20 16:57:48 -050082 $this->assertEquals($expect, ul($list, 'class="test"'));
Greg Akerb5679472011-04-21 14:34:31 -050083
84 $this->assertEquals($expect, ul($list, array('class' => 'test')));
85 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030086
Greg Akerb5679472011-04-21 14:34:31 -050087 // ------------------------------------------------------------------------
88
Eric Barnes68286a42011-04-21 22:00:33 -040089 public function test_NBS()
Greg Akerb5679472011-04-21 14:34:31 -050090 {
91 $this->assertEquals('&nbsp;&nbsp;&nbsp;', nbs(3));
92 }
93
94 // ------------------------------------------------------------------------
Andrey Andreev99b782d2012-06-09 22:24:46 +030095
Eric Barnes68286a42011-04-21 22:00:33 -040096 public function test_meta()
Greg Akerb5679472011-04-21 14:34:31 -050097 {
98 $this->assertEquals("<meta name=\"test\" content=\"foo\" />\n", meta('test', 'foo'));
Andrey Andreev99b782d2012-06-09 22:24:46 +030099
Greg Akerb5679472011-04-21 14:34:31 -0500100 $expect = "<meta name=\"foo\" content=\"\" />\n";
Andrey Andreev99b782d2012-06-09 22:24:46 +0300101
Greg Akerb5679472011-04-21 14:34:31 -0500102 $this->assertEquals($expect, meta(array('name' => 'foo')));
Andrey Andreev99b782d2012-06-09 22:24:46 +0300103
Greg Akerb5679472011-04-21 14:34:31 -0500104 }
Andrey Andreev838a9d62012-12-03 14:37:47 +0200105
Andrey Andreev356bc662017-03-06 14:39:28 +0200106}