Fixing XML support in Model and Set classes

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6427 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-02-02 20:45:37 +00:00
parent 71bd08b950
commit acfc38e57d
4 changed files with 56 additions and 42 deletions

View file

@ -792,7 +792,7 @@ class Set extends Object {
$out = array(); $out = array();
if (is_a($object, 'xmlnode') || is_a($object, 'XMLNode')) { if (is_a($object, 'xmlnode') || is_a($object, 'XMLNode')) {
if (isset($object->name) && isset($object->children)) { if (isset($object->name) && isset($object->children)) {
if ($object->name === 'root' && !empty($object->children)) { if ($object->name === '#document' && !empty($object->children)) {
$out = Set::reverse($object->children[0]); $out = Set::reverse($object->children[0]);
} else { } else {
$children = array(); $children = array();

View file

@ -1177,15 +1177,16 @@ class XMLManager {
* @var array * @var array
*/ */
var $__defaultNamespaceMap = array( var $__defaultNamespaceMap = array(
'dc' => 'http://purl.org/dc/elements/1.1/', // Dublin Core 'dc' => 'http://purl.org/dc/elements/1.1/', // Dublin Core
'dct' => 'http://purl.org/dc/terms/', // Dublin Core Terms 'dct' => 'http://purl.org/dc/terms/', // Dublin Core Terms
'g' => 'http://base.google.com/ns/1.0', // Google Base 'g' => 'http://base.google.com/ns/1.0', // Google Base
'rc' => 'http://purl.org/rss/1.0/modules/content/', // RSS 1.0 Content Module 'rc' => 'http://purl.org/rss/1.0/modules/content/', // RSS 1.0 Content Module
'wf' => 'http://wellformedweb.org/CommentAPI/', // Well-Formed Web Comment API 'wf' => 'http://wellformedweb.org/CommentAPI/', // Well-Formed Web Comment API
'fb' => 'http://rssnamespace.org/feedburner/ext/1.0', // FeedBurner extensions 'fb' => 'http://rssnamespace.org/feedburner/ext/1.0', // FeedBurner extensions
'lj' => 'http://www.livejournal.org/rss/lj/1.0/', // Live Journal 'lj' => 'http://www.livejournal.org/rss/lj/1.0/', // Live Journal
'itunes' => 'http://www.itunes.com/dtds/podcast-1.0.dtd', // iTunes 'itunes' => 'http://www.itunes.com/dtds/podcast-1.0.dtd', // iTunes
'xhtml' => 'http://www.w3.org/1999/xhtml' // XHTML 'xhtml' => 'http://www.w3.org/1999/xhtml', // XHTML,
'atom' => 'http://www.w3.org/2005/Atom' // Atom
); );
/** /**
* Returns a reference to the global XML object that manages app-wide XML settings * Returns a reference to the global XML object that manages app-wide XML settings

View file

@ -1990,10 +1990,10 @@ class ModelTest extends CakeTestCase {
function testSaveFromXml() { function testSaveFromXml() {
$this->loadFixtures('Article'); $this->loadFixtures('Article');
if (!class_exists('Xml')) { App::import('Core', 'Xml');
uses('xml');
}
$Article = new Article(); $Article = new Article();
$Article->save(new Xml('<article title="test xml" user_id="5" />'));
$this->assertTrue($Article->save(new Xml('<article title="test xml" user_id="5" />'))); $this->assertTrue($Article->save(new Xml('<article title="test xml" user_id="5" />')));
$results = $Article->find(array('Article.title' => 'test xml')); $results = $Article->find(array('Article.title' => 'test xml'));

View file

@ -429,6 +429,18 @@ class SetTest extends UnitTestCase {
$result = Set::reverse($map); $result = Set::reverse($map);
$this->assertIdentical($result, $expected); $this->assertIdentical($result, $expected);
$expected = array(
'Post' => array('id'=> 1, 'title' => 'First Post'),
'Comment' => array(
array('id'=> 1, 'title' => 'First Comment'),
array('id'=> 2, 'title' => 'Second Comment')
),
'Tag' => array(
array('id'=> 1, 'title' => 'First Tag'),
array('id'=> 2, 'title' => 'Second Tag')
),
);
$map = Set::map($expected); $map = Set::map($expected);
$this->assertIdentical($map->title, $expected['Post']['title']); $this->assertIdentical($map->title, $expected['Post']['title']);
foreach ($map->Comment as $comment) { foreach ($map->Comment as $comment) {
@ -942,9 +954,8 @@ class SetTest extends UnitTestCase {
} }
function testXmlSetReverse() { function testXmlSetReverse() {
if (!class_exists('Xml')) { App::import('Core', 'Xml');
uses('Xml');
}
$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> $string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0"> <rss version="2.0">
<channel> <channel>
@ -972,32 +983,34 @@ class SetTest extends UnitTestCase {
</rss>'; </rss>';
$xml = new Xml($string); $xml = new Xml($string);
$result = Set::reverse($xml); $result = Set::reverse($xml);
$expected = array('Rss' => array('version' => '2.0', $expected = array('Rss' => array(
'Channel' => array( 'version' => '2.0',
array('title' => 'Cake PHP Google Group', 'Channel' => array(
'link' => 'http://groups.google.com/group/cake-php', array('title' => 'Cake PHP Google Group',
'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.', 'link' => 'http://groups.google.com/group/cake-php',
'language' => 'en', '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.',
'Item' => array( 'language' => 'en',
array('title' => 'constructng result array when using findall', 'Item' => array(
'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f', 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(", 'title' => 'constructng result array when using findall',
'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'), 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
'author' => 'bmil...@gmail.com(bpscrugs)', '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(",
'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT', 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
), 'author' => 'bmil...@gmail.com(bpscrugs)',
array('title' => 'Re: share views between actions?', 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
'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', array(
'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'), 'title' => 'Re: share views between actions?',
'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)', 'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT' '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',
) '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'
) )
) )
); )
)
));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$string ='<data><post title="Title of this post" description="cool" /></data>'; $string ='<data><post title="Title of this post" description="cool" /></data>';