From f1921c15ef02459599113b105c854670c372c8d9 Mon Sep 17 00:00:00 2001 From: TommyO Date: Tue, 3 Jun 2008 22:33:21 +0000 Subject: [PATCH] New tests added for xml-based helpers git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7109 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../cases/libs/view/helpers/rss.test.php | 75 ++++++++----------- .../cases/libs/view/helpers/xml.test.php | 66 +++------------- 2 files changed, 41 insertions(+), 100 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/rss.test.php b/cake/tests/cases/libs/view/helpers/rss.test.php index 326d5c1d0..cdbc704fb 100644 --- a/cake/tests/cases/libs/view/helpers/rss.test.php +++ b/cake/tests/cases/libs/view/helpers/rss.test.php @@ -38,31 +38,38 @@ App::import('Helper', array('Rss', 'Time')); * @subpackage cake.tests.cases.libs.view.helpers */ class RssTest extends CakeTestCase { -/** - * setUp method - * - * @access public - * @return void - */ + function setUp() { $this->Rss =& new RssHelper(); - $this->Rss->Time = new TimeHelper(); + $this->Rss->Time =& new TimeHelper(); + $this->Rss->beforeRender(); } -/** - * tearDown method - * - * @access public - * @return void - */ + function tearDown() { unset($this->Rss); } -/** - * testDocument method - * - * @access public - * @return void - */ + + function testAddNamespace() { + $this->Rss->addNs('custom', 'http://example.com/dtd.xml'); + $manager =& XmlManager::getInstance(); + + $expected = array('custom' => 'http://example.com/dtd.xml'); + $this->assertEqual($manager->namespaces, $expected); + } + + function testRemoveNamespace() { + $this->Rss->addNs('custom', 'http://example.com/dtd.xml'); + $this->Rss->addNs('custom2', 'http://example.com/dtd2.xml'); + $manager =& XmlManager::getInstance(); + + $expected = array('custom' => 'http://example.com/dtd.xml', 'custom2' => 'http://example.com/dtd2.xml'); + $this->assertEqual($manager->namespaces, $expected); + + $this->Rss->removeNs('custom'); + $expected = array('custom2' => 'http://example.com/dtd2.xml'); + $this->assertEqual($manager->namespaces, $expected); + } + function testDocument() { $res = $this->Rss->document(); $this->assertPattern('/^$/', $res); @@ -78,12 +85,7 @@ class RssTest extends CakeTestCase { $this->assertPattern('/]+contrived="parameter"[^<>]*>/', $res); $this->assertNoPattern('/]+[^version|contrived]=[^<>]*>/', $res); } -/** - * testChannel method - * - * @access public - * @return void - */ + function testChannel() { $attrib = array('a' => '1', 'b' => '2'); $elements['title'] = 'title'; @@ -97,12 +99,7 @@ class RssTest extends CakeTestCase { $this->assertPattern('//', $res); $this->assertPattern('/content<\/channel>$/', $res); } -/** - * testChannelElementLevelAttrib method - * - * @access public - * @return void - */ + function testChannelElementLevelAttrib() { $attrib = array(); $elements['title'] = 'title'; @@ -116,12 +113,7 @@ class RssTest extends CakeTestCase { $this->assertPattern('//', $res); $this->assertPattern('/content<\/channel>$/', $res); } -/** - * testItems method - * - * @access public - * @return void - */ + function testItems() { $items = array( array('title' => 'title1', 'guid' => 'http://www.example.com/guid1', 'link' => 'http://www.example.com/link1', 'description' => 'description1'), @@ -147,12 +139,7 @@ class RssTest extends CakeTestCase { $result = $this->Rss->items(array()); $this->assertEqual($result, ''); } -/** - * testItem method - * - * @access public - * @return void - */ + function testItem() { $result = $this->Rss->item(null, array("title"=>"My title","description"=>"My description","link"=>"http://www.google.com/")); $expecting = 'My titleMy descriptionhttp://www.google.com/http://www.google.com/'; @@ -242,4 +229,4 @@ class RssTest extends CakeTestCase { $this->assertTags($result, $expected); } } -?> +?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/xml.test.php b/cake/tests/cases/libs/view/helpers/xml.test.php index 1806e5672..a9b5a569b 100644 --- a/cake/tests/cases/libs/view/helpers/xml.test.php +++ b/cake/tests/cases/libs/view/helpers/xml.test.php @@ -96,6 +96,16 @@ class XmlHelperTest extends UnitTestCase { $result .= $this->Xml->closeElem(); $this->assertEqual($result, $expected); } + + function testRenderElementWithComplexContent() { + $result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), array('contrived' => 'content')); + $expected = ''; + $this->assertEqual($result, $expected); + + $result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), array('cdata' => true, 'value' => 'content')); + $expected = ''; + $this->assertEqual($result, $expected); + } function testSerialize() { $data = array( @@ -147,63 +157,7 @@ class XmlHelperTest extends UnitTestCase { $expected = ''; $this->assertIdentical($result, $expected); } -/* - function test__ComposeContent() { - $content = 'some String'; - $result = $this->Xml->__composeContent($content); - $expected = 'some String'; - $this->assertIdentical($result, $expected); - $content = array('some String', 'some Other String'); - $result = $this->Xml->__composeContent($content); - $expected = ''; - $this->assertIdentical($result, $expected); - - $content = array(1, 'some Other String'); - $result = $this->Xml->__composeContent($content); - $expected = '1'; - $this->assertIdentical($result, $expected); - - $content = array( - array('some String'), - array('some Other String') - ); - $result = $this->Xml->__composeContent($content); - $expected = ''; - $this->assertIdentical($result, $expected); - - $content = array( - array(array('some String')), - array(('some Other String')) - ); - $result = $this->Xml->__composeContent($content); - $this->assertError(); - - $xml =& new Xml(null, array()); - $result = $xml->load('simple note'); - $result = $this->Xml->__composeContent($xml); - $expected = ''; - $this->assertIdentical($result, $expected); - - $xml =& new TestXml('simple note'); - $result = $this->Xml->__composeContent($xml); - $expected = 'simple note'; - $this->assertIdentical($result, $expected); - } - - function test__prepareNamespaces() { - $this->Xml->__namespaces = array('namespace1', 'namespace2'); - $result = $this->Xml->__prepareNamespaces(); - $expected = array('xmlns:0' => 'namespace1', 'xmlns:1' => 'namespace2'); - $this->assertIdentical($result, $expected); - - $this->Xml->__namespaces = array(); - $result = $this->Xml->__prepareNamespaces(); - $expected = array(); - $this->assertIdentical($result, $expected); - - } -*/ function tearDown() { unset($this->Xml); }