mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7227 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
ebe635a827
commit
42db64bbb3
6 changed files with 157 additions and 79 deletions
|
@ -111,6 +111,7 @@ class RssHelper extends XmlHelper {
|
|||
if (!isset($attrib['version']) || empty($attrib['version'])) {
|
||||
$attrib['version'] = $this->version;
|
||||
}
|
||||
|
||||
return $this->elem('rss', $attrib, $content);
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -43,6 +43,15 @@ class XmlHelper extends AppHelper {
|
|||
* @var string
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
@ -114,6 +123,7 @@ class XmlHelper extends AppHelper {
|
|||
$children = $content;
|
||||
$content = null;
|
||||
}
|
||||
|
||||
$elem =& $this->Xml->createElement($name, $content, $attrib, $namespace);
|
||||
foreach ($children as $child) {
|
||||
$elem->createElement($child);
|
||||
|
@ -125,6 +135,11 @@ class XmlHelper extends AppHelper {
|
|||
}
|
||||
return $this->output($out);
|
||||
}
|
||||
/**
|
||||
* Create closing tag for current element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function closeElem() {
|
||||
$name = $this->Xml->name();
|
||||
if ($parent =& $this->Xml->parent()) {
|
||||
|
@ -140,14 +155,8 @@ class XmlHelper extends AppHelper {
|
|||
* @return string A copy of $data in XML format
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
function beforeRender() {
|
||||
$this->Xml =& new Xml();
|
||||
$this->Xml->options(array('verifyNs' => false));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -114,7 +114,7 @@ class XmlNode extends Object {
|
|||
$this->createTextNode($value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a namespace to the current node
|
||||
*
|
||||
|
@ -129,7 +129,7 @@ class XmlNode extends Object {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an XmlNode object that can be appended to this document or a node in it
|
||||
*
|
||||
|
@ -196,7 +196,7 @@ class XmlNode extends Object {
|
|||
if ($tagOpts === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (isset($tagOpts['name'])) {
|
||||
$name = $tagOpts['name'];
|
||||
} elseif ($name != strtolower($name)) {
|
||||
|
@ -572,13 +572,23 @@ class XmlNode extends Object {
|
|||
if ($options['whitespace']) {
|
||||
$d .= str_repeat("\t", $depth);
|
||||
}
|
||||
|
||||
$d .= '<' . $this->name();
|
||||
if (is_array($this->namespaces) && count($this->namespaces) > 0) {
|
||||
if (count($this->namespaces) > 0) {
|
||||
foreach ($this->namespaces as $key => $val) {
|
||||
$val = str_replace('"', '\"', $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) {
|
||||
foreach ($this->attributes as $key => $val) {
|
||||
$val = str_replace('"', '\"', $val);
|
||||
|
@ -621,6 +631,7 @@ class XmlNode extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $d;
|
||||
}
|
||||
/**
|
||||
|
@ -918,6 +929,7 @@ class Xml extends XmlNode {
|
|||
if (is_bool($options)) {
|
||||
$options = array('header' => $options);
|
||||
}
|
||||
|
||||
$defaults = array('header' => false, 'encoding' => $this->encoding);
|
||||
$options = array_merge($defaults, Xml::options(), $options);
|
||||
$data = parent::toString($options, 0);
|
||||
|
@ -928,14 +940,21 @@ class Xml extends XmlNode {
|
|||
}
|
||||
return $this->header() . "\n" . $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()) {
|
||||
$header = 'xml';
|
||||
if (is_string($attrib)) {
|
||||
$header = $attrib;
|
||||
} else {
|
||||
|
||||
$attrib = array_merge(array('version' => $this->version, 'encoding' => $this->encoding), $attrib);
|
||||
foreach ($attrib as $key=>$val) {
|
||||
$header .= ' ' . $key . '="' . $val . '"';
|
||||
|
@ -966,21 +985,20 @@ class Xml extends XmlNode {
|
|||
*/
|
||||
function addGlobalNs($name, $url = null) {
|
||||
$_this =& XmlManager::getInstance();
|
||||
if ($ns = Xml::__resolveNamespace($name, $url)) {
|
||||
if ($ns = Xml::resolveNamespace($name, $url)) {
|
||||
$_this->namespaces = array_merge($_this->namespaces, $ns);
|
||||
return $ns;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Private method
|
||||
* Resolves current namespace
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $url
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
function __resolveNamespace($name, $url) {
|
||||
function resolveNamespace($name, $url) {
|
||||
$_this =& XmlManager::getInstance();
|
||||
if ($url == null && in_array($name, array_keys($_this->defaultNamespaceMap))) {
|
||||
$url = $_this->defaultNamespaceMap[$name];
|
||||
|
@ -1013,15 +1031,16 @@ class Xml extends XmlNode {
|
|||
*/
|
||||
function removeGlobalNs($name) {
|
||||
$_this =& XmlManager::getInstance();
|
||||
|
||||
if (in_array($name, array_keys($_this->namespaces))) {
|
||||
unset($_this->namespaces[$name]);
|
||||
unset($this->namespaces[$name]);
|
||||
} elseif (in_array($name, $_this->namespaces)) {
|
||||
$keys = array_keys($_this->namespaces);
|
||||
$count = count($keys);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if ($_this->namespaces[$keys[$i]] == $name) {
|
||||
unset($_this->namespaces[$keys[$i]]);
|
||||
unset($this->namespaces[$keys[$i]]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1050,18 +1069,39 @@ class Xml extends XmlNode {
|
|||
return $_this->options;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The XML Element
|
||||
*
|
||||
*/
|
||||
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) {
|
||||
parent::__construct($name, $value, $namespace);
|
||||
$this->addAttribute($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the attributes for this element
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function 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) {
|
||||
if (is_object($name)) {
|
||||
$name = get_object_vars($name);
|
||||
|
@ -1091,7 +1131,12 @@ class XmlElement extends XmlNode {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove attributes to this element
|
||||
*
|
||||
* @param string $name name of the node
|
||||
* @return boolean
|
||||
*/
|
||||
function removeAttribute($attr) {
|
||||
if ($this->attributes[$attr]) {
|
||||
unset($this->attributes[$attr]);
|
||||
|
@ -1182,8 +1227,6 @@ class XmlTextNode extends XmlNode {
|
|||
return $val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manages application-wide namespaces and XML parsing/generation settings.
|
||||
* Private class, used exclusively within scope of XML class.
|
||||
|
@ -1239,5 +1282,4 @@ class XmlManager {
|
|||
return $instance[0];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -40,7 +40,7 @@ App::import('Helper', array('Rss', 'Time'));
|
|||
class RssTest extends CakeTestCase {
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -51,7 +51,7 @@ class RssTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -60,7 +60,7 @@ class RssTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testAddNamespace method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -70,10 +70,18 @@ class RssTest extends CakeTestCase {
|
|||
|
||||
$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/');
|
||||
$res = $this->Rss->document();
|
||||
$this->assertPattern('/^<rss xmlns:dummy="http:\/\/dummy\.com\/1.0\/" version="2.0" \/>$/', $res);
|
||||
|
||||
$this->Rss->removeNs('dummy');
|
||||
}
|
||||
/**
|
||||
* testRemoveNamespace method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -91,7 +99,7 @@ class RssTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testDocument method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -112,7 +120,7 @@ class RssTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testChannel method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -131,7 +139,7 @@ class RssTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testChannelElementLevelAttrib method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -150,7 +158,7 @@ class RssTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testItems method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -181,7 +189,7 @@ class RssTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testItem method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -189,7 +197,7 @@ class RssTest extends CakeTestCase {
|
|||
$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>';
|
||||
$this->assertEqual($result, $expecting);
|
||||
|
||||
|
||||
$item = array(
|
||||
'title' => array(
|
||||
'value' => 'My Title',
|
||||
|
@ -224,7 +232,7 @@ class RssTest extends CakeTestCase {
|
|||
'/item'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
|
||||
$item = array(
|
||||
'title' => array(
|
||||
'value' => 'My Title & more',
|
||||
|
@ -240,7 +248,7 @@ class RssTest extends CakeTestCase {
|
|||
'/item'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
|
||||
$item = array(
|
||||
'title' => array(
|
||||
'value' => 'My Title & more',
|
||||
|
@ -256,7 +264,7 @@ class RssTest extends CakeTestCase {
|
|||
'/item'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
|
||||
$item = array(
|
||||
'title' => array(
|
||||
'value' => 'My Title & more',
|
||||
|
@ -276,7 +284,7 @@ class RssTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testTime method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -284,7 +292,7 @@ class RssTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testElementAttrNotInParent method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -301,4 +309,4 @@ class RssTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
|
@ -33,22 +33,22 @@ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
|||
uses('view'.DS.'helpers'.DS.'app_helper', 'controller'.DS.'controller', 'model'.DS.'model', 'view'.DS.'helper', 'view'.DS.'helpers'.DS.'xml');
|
||||
/**
|
||||
* TestXml class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.view.helpers
|
||||
*/
|
||||
class TestXml extends Object {
|
||||
/**
|
||||
* content property
|
||||
*
|
||||
*
|
||||
* @var string ''
|
||||
* @access public
|
||||
*/
|
||||
var $content = '';
|
||||
/**
|
||||
* construct method
|
||||
*
|
||||
* @param mixed $content
|
||||
*
|
||||
* @param mixed $content
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
|
@ -57,7 +57,7 @@ class TestXml extends Object {
|
|||
}
|
||||
/**
|
||||
* toString method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -74,7 +74,7 @@ class TestXml extends Object {
|
|||
class XmlHelperTest extends UnitTestCase {
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -86,7 +86,7 @@ class XmlHelperTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testAddNamespace method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -99,7 +99,7 @@ class XmlHelperTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testRemoveNamespace method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -117,7 +117,7 @@ class XmlHelperTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testRenderZeroElement method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -128,7 +128,7 @@ class XmlHelperTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testRenderElementWithNamespace method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -140,14 +140,14 @@ class XmlHelperTest extends UnitTestCase {
|
|||
$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
|
||||
*/
|
||||
|
@ -162,7 +162,7 @@ class XmlHelperTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testSerialize method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -182,10 +182,24 @@ class XmlHelperTest extends UnitTestCase {
|
|||
$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);
|
||||
}
|
||||
/**
|
||||
* testHeader method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -194,9 +208,9 @@ class XmlHelperTest extends UnitTestCase {
|
|||
if (empty($expectedDefaultEncoding)) {
|
||||
$expectedDefaultEncoding = 'UTF-8';
|
||||
}
|
||||
$attrib = array();
|
||||
$result = $this->Xml->header($attrib);
|
||||
$expected = '<?xml version="1.0" encoding="'.$expectedDefaultEncoding.'" ?>';
|
||||
$attrib = array();
|
||||
$result = $this->Xml->header($attrib);
|
||||
$expected = '<?xml version="1.0" encoding="'.$expectedDefaultEncoding.'" ?>';
|
||||
$this->assertIdentical($result, $expected);
|
||||
|
||||
$attrib = array(
|
||||
|
@ -223,7 +237,7 @@ class XmlHelperTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -232,4 +246,4 @@ class XmlHelperTest extends UnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
|
@ -35,6 +35,10 @@ App::import('Core', 'Xml');
|
|||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class XmlTest extends UnitTestCase {
|
||||
|
||||
function KgetTests() {
|
||||
return array('testRootTagParsing');
|
||||
}
|
||||
/**
|
||||
* testRootTagParsing method
|
||||
*
|
||||
|
@ -42,7 +46,11 @@ class XmlTest extends UnitTestCase {
|
|||
* @return void
|
||||
*/
|
||||
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);
|
||||
$this->assertEqual($xml->children[0]->name, 'plugin');
|
||||
$this->assertEqual($xml->children[0]->children[0]->name, 'current');
|
||||
|
@ -72,7 +80,7 @@ class XmlTest extends UnitTestCase {
|
|||
|
||||
$xml = new Xml($input);
|
||||
$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);
|
||||
|
||||
$input = array(
|
||||
|
@ -81,7 +89,7 @@ class XmlTest extends UnitTestCase {
|
|||
'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
|
||||
'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);
|
||||
$result = preg_replace("/\n/",'', $xml->toString(false));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
@ -183,7 +191,7 @@ class XmlTest extends UnitTestCase {
|
|||
'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'));
|
||||
$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'));
|
||||
$result = $xml->toString(array('header' => false, 'cdata' => false));
|
||||
|
@ -391,7 +399,7 @@ class XmlTest extends UnitTestCase {
|
|||
'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'));
|
||||
$result = $xml->toString(array('header' => false, 'cdata' => true));
|
||||
$this->assertEqual($expected, $result);
|
||||
|
@ -429,7 +437,7 @@ class XmlTest extends UnitTestCase {
|
|||
'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'));
|
||||
$result = $xml->toString(array('header' => false, 'cdata' => false, 'whitespace' => true));
|
||||
|
@ -456,7 +464,7 @@ class XmlTest extends UnitTestCase {
|
|||
'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'));
|
||||
$result = $xml->toString(array('header' => false, 'cdata' => false));
|
||||
|
@ -464,7 +472,7 @@ class XmlTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testSimpleParsing method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -476,7 +484,7 @@ class XmlTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testMixedParsing method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -488,19 +496,19 @@ class XmlTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testComplexParsing method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
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);
|
||||
$result = $xml->toString(array('cdata' => false));
|
||||
$this->assertEqual($source, $result);
|
||||
}
|
||||
/**
|
||||
* testNamespaceParsing method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -519,7 +527,7 @@ class XmlTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testNamespaces method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -535,10 +543,6 @@ class XmlTest extends UnitTestCase {
|
|||
$this->assertEqual($expects, $result);
|
||||
}
|
||||
|
||||
/*
|
||||
* @todo Add test for default namespaces
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
Loading…
Add table
Reference in a new issue