2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs.view.helpers
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
|
|
|
*/
|
|
|
|
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
|
|
|
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
uses('view'.DS.'helpers'.DS.'app_helper', 'controller'.DS.'controller', 'model'.DS.'model', 'view'.DS.'helper', 'view'.DS.'helpers'.DS.'xml');
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* TestXml class
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.view.helpers
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestXml extends Object {
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* content property
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var string ''
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $content = '';
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* construct method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
|
|
|
* @param mixed $content
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access private
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function __construct($content) {
|
|
|
|
$this->content = $content;
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* toString method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function toString() {
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Short description for class.
|
|
|
|
*
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs.view.helpers
|
|
|
|
*/
|
|
|
|
class XmlHelperTest extends UnitTestCase {
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function setUp() {
|
|
|
|
$this->Xml =& new XmlHelper();
|
2008-06-03 17:59:23 +00:00
|
|
|
$this->Xml->beforeRender();
|
2008-06-19 14:31:00 +00:00
|
|
|
$manager =& XmlManager::getInstance();
|
|
|
|
$manager->namespaces = array();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testAddNamespace method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAddNamespace() {
|
|
|
|
$this->Xml->addNs('custom', 'http://example.com/dtd.xml');
|
|
|
|
$manager =& XmlManager::getInstance();
|
|
|
|
|
|
|
|
$expected = array('custom' => 'http://example.com/dtd.xml');
|
|
|
|
$this->assertEqual($manager->namespaces, $expected);
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testRemoveNamespace method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRemoveNamespace() {
|
|
|
|
$this->Xml->addNs('custom', 'http://example.com/dtd.xml');
|
|
|
|
$this->Xml->addNs('custom2', 'http://example.com/dtd2.xml');
|
|
|
|
$manager =& XmlManager::getInstance();
|
|
|
|
|
|
|
|
$expected = array('custom' => 'http://example.com/dtd.xml', 'custom2' => 'http://example.com/dtd2.xml');
|
|
|
|
$this->assertEqual($manager->namespaces, $expected);
|
|
|
|
|
|
|
|
$this->Xml->removeNs('custom');
|
|
|
|
$expected = array('custom2' => 'http://example.com/dtd2.xml');
|
|
|
|
$this->assertEqual($manager->namespaces, $expected);
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testRenderZeroElement method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRenderZeroElement() {
|
|
|
|
$result = $this->Xml->elem('count', null, 0);
|
|
|
|
$expected = '<count>0</count>';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testRenderElementWithNamespace method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRenderElementWithNamespace() {
|
|
|
|
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), 'content');
|
2008-06-03 17:59:23 +00:00
|
|
|
$expected = '<myNameSpace:count>content</myNameSpace:count>';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), 'content', false);
|
|
|
|
$expected = '<myNameSpace:count>content';
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-06-21 15:23:58 +00:00
|
|
|
|
2008-06-03 17:59:23 +00:00
|
|
|
$expected .= '</myNameSpace:count>';
|
|
|
|
$result .= $this->Xml->closeElem();
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testRenderElementWithComplexContent method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-03 22:33:21 +00:00
|
|
|
function testRenderElementWithComplexContent() {
|
|
|
|
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), array('contrived' => 'content'));
|
|
|
|
$expected = '<myNameSpace:count><content /></myNameSpace:count>';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), array('cdata' => true, 'value' => 'content'));
|
|
|
|
$expected = '<myNameSpace:count><![CDATA[content]]></myNameSpace:count>';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testSerialize method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSerialize() {
|
|
|
|
$data = array(
|
|
|
|
'test1' => 'test with no quotes',
|
|
|
|
'test2' => 'test with "double quotes"'
|
|
|
|
);
|
|
|
|
$result = $this->Xml->serialize($data);
|
|
|
|
$expected = '<std_class test1="test with no quotes" test2="test with \"double quotes\"" />';
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'test1' => 'test with no quotes',
|
|
|
|
'test2' => 'test without double quotes'
|
|
|
|
);
|
|
|
|
$result = $this->Xml->serialize($data);
|
|
|
|
$expected = '<std_class test1="test with no quotes" test2="test without double quotes" />';
|
|
|
|
$this->assertIdentical($result, $expected);
|
2008-06-21 15:23:58 +00:00
|
|
|
|
|
|
|
$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);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testHeader method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testHeader() {
|
|
|
|
$expectedDefaultEncoding = Configure::read('App.encoding');
|
|
|
|
if (empty($expectedDefaultEncoding)) {
|
|
|
|
$expectedDefaultEncoding = 'UTF-8';
|
|
|
|
}
|
2008-06-21 15:23:58 +00:00
|
|
|
$attrib = array();
|
|
|
|
$result = $this->Xml->header($attrib);
|
|
|
|
$expected = '<?xml version="1.0" encoding="'.$expectedDefaultEncoding.'" ?>';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
|
|
|
|
$attrib = array(
|
|
|
|
'encoding' => 'UTF-8',
|
|
|
|
'version' => '1.1'
|
|
|
|
);
|
|
|
|
$result = $this->Xml->header($attrib);
|
|
|
|
$expected = '<?xml version="1.1" encoding="UTF-8" ?>';
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
|
|
|
|
$attrib = array(
|
|
|
|
'encoding' => 'UTF-8',
|
|
|
|
'version' => '1.2',
|
|
|
|
'additional' => 'attribute'
|
|
|
|
);
|
|
|
|
$result = $this->Xml->header($attrib);
|
|
|
|
$expected = '<?xml version="1.2" encoding="UTF-8" additional="attribute" ?>';
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
|
|
|
|
$attrib = 'encoding="UTF-8" someOther="value"';
|
|
|
|
$result = $this->Xml->header($attrib);
|
|
|
|
$expected = '<?xml encoding="UTF-8" someOther="value" ?>';
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function tearDown() {
|
|
|
|
unset($this->Xml);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-21 15:23:58 +00:00
|
|
|
?>
|