Skip to content

Commit

Permalink
Updating Set to use new Xml class.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Jul 28, 2010
1 parent b862d68 commit 53f8353
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
5 changes: 2 additions & 3 deletions cake/libs/set.php
Expand Up @@ -941,9 +941,8 @@ public static function combine($data, $path1 = null, $path2 = null, $groupPath =
*/
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_'])) {
Expand Down
63 changes: 30 additions & 33 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -2662,20 +2662,20 @@ function testXmlSetReverse() {
</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',
Expand All @@ -2694,43 +2694,43 @@ function testXmlSetReverse() {
$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'
Expand All @@ -2740,7 +2740,7 @@ function testXmlSetReverse() {
$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>
Expand Down Expand Up @@ -2771,23 +2771,23 @@ function testXmlSetReverse() {
</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',
Expand All @@ -2797,7 +2797,7 @@ function testXmlSetReverse() {
'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'
Expand Down Expand Up @@ -2829,15 +2829,13 @@ function testXmlSetReverse() {
</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',
Expand All @@ -2860,7 +2858,6 @@ function testXmlSetReverse() {
)
),
array(
'xmlns' => 'xri://$XRD*($v*2.0)',
'version' => '2.0',
'Type' => 'xri://$xrds*simple',
'Service' => array(
Expand Down

0 comments on commit 53f8353

Please sign in to comment.