fixes #4778, rss helper addNs, closes #4949 xml helper serialize with test case

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7227 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-06-21 15:23:58 +00:00
parent ebe635a827
commit 42db64bbb3
6 changed files with 157 additions and 79 deletions

View file

@ -111,6 +111,7 @@ class RssHelper extends XmlHelper {
if (!isset($attrib['version']) || empty($attrib['version'])) { if (!isset($attrib['version']) || empty($attrib['version'])) {
$attrib['version'] = $this->version; $attrib['version'] = $this->version;
} }
return $this->elem('rss', $attrib, $content); return $this->elem('rss', $attrib, $content);
} }
/** /**

View file

@ -43,6 +43,15 @@ class XmlHelper extends AppHelper {
* @var string * @var string
*/ */
var $encoding = 'UTF-8'; var $encoding = 'UTF-8';
/**
* Constructor
* @return void
*/
function __construct() {
parent::__construct();
$this->Xml =& new Xml();
$this->Xml->options(array('verifyNs' => false));
}
/** /**
* Returns an XML document header * Returns an XML document header
* *
@ -114,6 +123,7 @@ class XmlHelper extends AppHelper {
$children = $content; $children = $content;
$content = null; $content = null;
} }
$elem =& $this->Xml->createElement($name, $content, $attrib, $namespace); $elem =& $this->Xml->createElement($name, $content, $attrib, $namespace);
foreach ($children as $child) { foreach ($children as $child) {
$elem->createElement($child); $elem->createElement($child);
@ -125,6 +135,11 @@ class XmlHelper extends AppHelper {
} }
return $this->output($out); return $this->output($out);
} }
/**
* Create closing tag for current element
*
* @return string
*/
function closeElem() { function closeElem() {
$name = $this->Xml->name(); $name = $this->Xml->name();
if ($parent =& $this->Xml->parent()) { if ($parent =& $this->Xml->parent()) {
@ -140,14 +155,8 @@ class XmlHelper extends AppHelper {
* @return string A copy of $data in XML format * @return string A copy of $data in XML format
*/ */
function serialize($data, $options = array()) { function serialize($data, $options = array()) {
$data = new Xml($data, array_merge(array('attributes' => false, 'format' => 'attributes'), $options)); $data =& new Xml($data, array_merge(array('attributes' => false, 'format' => 'attributes'), $options));
return $data->toString(array_merge(array('header' => false), $options)); return $data->toString(array_merge(array('header' => false), $options));
} }
function beforeRender() {
$this->Xml =& new Xml();
$this->Xml->options(array('verifyNs' => false));
}
} }
?> ?>

View file

@ -572,13 +572,23 @@ class XmlNode extends Object {
if ($options['whitespace']) { if ($options['whitespace']) {
$d .= str_repeat("\t", $depth); $d .= str_repeat("\t", $depth);
} }
$d .= '<' . $this->name(); $d .= '<' . $this->name();
if (is_array($this->namespaces) && count($this->namespaces) > 0) { if (count($this->namespaces) > 0) {
foreach ($this->namespaces as $key => $val) { foreach ($this->namespaces as $key => $val) {
$val = str_replace('"', '\"', $val); $val = str_replace('"', '\"', $val);
$d .= ' xmlns:' . $key . '="' . $val . '"'; $d .= ' xmlns:' . $key . '="' . $val . '"';
} }
} }
$parent =& $this->parent();
if ($parent->name === '#document' && count($parent->namespaces) > 0) {
foreach ($parent->namespaces as $key => $val) {
$val = str_replace('"', '\"', $val);
$d .= ' xmlns:' . $key . '="' . $val . '"';
}
}
if (is_array($this->attributes) && count($this->attributes) > 0) { if (is_array($this->attributes) && count($this->attributes) > 0) {
foreach ($this->attributes as $key => $val) { foreach ($this->attributes as $key => $val) {
$val = str_replace('"', '\"', $val); $val = str_replace('"', '\"', $val);
@ -621,6 +631,7 @@ class XmlNode extends Object {
} }
} }
} }
return $d; return $d;
} }
/** /**
@ -918,6 +929,7 @@ class Xml extends XmlNode {
if (is_bool($options)) { if (is_bool($options)) {
$options = array('header' => $options); $options = array('header' => $options);
} }
$defaults = array('header' => false, 'encoding' => $this->encoding); $defaults = array('header' => false, 'encoding' => $this->encoding);
$options = array_merge($defaults, Xml::options(), $options); $options = array_merge($defaults, Xml::options(), $options);
$data = parent::toString($options, 0); $data = parent::toString($options, 0);
@ -928,14 +940,21 @@ class Xml extends XmlNode {
} }
return $this->header() . "\n" . $data; return $this->header() . "\n" . $data;
} }
return $data; return $data;
} }
/**
* Return a header used on the first line of the xml file
*
* @param mixed $attrib attributes of the header element
* @return string formated header
*/
function header($attrib = array()) { function header($attrib = array()) {
$header = 'xml'; $header = 'xml';
if (is_string($attrib)) { if (is_string($attrib)) {
$header = $attrib; $header = $attrib;
} else { } else {
$attrib = array_merge(array('version' => $this->version, 'encoding' => $this->encoding), $attrib); $attrib = array_merge(array('version' => $this->version, 'encoding' => $this->encoding), $attrib);
foreach ($attrib as $key=>$val) { foreach ($attrib as $key=>$val) {
$header .= ' ' . $key . '="' . $val . '"'; $header .= ' ' . $key . '="' . $val . '"';
@ -966,21 +985,20 @@ class Xml extends XmlNode {
*/ */
function addGlobalNs($name, $url = null) { function addGlobalNs($name, $url = null) {
$_this =& XmlManager::getInstance(); $_this =& XmlManager::getInstance();
if ($ns = Xml::__resolveNamespace($name, $url)) { if ($ns = Xml::resolveNamespace($name, $url)) {
$_this->namespaces = array_merge($_this->namespaces, $ns); $_this->namespaces = array_merge($_this->namespaces, $ns);
return $ns; return $ns;
} }
return false; return false;
} }
/** /**
* Private method * Resolves current namespace
* *
* @param string $name * @param string $name
* @param string $url * @param string $url
* @return array * @return array
* @access private
*/ */
function __resolveNamespace($name, $url) { function resolveNamespace($name, $url) {
$_this =& XmlManager::getInstance(); $_this =& XmlManager::getInstance();
if ($url == null && in_array($name, array_keys($_this->defaultNamespaceMap))) { if ($url == null && in_array($name, array_keys($_this->defaultNamespaceMap))) {
$url = $_this->defaultNamespaceMap[$name]; $url = $_this->defaultNamespaceMap[$name];
@ -1013,15 +1031,16 @@ class Xml extends XmlNode {
*/ */
function removeGlobalNs($name) { function removeGlobalNs($name) {
$_this =& XmlManager::getInstance(); $_this =& XmlManager::getInstance();
if (in_array($name, array_keys($_this->namespaces))) { if (in_array($name, array_keys($_this->namespaces))) {
unset($_this->namespaces[$name]); unset($_this->namespaces[$name]);
unset($this->namespaces[$name]);
} elseif (in_array($name, $_this->namespaces)) { } elseif (in_array($name, $_this->namespaces)) {
$keys = array_keys($_this->namespaces); $keys = array_keys($_this->namespaces);
$count = count($keys); $count = count($keys);
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if ($_this->namespaces[$keys[$i]] == $name) { if ($_this->namespaces[$keys[$i]] == $name) {
unset($_this->namespaces[$keys[$i]]); unset($_this->namespaces[$keys[$i]]);
unset($this->namespaces[$keys[$i]]);
return; return;
} }
} }
@ -1050,18 +1069,39 @@ class Xml extends XmlNode {
return $_this->options; return $_this->options;
} }
} }
/**
* The XML Element
*
*/
class XmlElement extends XmlNode { class XmlElement extends XmlNode {
/**
* Construct an Xml element
*
* @param string $name name of the node
* @param string $value value of the node
* @param array $attributes
* @param string $namespace
* @return string A copy of $data in XML format
*/
function __construct($name = null, $value = null, $attributes = array(), $namespace = false) { function __construct($name = null, $value = null, $attributes = array(), $namespace = false) {
parent::__construct($name, $value, $namespace); parent::__construct($name, $value, $namespace);
$this->addAttribute($attributes); $this->addAttribute($attributes);
} }
/**
* Get all the attributes for this element
*
* @return array
*/
function attributes() { function attributes() {
return $this->attributes; return $this->attributes;
} }
/**
* Add attributes to this element
*
* @param string $name name of the node
* @param string $value value of the node
* @return boolean
*/
function addAttribute($name, $val = null) { function addAttribute($name, $val = null) {
if (is_object($name)) { if (is_object($name)) {
$name = get_object_vars($name); $name = get_object_vars($name);
@ -1091,7 +1131,12 @@ class XmlElement extends XmlNode {
} }
return false; return false;
} }
/**
* Remove attributes to this element
*
* @param string $name name of the node
* @return boolean
*/
function removeAttribute($attr) { function removeAttribute($attr) {
if ($this->attributes[$attr]) { if ($this->attributes[$attr]) {
unset($this->attributes[$attr]); unset($this->attributes[$attr]);
@ -1182,8 +1227,6 @@ class XmlTextNode extends XmlNode {
return $val; return $val;
} }
} }
/** /**
* Manages application-wide namespaces and XML parsing/generation settings. * Manages application-wide namespaces and XML parsing/generation settings.
* Private class, used exclusively within scope of XML class. * Private class, used exclusively within scope of XML class.
@ -1239,5 +1282,4 @@ class XmlManager {
return $instance[0]; return $instance[0];
} }
} }
?> ?>

View file

@ -70,6 +70,14 @@ class RssTest extends CakeTestCase {
$expected = array('custom' => 'http://example.com/dtd.xml'); $expected = array('custom' => 'http://example.com/dtd.xml');
$this->assertEqual($manager->namespaces, $expected); $this->assertEqual($manager->namespaces, $expected);
$this->Rss->removeNs('custom');
$this->Rss->addNs('dummy', 'http://dummy.com/1.0/');
$res = $this->Rss->document();
$this->assertPattern('/^<rss xmlns:dummy="http:\/\/dummy\.com\/1.0\/" version="2.0" \/>$/', $res);
$this->Rss->removeNs('dummy');
} }
/** /**
* testRemoveNamespace method * testRemoveNamespace method

View file

@ -182,6 +182,20 @@ class XmlHelperTest extends UnitTestCase {
$result = $this->Xml->serialize($data); $result = $this->Xml->serialize($data);
$expected = '<std_class test1="test with no quotes" test2="test without double quotes" />'; $expected = '<std_class test1="test with no quotes" test2="test without double quotes" />';
$this->assertIdentical($result, $expected); $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);
} }
/** /**
* testHeader method * testHeader method

View file

@ -35,6 +35,10 @@ App::import('Core', 'Xml');
* @subpackage cake.tests.cases.libs * @subpackage cake.tests.cases.libs
*/ */
class XmlTest extends UnitTestCase { class XmlTest extends UnitTestCase {
function KgetTests() {
return array('testRootTagParsing');
}
/** /**
* testRootTagParsing method * testRootTagParsing method
* *
@ -42,7 +46,11 @@ class XmlTest extends UnitTestCase {
* @return void * @return void
*/ */
function testRootTagParsing() { function testRootTagParsing() {
$input = '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . "\n" . '<plugin id="1" version_id="1" name="my_plugin" title="My Plugin" author="Me" author_email="me@cakephp.org" description="My awesome package" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13"><current id="1" plugin_id="1" name="1.0" file="" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13"/><version id="1" plugin_id="1" name="1.0" file="" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13" /></plugin>'; $input = '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . "\n" .
'<plugin id="1" version_id="1" name="my_plugin" title="My Plugin" author="Me" author_email="me@cakephp.org" description="My awesome package" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13">'
.'<current id="1" plugin_id="1" name="1.0" file="" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13" />'
.'<version id="1" plugin_id="1" name="1.0" file="" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13" />'
.'</plugin>';
$xml = new Xml($input); $xml = new Xml($input);
$this->assertEqual($xml->children[0]->name, 'plugin'); $this->assertEqual($xml->children[0]->name, 'plugin');
$this->assertEqual($xml->children[0]->children[0]->name, 'current'); $this->assertEqual($xml->children[0]->children[0]->name, 'current');
@ -72,7 +80,7 @@ class XmlTest extends UnitTestCase {
$xml = new Xml($input); $xml = new Xml($input);
$result = preg_replace("/\n/",'', $xml->toString(false)); $result = preg_replace("/\n/",'', $xml->toString(false));
$expected = '<project id="1" title="" client_id="1" show="1" is_spotlight="" style_id="0" job_type_id="1" industry_id="1" modified="" created=""><style id="" name=""/><job_type id="1" name="Touch Screen Kiosk" /><industry id="1" name="Financial" /></project><project id="2" title="" client_id="2" show="1" is_spotlight="" style_id="0" job_type_id="2" industry_id="2" modified="2007-11-26 14:48:36" created=""><style id="" name="" /><job_type id="2" name="Awareness Campaign" /><industry id="2" name="Education" /></project>'; $expected = '<project id="1" title="" client_id="1" show="1" is_spotlight="" style_id="0" job_type_id="1" industry_id="1" modified="" created=""><style id="" name="" /><job_type id="1" name="Touch Screen Kiosk" /><industry id="1" name="Financial" /></project><project id="2" title="" client_id="2" show="1" is_spotlight="" style_id="0" job_type_id="2" industry_id="2" modified="2007-11-26 14:48:36" created=""><style id="" name="" /><job_type id="2" name="Awareness Campaign" /><industry id="2" name="Education" /></project>';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$input = array( $input = array(
@ -81,7 +89,7 @@ class XmlTest extends UnitTestCase {
'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'), 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
'Industry' => array('id' => 1, 'name' => 'Financial') 'Industry' => array('id' => 1, 'name' => 'Financial')
); );
$expected = '<project id="1" title="" client_id="1" show="1" is_spotlight="" style_id="0" job_type_id="1" industry_id="1" modified="" created=""><style id="" name=""/><job_type id="1" name="Touch Screen Kiosk" /><industry id="1" name="Financial" /></project>'; $expected = '<project id="1" title="" client_id="1" show="1" is_spotlight="" style_id="0" job_type_id="1" industry_id="1" modified="" created=""><style id="" name="" /><job_type id="1" name="Touch Screen Kiosk" /><industry id="1" name="Financial" /></project>';
$xml = new Xml($input); $xml = new Xml($input);
$result = preg_replace("/\n/",'', $xml->toString(false)); $result = preg_replace("/\n/",'', $xml->toString(false));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
@ -183,7 +191,7 @@ class XmlTest extends UnitTestCase {
'Industry' => array('id' => 2, 'name' => 'Education'), 'Industry' => array('id' => 2, 'name' => 'Education'),
) )
); );
$expected = '<project><id>1</id><title/><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry></project>'; $expected = '<project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry></project>';
$xml = new Xml($input, array('format' => 'tags')); $xml = new Xml($input, array('format' => 'tags'));
$result = $xml->toString(array('header' => false, 'cdata' => false)); $result = $xml->toString(array('header' => false, 'cdata' => false));
@ -224,7 +232,7 @@ class XmlTest extends UnitTestCase {
) )
) )
); );
$expected = '<project><id>1</id><title/><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry><business_solution><id>6</id><name>Convert Sales</name></business_solution><media_type><id>15</id><name>Print</name></media_type><media_type><id>7</id><name>Web Demo</name></media_type><media_type><id>6</id><name>CD-ROM</name></media_type></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry><business_solution><id>4</id><name>Build Relationship</name></business_solution><business_solution><id>6</id><name>Convert Sales</name></business_solution><media_type><id>17</id><name>Web</name></media_type><media_type><id>6</id><name>CD-ROM</name></media_type></project>'; $expected = '<project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry><business_solution><id>6</id><name>Convert Sales</name></business_solution><media_type><id>15</id><name>Print</name></media_type><media_type><id>7</id><name>Web Demo</name></media_type><media_type><id>6</id><name>CD-ROM</name></media_type></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry><business_solution><id>4</id><name>Build Relationship</name></business_solution><business_solution><id>6</id><name>Convert Sales</name></business_solution><media_type><id>17</id><name>Web</name></media_type><media_type><id>6</id><name>CD-ROM</name></media_type></project>';
$xml = new Xml($input, array('format' => 'tags')); $xml = new Xml($input, array('format' => 'tags'));
$result = $xml->toString(array('header' => false, 'cdata' => false)); $result = $xml->toString(array('header' => false, 'cdata' => false));
@ -391,7 +399,7 @@ class XmlTest extends UnitTestCase {
'Industry' => array('id' => 2, 'name' => 'Education'), 'Industry' => array('id' => 2, 'name' => 'Education'),
) )
); );
$expected = '<project><id>1</id><title/><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1.89</job_type_id><industry_id>1.56</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name><![CDATA[Touch Screen Kiosk]]></name></job_type><industry><id>1</id><name><![CDATA[Financial]]></name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2.2</job_type_id><industry_id>2.2</industry_id><modified><![CDATA[2007-11-26 14:48:36]]></modified><created /><style><id /><name /></style><job_type><id>2</id><name><![CDATA[Awareness Campaign]]></name></job_type><industry><id>2</id><name><![CDATA[Education]]></name></industry></project>'; $expected = '<project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1.89</job_type_id><industry_id>1.56</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name><![CDATA[Touch Screen Kiosk]]></name></job_type><industry><id>1</id><name><![CDATA[Financial]]></name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2.2</job_type_id><industry_id>2.2</industry_id><modified><![CDATA[2007-11-26 14:48:36]]></modified><created /><style><id /><name /></style><job_type><id>2</id><name><![CDATA[Awareness Campaign]]></name></job_type><industry><id>2</id><name><![CDATA[Education]]></name></industry></project>';
$xml = new Xml($input, array('format' => 'tags')); $xml = new Xml($input, array('format' => 'tags'));
$result = $xml->toString(array('header' => false, 'cdata' => true)); $result = $xml->toString(array('header' => false, 'cdata' => true));
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
@ -429,7 +437,7 @@ class XmlTest extends UnitTestCase {
'Industry' => array('id' => 2, 'name' => 'Education'), 'Industry' => array('id' => 2, 'name' => 'Education'),
) )
); );
$expected = "\n\t<project>\n\t\t<id>\n\t\t\t1\n\t\t</id>\n\t\t<title/>\n\t\t<client_id>\n\t\t\t1\n\t\t</client_id>\n\t\t<show>\n\t\t\t1\n\t\t</show>\n\t\t<is_spotlight />\n\t\t<style_id>\n\t\t\t0\n\t\t</style_id>\n\t\t<job_type_id>\n\t\t\t1\n\t\t</job_type_id>\n\t\t<industry_id>\n\t\t\t1\n\t\t</industry_id>\n\t\t<modified />\n\t\t<created />\n\t\t<style>\n\t\t\t<id />\n\t\t\t<name />\n\t\t</style>\n\t\t<job_type>\n\t\t\t<id>\n\t\t\t\t1\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tTouch Screen Kiosk\n\t\t\t</name>\n\t\t</job_type>\n\t\t<industry>\n\t\t\t<id>\n\t\t\t\t1\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tFinancial\n\t\t\t</name>\n\t\t</industry>\n\t</project>\n\t<project>\n\t\t<id>\n\t\t\t2\n\t\t</id>\n\t\t<title />\n\t\t<client_id>\n\t\t\t2\n\t\t</client_id>\n\t\t<show>\n\t\t\t1\n\t\t</show>\n\t\t<is_spotlight />\n\t\t<style_id>\n\t\t\t0\n\t\t</style_id>\n\t\t<job_type_id>\n\t\t\t2\n\t\t</job_type_id>\n\t\t<industry_id>\n\t\t\t2\n\t\t</industry_id>\n\t\t<modified>\n\t\t\t2007-11-26 14:48:36\n\t\t</modified>\n\t\t<created />\n\t\t<style>\n\t\t\t<id />\n\t\t\t<name />\n\t\t</style>\n\t\t<job_type>\n\t\t\t<id>\n\t\t\t\t2\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tAwareness Campaign\n\t\t\t</name>\n\t\t</job_type>\n\t\t<industry>\n\t\t\t<id>\n\t\t\t\t2\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tEducation\n\t\t\t</name>\n\t\t</industry>\n\t</project>\n"; $expected = "\n\t<project>\n\t\t<id>\n\t\t\t1\n\t\t</id>\n\t\t<title />\n\t\t<client_id>\n\t\t\t1\n\t\t</client_id>\n\t\t<show>\n\t\t\t1\n\t\t</show>\n\t\t<is_spotlight />\n\t\t<style_id>\n\t\t\t0\n\t\t</style_id>\n\t\t<job_type_id>\n\t\t\t1\n\t\t</job_type_id>\n\t\t<industry_id>\n\t\t\t1\n\t\t</industry_id>\n\t\t<modified />\n\t\t<created />\n\t\t<style>\n\t\t\t<id />\n\t\t\t<name />\n\t\t</style>\n\t\t<job_type>\n\t\t\t<id>\n\t\t\t\t1\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tTouch Screen Kiosk\n\t\t\t</name>\n\t\t</job_type>\n\t\t<industry>\n\t\t\t<id>\n\t\t\t\t1\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tFinancial\n\t\t\t</name>\n\t\t</industry>\n\t</project>\n\t<project>\n\t\t<id>\n\t\t\t2\n\t\t</id>\n\t\t<title />\n\t\t<client_id>\n\t\t\t2\n\t\t</client_id>\n\t\t<show>\n\t\t\t1\n\t\t</show>\n\t\t<is_spotlight />\n\t\t<style_id>\n\t\t\t0\n\t\t</style_id>\n\t\t<job_type_id>\n\t\t\t2\n\t\t</job_type_id>\n\t\t<industry_id>\n\t\t\t2\n\t\t</industry_id>\n\t\t<modified>\n\t\t\t2007-11-26 14:48:36\n\t\t</modified>\n\t\t<created />\n\t\t<style>\n\t\t\t<id />\n\t\t\t<name />\n\t\t</style>\n\t\t<job_type>\n\t\t\t<id>\n\t\t\t\t2\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tAwareness Campaign\n\t\t\t</name>\n\t\t</job_type>\n\t\t<industry>\n\t\t\t<id>\n\t\t\t\t2\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tEducation\n\t\t\t</name>\n\t\t</industry>\n\t</project>\n";
$xml = new Xml($input, array('format' => 'tags')); $xml = new Xml($input, array('format' => 'tags'));
$result = $xml->toString(array('header' => false, 'cdata' => false, 'whitespace' => true)); $result = $xml->toString(array('header' => false, 'cdata' => false, 'whitespace' => true));
@ -456,7 +464,7 @@ class XmlTest extends UnitTestCase {
'Industry' => array('id' => 2, 'name' => 'Education'), 'Industry' => array('id' => 2, 'name' => 'Education'),
) )
); );
$expected = '<project><id>1</id><title/><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry></project>'; $expected = '<project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry></project>';
$xml = new Xml(Set::map($input), array('format' => 'tags')); $xml = new Xml(Set::map($input), array('format' => 'tags'));
$result = $xml->toString(array('header' => false, 'cdata' => false)); $result = $xml->toString(array('header' => false, 'cdata' => false));
@ -493,7 +501,7 @@ class XmlTest extends UnitTestCase {
* @return void * @return void
*/ */
function testComplexParsing() { function testComplexParsing() {
$source = '<projects><project><id>1</id><title/><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry></project></projects>'; $source = '<projects><project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry></project></projects>';
$xml = new Xml($source); $xml = new Xml($source);
$result = $xml->toString(array('cdata' => false)); $result = $xml->toString(array('cdata' => false));
$this->assertEqual($source, $result); $this->assertEqual($source, $result);
@ -535,10 +543,6 @@ class XmlTest extends UnitTestCase {
$this->assertEqual($expects, $result); $this->assertEqual($expects, $result);
} }
/*
* @todo Add test for default namespaces
*/
} }
?> ?>