From 4cf94f9c2866b0f684f4bb90048a752db20ce8de Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Wed, 3 Oct 2012 09:30:44 -0400 Subject: [PATCH] Added tests for the convert class --- tests/classes/ConvertTest.php | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/classes/ConvertTest.php diff --git a/tests/classes/ConvertTest.php b/tests/classes/ConvertTest.php new file mode 100644 index 0000000..7d724d8 --- /dev/null +++ b/tests/classes/ConvertTest.php @@ -0,0 +1,59 @@ +assertEquals(Convert::toJSON($a), $b); + } + + public function providerToJSON() + { + $object = (object)'object'; + $object->foo = 'foo'; + $object->bar = 'bar'; + + return array( + array('', '""'), + array('foo', '"foo"'), + array(array('bar'), '["bar"]'), + array(array('foo', 'bar'), '["foo","bar"]'), + array(19810223, '19810223'), + array(array(1981, 02, 23), '[1981,2,23]'), + array(array('foo', 1981), '["foo",1981]'), + array(array('foo', array('bar')), '["foo",["bar"]]'), + array($object, '{"scalar":"object","foo":"foo","bar":"bar"}'), + array(true, 'true'), + array(false, 'false'), + array(null, 'null'), + ); + } + + /** + * @dataProvider providerArrayToXML + */ + public function testArrayToXML($a, $b, $c) + { + $this->assertEquals(Convert::arrayToXML($a, $b), $c); + } + + public function providerArrayToXML() + { + return array( + array('foo', false, ''), + array(array('foo', 'bar'), false, '<0>foo<1>bar'), + array(array('foo', 'bar'), true, "<0>foo\n<1>bar\n"), + array(array('foo' => 'bar'), false, 'bar'), + array(array('children' => array('child' => array('foo', 'bar'))), false, 'foobar'), + array(array('children' => array('child' => array('foo', 'bar'))), true, "\n\tfoo\n\tbar\n\n"), + ); + } +} + +?>