diff --git a/cake/libs/xml.php b/cake/libs/xml.php index d4fbd182859..0c714dc44fd 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -302,10 +302,10 @@ function normalize($object, $keyName = null, $options = array()) { * @access private */ function __tagOptions($name, $option = null) { - if (isset($this->__tags[$name])) { - $tagOpts = $this->__tags[$name]; - } elseif (isset($this->__tags[strtolower($name)])) { - $tagOpts = $this->__tags[strtolower($name)]; + if (isset($this->_tags[$name])) { + $tagOpts = $this->_tags[$name]; + } elseif (isset($this->_tags[strtolower($name)])) { + $tagOpts = $this->_tags[strtolower($name)]; } else { return null; } @@ -810,18 +810,18 @@ class Xml extends XmlNode { * XML document header * * @var string - * @access private + * @access protected */ - private $__header = null; + protected $_header = null; /** * Default array keys/object properties to use as tag names when converting objects or array * structures to XML. Set by passing $options['tags'] to this object's constructor. * * @var array - * @access private + * @access protected */ - private $__tags = array(); + protected $_tags = array(); /** * XML document version @@ -868,7 +868,7 @@ function __construct($input = null, $options = array()) { foreach (array('version', 'encoding', 'namespaces') as $key) { $this->{$key} = $options[$key]; } - $this->__tags = $options['tags']; + $this->_tags = $options['tags']; parent::__construct('#document'); if ($options['root'] !== '#document') { @@ -898,7 +898,7 @@ function load($input) { return false; } $this->__rawData = null; - $this->__header = null; + $this->_header = null; if (strstr($input, "<")) { $this->__rawData = $input; @@ -926,7 +926,7 @@ function load($input) { function parse() { $this->__initParser(); $this->__rawData = trim($this->__rawData); - $this->__header = trim(str_replace( + $this->_header = trim(str_replace( array('<' . '?', '?' . '>'), array('', ''), substr($this->__rawData, 0, strpos($this->__rawData, '?' . '>')) @@ -1098,8 +1098,8 @@ function toString($options = array()) { $data = parent::toString($options, 0); if ($options['header']) { - if (!empty($this->__header)) { - return $this->header($this->__header) . "\n" . $data; + if (!empty($this->_header)) { + return $this->header($this->_header) . "\n" . $data; } return $this->header() . "\n" . $data; } diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index c8358210a34..376a3c7b02c 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -19,6 +19,25 @@ */ App::import('Core', 'Xml'); +/** + * Test XML Class + * + * @package cake + * @subpackage cake.tests.cases.libs + */ +class TestXml extends Xml { + +/** + * Return the protected _header instance variable + * + * @return string Header + * @access public + */ + function getHeader() { + return $this->_header; + } +} + /** * XmlTest class * @@ -488,17 +507,17 @@ function testParsingWithNonStandardWhitespace() { $raw = '1.0'; $array = array('Prices' => array('price' => 1.0)); - $xml = new Xml($raw); + $xml = new TestXml($raw); $this->assertEqual($xml->toArray(), $array); - $this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"'); + $this->assertEqual($xml->getHeader(), 'xml version="1.0" encoding="ISO-8859-1"'); - $xml = new Xml(' ' . $raw); + $xml = new TestXml(' ' . $raw); $this->assertEqual($xml->toArray(), $array); - $this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"'); + $this->assertEqual($xml->getHeader(), 'xml version="1.0" encoding="ISO-8859-1"'); - $xml = new Xml("\n" . $raw); + $xml = new TestXml("\n" . $raw); $this->assertEqual($xml->toArray(), $array); - $this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"'); + $this->assertEqual($xml->getHeader(), 'xml version="1.0" encoding="ISO-8859-1"'); } /* Not implemented yet */