Merge remote branch 'upstream/2.0' into 2.0

This commit is contained in:
Jeremy Harris 2010-10-11 20:12:24 -07:00
commit 692aafbf42
14 changed files with 1106 additions and 3224 deletions

View file

@ -172,15 +172,15 @@ class RequestHandlerComponent extends Component {
}
if ($this->requestedWith('xml')) {
if (!class_exists('XmlNode')) {
if (!class_exists('Xml')) {
App::import('Core', 'Xml');
}
$xml = new Xml(trim(file_get_contents('php://input')));
$xml = Xml::build(trim(file_get_contents('php://input')));
if (count($xml->children) == 1 && is_object($dataNode = $xml->child('data'))) {
$controller->data = $dataNode->toArray();
if (isset($xml->data)) {
$controller->data = Xml::toArray($xml->data);
} else {
$controller->data = $xml->toArray();
$controller->data = Xml::toArray($xml);
}
}
}

View file

@ -941,9 +941,8 @@ class Set {
*/
public static function reverse($object) {
$out = array();
if (is_a($object, 'XmlNode')) {
$out = $object->toArray();
return $out;
if ($object instanceof SimpleXMLElement) {
return Xml::toArray($object);
} else if (is_object($object)) {
$keys = get_object_vars($object);
if (isset($keys['_name_'])) {

View file

@ -17,18 +17,16 @@
* @since CakePHP(tm) v 1.2
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Helper', 'Xml');
App::import('Core', 'Xml');
/**
* XML Helper class for easy output of XML structures.
*
* XmlHelper encloses all methods needed while working with XML documents.
* RSS Helper class for easy output RSS structures.
*
* @package cake
* @subpackage cake.cake.libs.view.helpers
* @link http://book.cakephp.org/view/1460/RSS
*/
class RssHelper extends XmlHelper {
class RssHelper extends AppHelper {
/**
* Helpers used by RSS Helper
@ -270,7 +268,7 @@ class RssHelper extends XmlHelper {
if (!empty($elements)) {
$content = implode('', $elements);
}
return $this->elem('item', $att, $content, !($content === null));
return $this->elem('item', (array)$att, $content, !($content === null));
}
/**
@ -283,4 +281,62 @@ class RssHelper extends XmlHelper {
function time($time) {
return $this->Time->toRSS($time);
}
/**
* Generates an XML element
*
* @param string $name The name of the XML element
* @param array $attrib The attributes of the XML element
* @param mixed $content XML element content
* @param boolean $endTag Whether the end tag of the element should be printed
* @return string XML
*/
function elem($name, $attrib = array(), $content = null, $endTag = true) {
$namespace = null;
if (isset($attrib['namespace'])) {
$namespace = $attrib['namespace'];
unset($attrib['namespace']);
}
$cdata = false;
if (is_array($content) && isset($content['cdata'])) {
$cdata = true;
unset($content['cdata']);
}
if (is_array($content) && array_key_exists('value', $content)) {
$content = $content['value'];
}
$children = array();
if (is_array($content)) {
$children = $content;
$content = null;
}
$xml = '<' . $name;
if (!empty($namespace)) {
$xml .= ' xmlns:"' . $namespace . '"';
}
if (strpos($name, ':') !== false) {
list($prefix, ) = explode(':', $name, 2);
switch ($prefix) {
case 'atom':
$xml .= ' xmlns:atom="http://www.w3.org/2005/Atom"';
break;
}
}
if ($cdata && !empty($content)) {
$content = '<![CDATA[' . $content . ']]>';
}
$xml .= '>' . $content . '</' . $name. '>';
$elem = Xml::build($xml);
foreach ($attrib as $key => $value) {
$elem->addAttribute($key, $value);
}
foreach ($children as $child) {
$elem->addChild($child);
}
$xml = $elem->asXML();
$xml = trim(substr($xml, strpos($xml, '?>') + 2));
return $xml;
}
}

View file

@ -1,179 +0,0 @@
<?php
/**
* XML Helper class file.
*
* Simplifies the output of XML documents.
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.view.helpers
* @since CakePHP(tm) v 1.2
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', array('Xml', 'Set'));
/**
* XML Helper class for easy output of XML structures.
*
* XmlHelper encloses all methods needed while working with XML documents.
*
* @package cake
* @subpackage cake.cake.libs.view.helpers
* @link http://book.cakephp.org/view/1473/XML
*/
class XmlHelper extends AppHelper {
/**
* Default document encoding
*
* @access public
* @var string
*/
public $encoding = 'UTF-8';
/**
* Xml instance
*
* @var Xml
*/
public $Xml;
/**
* Constructor
*
* @return void
*/
function __construct(View $View, $settings = array()) {
parent::__construct($View, $settings);
$this->Xml =& new Xml();
$this->Xml->options(array('verifyNs' => false));
}
/**
* Returns an XML document header
*
* @param array $attrib Header tag attributes
* @return string XML header
* @access public
* @link http://book.cakephp.org/view/1476/header
*/
public function header($attrib = array()) {
if (Configure::read('App.encoding') !== null) {
$this->encoding = Configure::read('App.encoding');
}
if (is_array($attrib)) {
$attrib = array_merge(array('encoding' => $this->encoding), $attrib);
}
if (is_string($attrib) && strpos($attrib, 'xml') !== 0) {
$attrib = 'xml ' . $attrib;
}
return $this->Xml->header($attrib);
}
/**
* Adds a namespace to any documents generated
*
* @param string $name The namespace name
* @param string $url The namespace URI; can be empty if in the default namespace map
* @return boolean False if no URL is specified, and the namespace does not exist
* default namespace map, otherwise true
* @deprecated
* @see Xml::addNs()
*/
function addNs($name, $url = null) {
return $this->Xml->addNamespace($name, $url);
}
/**
* Removes a namespace added in addNs()
*
* @param string $name The namespace name or URI
* @deprecated
* @see Xml::removeNs()
*/
public function removeNs($name) {
return $this->Xml->removeGlobalNamespace($name);
}
/**
* Generates an XML element
*
* @param string $name The name of the XML element
* @param array $attrib The attributes of the XML element
* @param mixed $content XML element content
* @param boolean $endTag Whether the end tag of the element should be printed
* @return string XML
* @access public
* @link http://book.cakephp.org/view/1475/elem
*/
public function elem($name, $attrib = array(), $content = null, $endTag = true) {
$namespace = null;
if (isset($attrib['namespace'])) {
$namespace = $attrib['namespace'];
unset($attrib['namespace']);
}
$cdata = false;
if (is_array($content) && isset($content['cdata'])) {
$cdata = true;
unset($content['cdata']);
}
if (is_array($content) && array_key_exists('value', $content)) {
$content = $content['value'];
}
$children = array();
if (is_array($content)) {
$children = $content;
$content = null;
}
$elem =& $this->Xml->createElement($name, $content, $attrib, $namespace);
foreach ($children as $child) {
$elem->createElement($child);
}
$out = $elem->toString(array('cdata' => $cdata, 'leaveOpen' => !$endTag));
if (!$endTag) {
$this->Xml =& $elem;
}
return $out;
}
/**
* Create closing tag for current element
*
* @return string
*/
public function closeElem() {
$name = $this->Xml->name();
if ($parent =& $this->Xml->parent()) {
$this->Xml =& $parent;
}
return '</' . $name . '>';
}
/**
* Serializes a model resultset into XML
*
* @param mixed $data The content to be converted to XML
* @param array $options The data formatting options. For a list of valid options, see
* Xml::__construct().
* @return string A copy of $data in XML format
* @see Xml::__construct()
* @access public
* @link http://book.cakephp.org/view/1474/serialize
*/
public function serialize($data, $options = array()) {
$options += array('attributes' => false, 'format' => 'attributes');
$data =& new Xml($data, $options);
return $data->toString($options + array('header' => false));
}
}

File diff suppressed because it is too large Load diff

View file

@ -38,7 +38,6 @@ class AllXmlTest extends PHPUnit_Framework_TestSuite {
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'xml.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS . 'rss.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS . 'xml.test.php');
return $suite;
}
}

View file

@ -2674,20 +2674,20 @@ class SetTest extends CakeTestCase {
</item>
</channel>
</rss>';
$xml = new Xml($string);
$xml = Xml::build($string);
$result = Set::reverse($xml);
$expected = array('Rss' => array(
$expected = array('rss' => array(
'version' => '2.0',
'Channel' => array(
'channel' => array(
'title' => 'Cake PHP Google Group',
'link' => 'http://groups.google.com/group/cake-php',
'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.',
'language' => 'en',
'Item' => array(
'item' => array(
array(
'title' => 'constructng result array when using findall',
'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br><p>Array( <br> [0] =&gt; Array(",
'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] =&gt; Array(",
'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
'author' => 'bmil...@gmail.com(bpscrugs)',
'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
@ -2706,43 +2706,43 @@ class SetTest extends CakeTestCase {
$this->assertEqual($result, $expected);
$string ='<data><post title="Title of this post" description="cool"/></data>';
$xml = new Xml($string);
$xml = Xml::build($string);
$result = Set::reverse($xml);
$expected = array('Data' => array('Post' => array('title' => 'Title of this post', 'description' => 'cool')));
$expected = array('data' => array('post' => array('title' => 'Title of this post', 'description' => 'cool')));
$this->assertEqual($result, $expected);
$xml = new Xml('<example><item><title>An example of a correctly reversed XMLNode</title><desc/></item></example>');
$xml = Xml::build('<example><item><title>An example of a correctly reversed SimpleXMLElement</title><desc/></item></example>');
$result = Set::reverse($xml);
$expected = array('Example' =>
$expected = array('example' =>
array(
'Item' => array(
'title' => 'An example of a correctly reversed XMLNode',
'desc' => array(),
'item' => array(
'title' => 'An example of a correctly reversed SimpleXMLElement',
'desc' => '',
)
)
);
$this->assertEquals($result, $expected);
$xml = new Xml('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
$xml = Xml::build('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
$result = Set::reverse($xml);
$expected =
array('Example' => array(
'Item' => array(
array('example' => array(
'item' => array(
'attr' => '123',
'Titles' => array(
'Title' => array('title1', 'title2')
'titles' => array(
'title' => array('title1', 'title2')
)
)
)
);
$this->assertEquals($result, $expected);
$xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
$xml = Xml::build('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
$result = Set::reverse($xml);
$expected =
array('Example' => array(
array('example' => array(
'attr' => 'ex_attr',
'Item' => array(
'item' => array(
'attr' => '123',
'titles' => 'list',
'value' => 'textforitems'
@ -2752,7 +2752,7 @@ class SetTest extends CakeTestCase {
$this->assertEquals($result, $expected);
$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0">
<rss version="2.0" xmlns:dc="http://www.cakephp.org/">
<channel>
<title>Cake PHP Google Group</title>
<link>http://groups.google.com/group/cake-php</link>
@ -2783,23 +2783,23 @@ class SetTest extends CakeTestCase {
</channel>
</rss>';
$xml = new Xml($string);
$xml = Xml::build($string);
$result = Set::reverse($xml);
$expected = array('Rss' => array(
$expected = array('rss' => array(
'version' => '2.0',
'Channel' => array(
'channel' => array(
'title' => 'Cake PHP Google Group',
'link' => 'http://groups.google.com/group/cake-php',
'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.',
'language' => 'en',
'Item' => array(
'item' => array(
array(
'title' => 'constructng result array when using findall',
'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br><p>Array( <br> [0] =&gt; Array(",
'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] =&gt; Array(",
'creator' => 'cakephp',
'Category' => array('cakephp', 'model'),
'category' => array('cakephp', 'model'),
'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
'author' => 'bmil...@gmail.com(bpscrugs)',
'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
@ -2809,7 +2809,7 @@ class SetTest extends CakeTestCase {
'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other',
'creator' => 'cakephp',
'Category' => array('cakephp', 'model'),
'category' => array('cakephp', 'model'),
'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
@ -2841,15 +2841,13 @@ class SetTest extends CakeTestCase {
</XRD>
</XRDS>';
$xml = new Xml($text);
$xml = Xml::build($text);
$result = Set::reverse($xml);
$expected = array('XRDS' => array(
'xmlns' => 'xri://$xrds',
'XRD' => array(
array(
'xml:id' => 'oauth',
'xmlns' => 'xri://$XRD*($v*2.0)',
'id' => 'oauth',
'version' => '2.0',
'Type' => 'xri://$xrds*simple',
'Expires' => '2008-04-13T07:34:58Z',
@ -2872,7 +2870,6 @@ class SetTest extends CakeTestCase {
)
),
array(
'xmlns' => 'xri://$XRD*($v*2.0)',
'version' => '2.0',
'Type' => 'xri://$xrds*simple',
'Service' => array(

View file

@ -38,9 +38,6 @@ class RssHelperTest extends CakeTestCase {
$controller = null;
$this->View = new View($controller);
$this->Rss = new RssHelper($this->View);
$manager =& XmlManager::getInstance();
$manager->namespaces = array();
}
/**
@ -54,52 +51,6 @@ class RssHelperTest extends CakeTestCase {
}
/**
* testAddNamespace 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);
$this->Rss->removeNs('custom');
$this->Rss->addNs('dummy', 'http://dummy.com/1.0/');
$result = $this->Rss->document();
$expected = array(
'rss' => array(
'xmlns:dummy' => 'http://dummy.com/1.0/',
'version' => '2.0'
)
);
$this->assertTags($result, $expected);
$this->Rss->removeNs('dummy');
}
/**
* testRemoveNamespace method
*
* @access public
* @return void
*/
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);
}
/**
* testDocument method
*
* @access public
@ -253,6 +204,7 @@ class RssHelperTest extends CakeTestCase {
'<link', 'http://example.com', '/link',
'/image',
'atom:link' => array(
'xmlns:atom' => 'http://www.w3.org/2005/Atom',
'href' => "http://www.example.com/rss.xml",
'rel' => "self",
'type' =>"application/rss+xml"
@ -387,22 +339,6 @@ class RssHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$item = array(
'title' => array(
'value' => 'My Title & more',
'convertEntities' => false
)
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'My Title & more',
'/title',
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'title' => array(
'value' => 'My Title & more',

View file

@ -1,289 +0,0 @@
<?php
/**
* XmlHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
App::import('Helper', 'Xml');
App::import('Core', 'View');
/**
* TestXml class
*
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
*/
class TestXmlHelper extends Object {
/**
* content property
*
* @var string ''
* @access public
*/
public $content = '';
/**
* construct method
*
* @param mixed $content
* @access private
* @return void
*/
function __construct($content) {
$this->content = $content;
}
/**
* toString method
*
* @access public
* @return void
*/
function toString() {
return $this->content;
}
}
/**
* XmlHelperTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
*/
class XmlHelperTest extends CakeTestCase {
/**
* setUp method
*
* @access public
* @return void
*/
function setUp() {
$controller = null;
$View = new View($controller);
$this->Xml = new XmlHelper($View);
$manager =& XmlManager::getInstance();
$manager->namespaces = array();
}
/**
* tearDown method
*
* @access public
* @return void
*/
function tearDown() {
unset($this->Xml);
}
/**
* testAddNamespace method
*
* @access public
* @return void
*/
function testAddNamespace() {
$this->Xml->addNs('custom', 'http://example.com/dtd.xml');
$manager =& XmlManager::getInstance();
$expected = array('custom' => 'http://example.com/dtd.xml');
$this->assertEqual($manager->namespaces, $expected);
}
/**
* testRemoveNamespace method
*
* @access public
* @return void
*/
function testRemoveNamespace() {
$this->Xml->addNs('custom', 'http://example.com/dtd.xml');
$this->Xml->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->Xml->removeNs('custom');
$expected = array('custom2' => 'http://example.com/dtd2.xml');
$this->assertEqual($manager->namespaces, $expected);
}
/**
* testRenderZeroElement method
*
* @access public
* @return void
*/
function testRenderZeroElement() {
$result = $this->Xml->elem('count', null, 0);
$expected = '<count>0</count>';
$this->assertEqual($result, $expected);
$result = $this->Xml->elem('count', null, array('cdata' => true, 'value' => null));
$expected = '<count />';
$this->assertEqual($result, $expected);
}
/**
* testRenderElementWithNamespace method
*
* @access public
* @return void
*/
function testRenderElementWithNamespace() {
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), 'content');
$expected = '<myNameSpace:count>content</myNameSpace:count>';
$this->assertEqual($result, $expected);
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), 'content', false);
$expected = '<myNameSpace:count>content';
$this->assertEqual($result, $expected);
$expected .= '</myNameSpace:count>';
$result .= $this->Xml->closeElem();
$this->assertEqual($result, $expected);
}
/**
* testRenderElementWithComplexContent method
*
* @access public
* @return void
*/
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);
}
/**
* testSerialize method
*
* @access public
* @return void
*/
function testSerialize() {
$data = array(
'test1' => 'test with no quotes',
'test2' => 'test with "double quotes"'
);
$result = $this->Xml->serialize($data);
$expected = '<std_class test1="test with no quotes" test2="test with &quot;double quotes&quot;" />';
$this->assertIdentical($result, $expected);
$data = array(
'test1' => 'test with no quotes',
'test2' => 'test without double quotes'
);
$result = $this->Xml->serialize($data);
$expected = '<std_class test1="test with no quotes" test2="test without double quotes" />';
$this->assertIdentical($result, $expected);
$data = array(
'ServiceDay' => array('ServiceTime' => array('ServiceTimePrice' => array('dollar' => 1, 'cents' => '2')))
);
$result = $this->Xml->serialize($data);
$expected = '<service_day><service_time><service_time_price dollar="1" cents="2" /></service_time></service_day>';
$this->assertIdentical($result, $expected);
$data = array(
'ServiceDay' => array('ServiceTime' => array('ServiceTimePrice' => array('dollar' => 1, 'cents' => '2')))
);
$result = $this->Xml->serialize($data, array('format' => 'tags'));
$expected = '<service_day><service_time><service_time_price><dollar>1</dollar><cents>2</cents></service_time_price></service_time></service_day>';
$this->assertIdentical($result, $expected);
$data = array(
'Pages' => array('id' => 2, 'url' => 'http://www.url.com/rb/153/?id=bbbb&t=access')
);
$result = $this->Xml->serialize($data);
$expected = '<pages id="2" url="http://www.url.com/rb/153/?id=bbbb&amp;t=access" />';
$this->assertIdentical($result, $expected);
$test = array(
'Test' => array('test' => true)
);
$expected = '<test test="1" />';
$result = $this->Xml->serialize($test);
$this->assertidentical($expected, $result);
}
/**
* testSerializeOnMultiDimensionalArray method
*
* @access public
* @return void
*/
function testSerializeOnMultiDimensionalArray() {
$data = array(
'Statuses' => array(
array('Status' => array('id' => 1)),
array('Status' => array('id' => 2))
)
);
$result = $this->Xml->serialize($data, array('format' => 'tags'));
$expected = '<statuses><status><id>1</id></status><status><id>2</id></status></statuses>';
$this->assertIdentical($result, $expected);
}
/**
* testHeader method
*
* @access public
* @return void
*/
function testHeader() {
$expectedDefaultEncoding = Configure::read('App.encoding');
if (empty($expectedDefaultEncoding)) {
$expectedDefaultEncoding = 'UTF-8';
}
$attrib = array();
$result = $this->Xml->header($attrib);
$expected = '<?xml version="1.0" encoding="'.$expectedDefaultEncoding.'" ?>';
$this->assertIdentical($result, $expected);
$attrib = array(
'encoding' => 'UTF-8',
'version' => '1.1'
);
$result = $this->Xml->header($attrib);
$expected = '<?xml version="1.1" encoding="UTF-8" ?>';
$this->assertIdentical($result, $expected);
$attrib = array(
'encoding' => 'UTF-8',
'version' => '1.2',
'additional' => 'attribute'
);
$result = $this->Xml->header($attrib);
$expected = '<?xml version="1.2" encoding="UTF-8" additional="attribute" ?>';
$this->assertIdentical($result, $expected);
$attrib = 'encoding="UTF-8" someOther="value"';
$result = $this->Xml->header($attrib);
$expected = '<?xml encoding="UTF-8" someOther="value" ?>';
$this->assertIdentical($result, $expected);
}
}

File diff suppressed because it is too large Load diff

33
cake/tests/fixtures/rss.xml vendored Normal file
View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="http://bakery.cakephp.org/articles/rss" rel="self" type="application/rss+xml" />
<title>The Bakery: </title>
<link>http://bakery.cakephp.org/</link>
<description>Recent Articles at The Bakery.</description>
<language>en-us</language>
<pubDate>Wed, 01 Sep 2010 12:09:25 -0500</pubDate>
<docs>http://validator.w3.org/feed/docs/rss2.html</docs>
<generator>CakePHP Bakery</generator>
<managingEditor>mariano@cricava.com (Mariano Iglesias)</managingEditor>
<webMaster>gwoo@cakephp.org (Garrett Woodworth)</webMaster>
<item>
<title>EpisodeCMS</title>
<link>http://bakery.cakephp.org/articles/view/episodecms</link>
<description>EpisodeCMS is CakePHP based content management system.
Features: control panel, events API, module management, multilanguage and translations, themes
http://episodecms.com/
Please help me to improve it. Thanks.</description>
<pubDate>Tue, 31 Aug 2010 02:07:02 -0500</pubDate>
<guid>http://bakery.cakephp.org/articles/view/episodecms</guid>
</item>
<item>
<title>Alertpay automated sales via IPN</title>
<link>http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn</link>
<description>I&#039;m going to show you how I implemented a payment module via the Alertpay payment processor.</description>
<pubDate>Tue, 31 Aug 2010 01:42:00 -0500</pubDate>
<guid>http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn</guid>
</item>
</channel>
</rss>

9
cake/tests/fixtures/sample.xml vendored Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<tags>
<tag id="1">
<name>defect</name>
</tag>
<tag id="2">
<name>enhancement</name>
</tag>
</tags>

12
cake/tests/fixtures/soap_request.xml vendored Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>

12
cake/tests/fixtures/soap_response.xml vendored Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>