From acedd2b1a37b22cb04b01038f21876ddfe38b83a Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 29 Jul 2012 00:15:40 -0400 Subject: Adding a common stringify_attributes function for dealing with attributes through out various helpers. Signed-off-by: Eric Barnes --- tests/codeigniter/core/Common_test.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index f9bf6c27f..27d48efc2 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -10,4 +10,35 @@ class Common_test extends CI_TestCase { $this->assertEquals(FALSE, is_php('9999.9.9')); } + // ------------------------------------------------------------------------ + + public function test_stringify_attributes() + { + $this->assertEquals(' class="foo" id="bar"', _stringify_attributes(array('class' => 'foo', 'id' => 'bar'))); + + $atts = new Stdclass; + $atts->class = 'foo'; + $atts->id = 'bar'; + $this->assertEquals(' class="foo" id="bar"', _stringify_attributes($atts)); + + $atts = new Stdclass; + $this->assertEquals('', _stringify_attributes($atts)); + + $this->assertEquals(' class="foo" id="bar"', _stringify_attributes('class="foo" id="bar"')); + + $this->assertEquals('', _stringify_attributes(array())); + } + + // ------------------------------------------------------------------------ + + public function test_stringify_js_attributes() + { + $this->assertEquals('width=800,height=600', _stringify_attributes(array('width' => '800', 'height' => '600'), TRUE)); + + $atts = new Stdclass; + $atts->width = 800; + $atts->height = 600; + $this->assertEquals('width=800,height=600', _stringify_attributes($atts, TRUE)); + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b