mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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
This commit is contained in:
parent
eaf4dc9ff5
commit
f1921c15ef
2 changed files with 41 additions and 100 deletions
|
@ -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('/^<rss version="2.0" \/>$/', $res);
|
||||
|
@ -78,12 +85,7 @@ class RssTest extends CakeTestCase {
|
|||
$this->assertPattern('/<rss[^<>]+contrived="parameter"[^<>]*>/', $res);
|
||||
$this->assertNoPattern('/<rss[^<>]+[^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('/<description \/>/', $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('/<description \/>/', $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 = '<item><title>My title</title><description>My description</description><link>http://www.google.com/</link><guid>http://www.google.com/</guid></item>';
|
||||
|
@ -242,4 +229,4 @@ class RssTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
|
@ -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 = '<myNameSpace:count><content /></myNameSpace:count>';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), array('cdata' => true, 'value' => 'content'));
|
||||
$expected = '<myNameSpace:count><![CDATA[content]]></myNameSpace:count>';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testSerialize() {
|
||||
$data = array(
|
||||
|
@ -147,63 +157,7 @@ class XmlHelperTest extends UnitTestCase {
|
|||
$expected = '<?xml encoding="UTF-8" someOther="value" ?>';
|
||||
$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 = '<some String /><some Other String />';
|
||||
$this->assertIdentical($result, $expected);
|
||||
|
||||
$content = array(1, 'some Other String');
|
||||
$result = $this->Xml->__composeContent($content);
|
||||
$expected = '1<some Other String />';
|
||||
$this->assertIdentical($result, $expected);
|
||||
|
||||
$content = array(
|
||||
array('some String'),
|
||||
array('some Other String')
|
||||
);
|
||||
$result = $this->Xml->__composeContent($content);
|
||||
$expected = '<some String /><some Other String />';
|
||||
$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('<para><note>simple note</note></para>');
|
||||
$result = $this->Xml->__composeContent($xml);
|
||||
$expected = '<para><note><![CDATA[simple note]]></note></para>';
|
||||
$this->assertIdentical($result, $expected);
|
||||
|
||||
$xml =& new TestXml('<para><note>simple note</note></para>');
|
||||
$result = $this->Xml->__composeContent($xml);
|
||||
$expected = '<para><note>simple note</note></para>';
|
||||
$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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue