2008-05-30 11:40:08 +00:00
< ? php
/**
2009-03-18 17:55:58 +00:00
* XmlTest file
2008-05-30 11:40:08 +00:00
*
2010-10-03 16:31:21 +00:00
* PHP 5
2008-05-30 11:40:08 +00:00
*
2010-05-19 01:15:13 +00:00
* CakePHP ( tm ) Tests < http :// book . cakephp . org / view / 1196 / Testing >
2012-03-13 02:46:07 +00:00
* Copyright 2005 - 2012 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2008-05-30 11:40:08 +00:00
*
2010-10-03 16:31:21 +00:00
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
2008-05-30 11:40:08 +00:00
*
2012-03-13 02:46:07 +00:00
* @ copyright Copyright 2005 - 2012 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2010-05-19 01:15:13 +00:00
* @ link http :// book . cakephp . org / view / 1196 / Testing CakePHP ( tm ) Tests
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . Utility
2008-10-30 17:30:26 +00:00
* @ since CakePHP ( tm ) v 1.2 . 0.5432
2010-10-03 16:27:27 +00:00
* @ license MIT License ( http :// www . opensource . org / licenses / mit - license . php )
2008-05-30 11:40:08 +00:00
*/
2010-12-08 06:19:36 +00:00
App :: uses ( 'Xml' , 'Utility' );
App :: uses ( 'CakeTestModel' , 'TestSuite/Fixture' );
2009-07-24 19:18:37 +00:00
2010-04-04 22:57:40 +00:00
/**
2010-09-13 03:43:11 +00:00
* Article class
2008-05-30 11:40:08 +00:00
*
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . Utility
2008-05-30 11:40:08 +00:00
*/
2010-10-14 02:30:40 +00:00
class XmlArticle extends CakeTestModel {
2009-07-24 19:18:37 +00:00
2009-03-18 17:55:58 +00:00
/**
2010-09-13 03:43:11 +00:00
* name property
2009-03-18 17:55:58 +00:00
*
2010-09-13 03:43:11 +00:00
* @ var string 'Article'
2009-03-18 17:55:58 +00:00
*/
2010-09-13 03:43:11 +00:00
public $name = 'Article' ;
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
2010-09-13 03:43:11 +00:00
* belongsTo property
2008-06-05 15:20:45 +00:00
*
2010-09-13 03:43:11 +00:00
* @ var array
2008-06-02 19:22:55 +00:00
*/
2010-10-14 02:30:40 +00:00
public $belongsTo = array (
'XmlUser' => array (
'className' => 'XmlArticle' ,
'foreignKey' => 'user_id'
)
);
2010-09-13 03:43:11 +00:00
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
2010-09-13 03:43:11 +00:00
* User class
2008-06-05 15:20:45 +00:00
*
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . Utility
2008-06-02 19:22:55 +00:00
*/
2010-10-14 02:30:40 +00:00
class XmlUser extends CakeTestModel {
2009-06-30 01:14:20 +00:00
2009-08-02 06:47:28 +00:00
/**
2010-09-13 03:43:11 +00:00
* name property
2009-08-02 06:47:28 +00:00
*
2010-09-13 03:43:11 +00:00
* @ var string 'User'
2009-08-02 06:47:28 +00:00
*/
2010-09-13 03:43:11 +00:00
public $name = 'User' ;
2009-08-02 06:47:28 +00:00
2009-06-30 01:14:20 +00:00
/**
2010-09-13 03:43:11 +00:00
* hasMany property
2009-06-30 01:14:20 +00:00
*
2010-09-13 03:43:11 +00:00
* @ var array
2009-11-14 12:19:25 +00:00
*/
2010-09-13 03:43:11 +00:00
public $hasMany = array ( 'Article' );
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
2009-03-18 17:55:58 +00:00
* XmlTest class
2008-06-05 15:20:45 +00:00
*
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . Utility
2008-06-02 19:22:55 +00:00
*/
2008-07-21 02:40:58 +00:00
class XmlTest extends CakeTestCase {
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
2010-09-13 03:43:11 +00:00
* autoFixtures property
2008-06-05 15:20:45 +00:00
*
2010-09-13 03:43:11 +00:00
* @ var bool false
2008-06-02 19:22:55 +00:00
*/
2010-09-13 03:43:11 +00:00
public $autoFixtures = false ;
2009-07-24 19:18:37 +00:00
2009-09-18 02:08:32 +00:00
/**
2010-09-13 03:43:11 +00:00
* fixtures property
* @ var array
2009-09-18 02:08:32 +00:00
*/
2010-09-13 03:43:11 +00:00
public $fixtures = array (
'core.article' , 'core.user'
);
2008-06-05 15:20:45 +00:00
/**
2011-12-04 21:27:51 +00:00
* setUp method
2008-06-05 15:20:45 +00:00
*
2008-06-02 19:22:55 +00:00
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function setUp () {
2011-12-04 21:27:51 +00:00
parent :: setUp ();
2010-09-08 22:40:33 +00:00
$this -> _appEncoding = Configure :: read ( 'App.encoding' );
Configure :: write ( 'App.encoding' , 'UTF-8' );
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
2010-09-08 22:40:33 +00:00
* tearDown method
2008-06-05 15:20:45 +00:00
*
2008-06-02 19:22:55 +00:00
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function tearDown () {
2010-09-08 22:40:33 +00:00
parent :: tearDown ();
Configure :: write ( 'App.encoding' , $this -> _appEncoding );
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
2010-07-27 00:31:39 +00:00
* testBuild method
2008-06-05 15:20:45 +00:00
*
2008-06-02 19:22:55 +00:00
* @ return void
*/
2010-09-01 23:09:03 +00:00
public function testBuild () {
2010-07-27 00:31:39 +00:00
$xml = '<tag>value</tag>' ;
$obj = Xml :: build ( $xml );
$this -> assertTrue ( $obj instanceof SimpleXMLElement );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tag' , ( string ) $obj -> getName ());
$this -> assertEquals ( 'value' , ( string ) $obj );
2008-10-04 19:50:38 +00:00
2010-09-08 22:40:33 +00:00
$xml = '<?xml version="1.0" encoding="UTF-8"?><tag>value</tag>' ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $obj , Xml :: build ( $xml ));
2009-07-24 19:18:37 +00:00
2010-09-08 23:30:04 +00:00
$obj = Xml :: build ( $xml , array ( 'return' => 'domdocument' ));
$this -> assertTrue ( $obj instanceof DOMDocument );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tag' , $obj -> firstChild -> nodeName );
$this -> assertEquals ( 'value' , $obj -> firstChild -> nodeValue );
2008-05-30 11:40:08 +00:00
2011-04-17 10:35:21 +00:00
$xml = CAKE . 'Test' . DS . 'Fixture' . DS . 'sample.xml' ;
2010-07-27 00:31:39 +00:00
$obj = Xml :: build ( $xml );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tags' , $obj -> getName ());
$this -> assertEquals ( 2 , count ( $obj ));
2009-07-24 19:18:37 +00:00
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( Xml :: build ( $xml ), Xml :: build ( file_get_contents ( $xml )));
2008-05-30 11:40:08 +00:00
2010-09-08 23:30:04 +00:00
$obj = Xml :: build ( $xml , array ( 'return' => 'domdocument' ));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tags' , $obj -> firstChild -> nodeName );
2010-09-08 23:30:04 +00:00
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( Xml :: build ( $xml , array ( 'return' => 'domdocument' )), Xml :: build ( file_get_contents ( $xml ), array ( 'return' => 'domdocument' )));
$this -> assertEquals ( Xml :: build ( $xml , array ( 'return' => 'simplexml' )), Xml :: build ( $xml , 'simplexml' ));
2010-09-08 23:30:04 +00:00
2010-07-27 00:31:39 +00:00
$xml = array ( 'tag' => 'value' );
$obj = Xml :: build ( $xml );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tag' , $obj -> getName ());
$this -> assertEquals ( 'value' , ( string ) $obj );
2008-06-05 15:20:45 +00:00
2010-09-08 23:30:04 +00:00
$obj = Xml :: build ( $xml , array ( 'return' => 'domdocument' ));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tag' , $obj -> firstChild -> nodeName );
$this -> assertEquals ( 'value' , $obj -> firstChild -> nodeValue );
2010-09-12 01:12:54 +00:00
$obj = Xml :: build ( $xml , array ( 'return' => 'domdocument' , 'encoding' => null ));
2011-11-16 00:07:56 +00:00
$this -> assertNotRegExp ( '/encoding/' , $obj -> saveXML ());
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2009-04-17 13:26:07 +00:00
/**
2010-08-23 03:19:54 +00:00
* data provider function for testBuildInvalidData
2009-04-17 13:26:07 +00:00
*
2010-08-23 21:23:53 +00:00
* @ return array
2009-04-17 13:26:07 +00:00
*/
2010-08-23 03:19:54 +00:00
public static function invalidDataProvider () {
return array (
array ( null ),
array ( false ),
array ( '' ),
2009-11-27 19:27:32 +00:00
);
2009-04-17 13:26:07 +00:00
}
2009-07-24 19:18:37 +00:00
2008-08-26 23:15:48 +00:00
/**
2010-08-23 03:19:54 +00:00
* testBuildInvalidData
2008-08-26 23:15:48 +00:00
*
2010-08-23 03:19:54 +00:00
* @ dataProvider invalidDataProvider
2011-11-03 03:44:22 +00:00
* @ expectedException XmlException
2010-07-27 02:25:55 +00:00
* return void
2008-08-26 23:15:48 +00:00
*/
2010-09-01 23:09:03 +00:00
public function testBuildInvalidData ( $value ) {
2010-08-23 03:19:54 +00:00
Xml :: build ( $value );
2008-08-26 23:15:48 +00:00
}
2009-07-24 19:18:37 +00:00
2011-11-03 03:44:22 +00:00
/**
* test build with a single empty tag
*
* return void
*/
public function testBuildEmptyTag () {
try {
Xml :: build ( '<tag>' );
$this -> fail ( 'No exception' );
} catch ( Exception $e ) {
$this -> assertTrue ( true , 'An exception was raised' );
}
}
2008-08-26 23:15:48 +00:00
/**
2010-07-27 00:31:39 +00:00
* testFromArray method
2008-08-26 23:15:48 +00:00
*
* @ return void
*/
2010-09-01 23:09:03 +00:00
public function testFromArray () {
2010-07-27 00:31:39 +00:00
$xml = array ( 'tag' => 'value' );
$obj = Xml :: fromArray ( $xml );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tag' , $obj -> getName ());
$this -> assertEquals ( 'value' , ( string ) $obj );
2008-09-04 15:34:08 +00:00
2010-07-27 00:31:39 +00:00
$xml = array ( 'tag' => null );
$obj = Xml :: fromArray ( $xml );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tag' , $obj -> getName ());
$this -> assertEquals ( '' , ( string ) $obj );
2008-09-04 15:34:08 +00:00
2010-08-23 04:33:06 +00:00
$xml = array ( 'tag' => array ( '@' => 'value' ));
$obj = Xml :: fromArray ( $xml );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tag' , $obj -> getName ());
$this -> assertEquals ( 'value' , ( string ) $obj );
2009-07-24 19:18:37 +00:00
2010-07-27 00:31:39 +00:00
$xml = array (
'tags' => array (
'tag' => array (
array (
'id' => '1' ,
'name' => 'defect'
),
array (
'id' => '2' ,
'name' => 'enhancement'
)
2008-05-30 11:40:08 +00:00
)
2008-08-26 23:15:48 +00:00
)
);
2010-09-07 02:11:45 +00:00
$obj = Xml :: fromArray ( $xml , 'attributes' );
2010-07-27 00:31:39 +00:00
$this -> assertTrue ( $obj instanceof SimpleXMLElement );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tags' , $obj -> getName ());
$this -> assertEquals ( 2 , count ( $obj ));
2010-09-08 22:40:33 +00:00
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1" name="defect"/><tag id="2" name="enhancement"/></tags>' ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $obj -> asXML ()), $xmlText );
2010-07-27 00:31:39 +00:00
2010-09-07 02:11:45 +00:00
$obj = Xml :: fromArray ( $xml );
2010-07-27 00:31:39 +00:00
$this -> assertTrue ( $obj instanceof SimpleXMLElement );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tags' , $obj -> getName ());
$this -> assertEquals ( 2 , count ( $obj ));
2010-09-08 22:40:33 +00:00
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag><id>1</id><name>defect</name></tag><tag><id>2</id><name>enhancement</name></tag></tags>' ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $obj -> asXML ()), $xmlText );
2010-07-27 00:31:39 +00:00
$xml = array (
'tags' => array (
2008-05-30 11:40:08 +00:00
)
2008-08-26 23:15:48 +00:00
);
2010-07-27 00:31:39 +00:00
$obj = Xml :: fromArray ( $xml );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'tags' , $obj -> getName ());
$this -> assertEquals ( '' , ( string ) $obj );
2010-07-27 00:31:39 +00:00
$xml = array (
'tags' => array (
'bool' => true ,
'int' => 1 ,
'float' => 10.2 ,
'string' => 'ok' ,
'null' => null ,
'array' => array ()
2008-05-30 11:40:08 +00:00
)
2008-08-26 23:15:48 +00:00
);
2010-07-27 00:31:39 +00:00
$obj = Xml :: fromArray ( $xml , 'tags' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 6 , count ( $obj ));
2011-11-16 00:07:56 +00:00
$this -> assertSame (( string ) $obj -> bool , '1' );
$this -> assertSame (( string ) $obj -> int , '1' );
$this -> assertSame (( string ) $obj -> float , '10.2' );
$this -> assertSame (( string ) $obj -> string , 'ok' );
$this -> assertSame (( string ) $obj -> null , '' );
$this -> assertSame (( string ) $obj -> array , '' );
2010-08-23 03:48:34 +00:00
$xml = array (
'tags' => array (
'tag' => array (
array (
'@id' => '1' ,
'name' => 'defect'
),
array (
'@id' => '2' ,
'name' => 'enhancement'
)
)
2008-05-30 11:40:08 +00:00
)
);
2010-08-23 03:48:34 +00:00
$obj = Xml :: fromArray ( $xml , 'tags' );
2010-09-08 22:40:33 +00:00
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1"><name>defect</name></tag><tag id="2"><name>enhancement</name></tag></tags>' ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $obj -> asXML ()), $xmlText );
2009-07-24 19:18:37 +00:00
2010-08-23 04:33:06 +00:00
$xml = array (
'tags' => array (
'tag' => array (
array (
'@id' => '1' ,
'name' => 'defect' ,
'@' => 'Tag 1'
),
array (
'@id' => '2' ,
'name' => 'enhancement'
),
),
'@' => 'All tags'
2008-05-30 11:40:08 +00:00
)
);
2010-08-23 04:33:06 +00:00
$obj = Xml :: fromArray ( $xml , 'tags' );
2010-09-08 22:40:33 +00:00
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags>All tags<tag id="1">Tag 1<name>defect</name></tag><tag id="2"><name>enhancement</name></tag></tags>' ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $obj -> asXML ()), $xmlText );
2009-07-24 19:18:37 +00:00
2010-08-23 04:33:06 +00:00
$xml = array (
'tags' => array (
'tag' => array (
'id' => 1 ,
'@' => 'defect'
)
2008-05-30 11:40:08 +00:00
)
);
2010-09-07 02:11:45 +00:00
$obj = Xml :: fromArray ( $xml , 'attributes' );
2010-09-08 22:40:33 +00:00
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1">defect</tag></tags>' ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $obj -> asXML ()), $xmlText );
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2009-11-27 19:27:32 +00:00
/**
2010-08-23 03:19:54 +00:00
* data provider for fromArray () failures
2009-11-27 19:27:32 +00:00
*
2010-08-23 21:23:53 +00:00
* @ return array
2009-11-27 19:27:32 +00:00
*/
2010-08-23 03:19:54 +00:00
public static function invalidArrayDataProvider () {
return array (
array ( '' ),
array ( null ),
array ( false ),
array ( array ()),
2010-08-23 21:23:53 +00:00
array ( array ( 'numeric key as root' )),
array ( array ( 'item1' => '' , 'item2' => '' )),
array ( array ( 'items' => array ( 'item1' , 'item2' ))),
2010-08-23 03:19:54 +00:00
array ( array (
2010-07-27 00:31:39 +00:00
'tags' => array (
'tag' => array (
array (
array (
'string'
)
)
)
2009-07-01 18:58:05 +00:00
)
2010-08-23 03:19:54 +00:00
)),
2010-08-23 04:46:31 +00:00
array ( array (
2010-08-23 03:48:34 +00:00
'tags' => array (
'@tag' => array (
array (
'@id' => '1' ,
'name' => 'defect'
),
array (
'@id' => '2' ,
'name' => 'enhancement'
)
)
)
2010-08-23 04:46:31 +00:00
)),
2010-08-23 03:19:54 +00:00
array ( new DateTime ())
2009-11-27 19:27:32 +00:00
);
}
2008-07-31 23:50:32 +00:00
2008-06-05 15:20:45 +00:00
/**
2010-08-23 03:19:54 +00:00
* testFromArrayFail method
2008-06-21 15:23:58 +00:00
*
2010-08-23 03:19:54 +00:00
* @ dataProvider invalidArrayDataProvider
2008-06-05 15:20:45 +00:00
*/
2010-09-01 23:09:03 +00:00
public function testFromArrayFail ( $value ) {
2011-11-03 03:44:22 +00:00
try {
Xml :: fromArray ( $value );
$this -> fail ( 'No exception.' );
} catch ( Exception $e ) {
$this -> assertTrue ( true , 'Caught exception.' );
}
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2009-07-01 18:58:05 +00:00
/**
2010-07-27 02:25:55 +00:00
* testToArray method
2009-07-01 18:58:05 +00:00
*
* @ return void
2009-11-14 12:19:25 +00:00
*/
2010-09-01 23:09:03 +00:00
public function testToArray () {
2010-07-27 00:31:39 +00:00
$xml = '<tag>name</tag>' ;
$obj = Xml :: build ( $xml );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( array ( 'tag' => 'name' ), Xml :: toArray ( $obj ));
2008-08-10 16:26:43 +00:00
2011-04-17 10:35:21 +00:00
$xml = CAKE . 'Test' . DS . 'Fixture' . DS . 'sample.xml' ;
2010-07-27 00:31:39 +00:00
$obj = Xml :: build ( $xml );
2009-07-01 18:58:05 +00:00
$expected = array (
2010-08-23 03:24:56 +00:00
'tags' => array (
'tag' => array (
array (
'@id' => '1' ,
'name' => 'defect'
),
array (
'@id' => '2' ,
'name' => 'enhancement'
)
2009-07-01 18:58:05 +00:00
)
2010-08-23 03:24:56 +00:00
)
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( $obj ));
2009-07-01 18:58:05 +00:00
2010-08-23 03:24:56 +00:00
$array = array (
2010-07-27 00:31:39 +00:00
'tags' => array (
'tag' => array (
2008-07-31 23:50:32 +00:00
array (
2010-07-27 00:31:39 +00:00
'id' => '1' ,
'name' => 'defect'
2008-07-31 23:50:32 +00:00
),
array (
2010-07-27 00:31:39 +00:00
'id' => '2' ,
'name' => 'enhancement'
2008-07-31 23:50:32 +00:00
)
)
)
2010-07-27 00:31:39 +00:00
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( Xml :: toArray ( Xml :: fromArray ( $array , 'tags' )), $array );
2009-07-24 19:18:37 +00:00
2009-08-14 02:47:17 +00:00
$expected = array (
2010-08-23 03:24:56 +00:00
'tags' => array (
'tag' => array (
array (
'@id' => '1' ,
'@name' => 'defect'
),
array (
'@id' => '2' ,
'@name' => 'enhancement'
)
)
)
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( Xml :: fromArray ( $array , 'attributes' )));
$this -> assertEquals ( $expected , Xml :: toArray ( Xml :: fromArray ( $array , array ( 'return' => 'domdocument' , 'format' => 'attributes' ))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( Xml :: toArray ( Xml :: fromArray ( $array )), $array );
$this -> assertEquals ( Xml :: toArray ( Xml :: fromArray ( $array , array ( 'return' => 'domdocument' ))), $array );
2010-08-23 03:24:56 +00:00
$array = array (
2010-07-27 00:31:39 +00:00
'tags' => array (
'tag' => array (
'id' => '1' ,
'posts' => array (
array ( 'id' => '1' ),
array ( 'id' => '2' )
2008-09-05 17:20:18 +00:00
)
2009-08-14 02:47:17 +00:00
),
2010-07-27 00:31:39 +00:00
'tagOther' => array (
'subtag' => array (
'id' => '1'
2008-09-05 17:20:18 +00:00
)
)
2009-08-14 02:47:17 +00:00
)
);
$expected = array (
2010-08-23 03:24:56 +00:00
'tags' => array (
'tag' => array (
'@id' => '1' ,
'posts' => array (
array ( '@id' => '1' ),
array ( '@id' => '2' )
)
2009-08-14 02:47:17 +00:00
),
2010-08-23 03:24:56 +00:00
'tagOther' => array (
'subtag' => array (
'@id' => '1'
)
)
2009-08-14 02:47:17 +00:00
)
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( Xml :: fromArray ( $array , 'attributes' )));
$this -> assertEquals ( $expected , Xml :: toArray ( Xml :: fromArray ( $array , array ( 'format' => 'attributes' , 'return' => 'domdocument' ))));
2009-07-24 19:18:37 +00:00
2010-07-28 21:53:36 +00:00
$xml = '<root>' ;
$xml .= '<tag id="1">defect</tag>' ;
$xml .= '</root>' ;
$obj = Xml :: build ( $xml );
2009-07-24 19:18:37 +00:00
2010-07-28 21:53:36 +00:00
$expected = array (
'root' => array (
'tag' => array (
2010-08-23 03:24:56 +00:00
'@id' => 1 ,
2010-08-23 04:33:06 +00:00
'@' => 'defect'
2010-07-28 21:53:36 +00:00
)
)
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( $obj ));
2010-07-28 21:53:36 +00:00
2010-07-27 00:31:39 +00:00
$xml = '<root>' ;
$xml .= '<table xmlns="http://www.w3.org/TR/html4/"><tr><td>Apples</td><td>Bananas</td></tr></table>' ;
$xml .= '<table xmlns="http://www.cakephp.org"><name>CakePHP</name><license>MIT</license></table>' ;
$xml .= '<table>The book is on the table.</table>' ;
$xml .= '</root>' ;
$obj = Xml :: build ( $xml );
2008-06-03 01:42:05 +00:00
2010-03-26 08:59:09 +00:00
$expected = array (
2010-07-27 00:31:39 +00:00
'root' => array (
'table' => array (
array ( 'tr' => array ( 'td' => array ( 'Apples' , 'Bananas' ))),
array ( 'name' => 'CakePHP' , 'license' => 'MIT' ),
'The book is on the table.'
2010-03-26 08:59:09 +00:00
)
2010-07-27 00:31:39 +00:00
)
2010-03-26 08:59:09 +00:00
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( $obj ));
2008-06-03 01:42:05 +00:00
2010-07-28 22:46:35 +00:00
$xml = '<root xmlns:cake="http://www.cakephp.org/">' ;
$xml .= '<tag>defect</tag>' ;
$xml .= '<cake:bug>1</cake:bug>' ;
$xml .= '</root>' ;
$obj = Xml :: build ( $xml );
2008-06-05 15:20:45 +00:00
2010-07-28 22:46:35 +00:00
$expected = array (
'root' => array (
'tag' => 'defect' ,
2010-09-07 03:31:50 +00:00
'cake:bug' => 1
2010-07-28 22:46:35 +00:00
)
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( $obj ));
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2008-06-05 15:20:45 +00:00
/**
2010-09-12 14:54:11 +00:00
* testRss
2008-06-21 15:23:58 +00:00
*
2008-06-05 15:20:45 +00:00
* @ return void
*/
2010-09-12 14:54:11 +00:00
public function testRss () {
2011-04-17 10:35:21 +00:00
$rss = file_get_contents ( CAKE . 'Test' . DS . 'Fixture' . DS . 'rss.xml' );
2010-09-01 23:06:56 +00:00
$rssAsArray = Xml :: toArray ( Xml :: build ( $rss ));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( '2.0' , $rssAsArray [ 'rss' ][ '@version' ]);
$this -> assertEquals ( 2 , count ( $rssAsArray [ 'rss' ][ 'channel' ][ 'item' ]));
2008-06-03 01:42:05 +00:00
2010-09-07 03:31:50 +00:00
$atomLink = array ( '@href' => 'http://bakery.cakephp.org/articles/rss' , '@rel' => 'self' , '@type' => 'application/rss+xml' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $rssAsArray [ 'rss' ][ 'channel' ][ 'atom:link' ], $atomLink );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'http://bakery.cakephp.org/' , $rssAsArray [ 'rss' ][ 'channel' ][ 'link' ]);
2008-06-03 01:42:05 +00:00
2010-09-01 23:06:56 +00:00
$expected = array (
'title' => 'Alertpay automated sales via IPN' ,
'link' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn' ,
'description' => 'I\'m going to show you how I implemented a payment module via the Alertpay payment processor.' ,
'pubDate' => 'Tue, 31 Aug 2010 01:42:00 -0500' ,
'guid' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn'
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $rssAsArray [ 'rss' ][ 'channel' ][ 'item' ][ 1 ], $expected );
2010-09-12 14:54:11 +00:00
$rss = array (
'rss' => array (
'xmlns:atom' => 'http://www.w3.org/2005/Atom' ,
'@version' => '2.0' ,
'channel' => array (
'atom:link' => array (
'@href' => 'http://bakery.cakephp.org/articles/rss' ,
'@rel' => 'self' ,
'@type' => 'application/rss+xml'
),
'title' => 'The Bakery: ' ,
'link' => 'http://bakery.cakephp.org/' ,
'description' => 'Recent Articles at The Bakery.' ,
'pubDate' => 'Sun, 12 Sep 2010 04:18:26 -0500' ,
'item' => array (
array (
'title' => 'CakePHP 1.3.4 released' ,
'link' => 'http://bakery.cakephp.org/articles/view/cakephp-1-3-4-released'
),
array (
'title' => 'Wizard Component 1.2 Tutorial' ,
'link' => 'http://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial'
)
)
)
)
);
$rssAsSimpleXML = Xml :: fromArray ( $rss );
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?>' ;
$xmlText .= '<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">' ;
$xmlText .= '<channel>' ;
$xmlText .= '<atom:link href="http://bakery.cakephp.org/articles/rss" rel="self" type="application/rss+xml"/>' ;
$xmlText .= '<title>The Bakery: </title>' ;
$xmlText .= '<link>http://bakery.cakephp.org/</link>' ;
$xmlText .= '<description>Recent Articles at The Bakery.</description>' ;
$xmlText .= '<pubDate>Sun, 12 Sep 2010 04:18:26 -0500</pubDate>' ;
$xmlText .= '<item><title>CakePHP 1.3.4 released</title><link>http://bakery.cakephp.org/articles/view/cakephp-1-3-4-released</link></item>' ;
$xmlText .= '<item><title>Wizard Component 1.2 Tutorial</title><link>http://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial</link></item>' ;
$xmlText .= '</channel></rss>' ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $rssAsSimpleXML -> asXML ()), $xmlText );
2008-06-03 01:42:05 +00:00
}
2009-07-24 19:18:37 +00:00
2008-06-24 01:38:40 +00:00
/**
2010-09-02 00:04:53 +00:00
* testXmlRpc
2008-06-24 01:38:40 +00:00
*
* @ return void
*/
2010-09-02 00:04:53 +00:00
public function testXmlRpc () {
$xml = Xml :: build ( '<methodCall><methodName>test</methodName><params /></methodCall>' );
$expected = array (
'methodCall' => array (
'methodName' => 'test' ,
'params' => ''
)
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( Xml :: toArray ( $xml ), $expected );
2008-06-24 01:38:40 +00:00
2010-09-02 00:04:53 +00:00
$xml = Xml :: build ( '<methodCall><methodName>test</methodName><params><param><value><array><data><value><int>12</int></value><value><string>Egypt</string></value><value><boolean>0</boolean></value><value><int>-31</int></value></data></array></value></param></params></methodCall>' );
$expected = array (
'methodCall' => array (
'methodName' => 'test' ,
'params' => array (
'param' => array (
'value' => array (
'array' => array (
'data' => array (
'value' => array (
array ( 'int' => '12' ),
array ( 'string' => 'Egypt' ),
array ( 'boolean' => '0' ),
array ( 'int' => '-31' )
)
)
)
)
)
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( Xml :: toArray ( $xml ), $expected );
2009-07-24 19:18:37 +00:00
2010-09-08 22:40:33 +00:00
$xmlText = '<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><array><data><value><int>1</int></value><value><string>testing</string></value></data></array></value></param></params></methodResponse>' ;
2010-09-02 00:04:53 +00:00
$xml = Xml :: build ( $xmlText );
$expected = array (
'methodResponse' => array (
'params' => array (
'param' => array (
'value' => array (
'array' => array (
'data' => array (
'value' => array (
array ( 'int' => '1' ),
array ( 'string' => 'testing' )
)
)
)
)
)
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( Xml :: toArray ( $xml ), $expected );
2008-09-15 11:50:51 +00:00
2010-09-02 00:04:53 +00:00
$xml = Xml :: fromArray ( $expected , 'tags' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $xml -> asXML ()), $xmlText );
2008-09-15 11:50:51 +00:00
}
2009-07-24 19:18:37 +00:00
2008-07-31 23:50:32 +00:00
/**
2010-09-02 00:37:32 +00:00
* testSoap
2008-07-31 23:50:32 +00:00
*
* @ return void
*/
2010-09-02 00:37:32 +00:00
public function testSoap () {
2011-04-17 10:35:21 +00:00
$xmlRequest = Xml :: build ( CAKE . 'Test' . DS . 'Fixture' . DS . 'soap_request.xml' );
2010-09-02 00:37:32 +00:00
$expected = array (
'Envelope' => array (
2010-09-07 03:31:50 +00:00
'@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding' ,
'soap:Body' => array (
'm:GetStockPrice' => array (
'm:StockName' => 'IBM'
2008-07-31 23:50:32 +00:00
)
)
)
2010-09-02 00:37:32 +00:00
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( $xmlRequest ));
2008-07-31 23:50:32 +00:00
2011-04-17 10:35:21 +00:00
$xmlResponse = Xml :: build ( CAKE . 'Test' . DS . 'Fixture' . DS . 'soap_response.xml' );
2008-08-10 16:26:43 +00:00
$expected = array (
2010-09-02 00:37:32 +00:00
'Envelope' => array (
2010-09-07 03:31:50 +00:00
'@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding' ,
'soap:Body' => array (
'm:GetStockPriceResponse' => array (
'm:Price' => '34.5'
2010-09-02 00:37:32 +00:00
)
2008-07-31 23:50:32 +00:00
)
)
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( $xmlResponse ));
2010-09-12 15:06:59 +00:00
$xml = array (
'soap:Envelope' => array (
'xmlns:soap' => 'http://www.w3.org/2001/12/soap-envelope' ,
'@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding' ,
'soap:Body' => array (
'xmlns:m' => 'http://www.example.org/stock' ,
'm:GetStockPrice' => array (
'm:StockName' => 'IBM'
2008-07-31 23:50:32 +00:00
)
)
)
);
2010-09-12 15:06:59 +00:00
$xmlRequest = Xml :: fromArray ( $xml , array ( 'encoding' => null ));
$xmlText = '<' . '?xml version="1.0"?>' ;
$xmlText .= '<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">' ;
$xmlText .= '<soap:Body xmlns:m="http://www.example.org/stock">' ;
$xmlText .= '<m:GetStockPrice><m:StockName>IBM</m:StockName></m:GetStockPrice>' ;
$xmlText .= '</soap:Body></soap:Envelope>' ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $xmlRequest -> asXML ()), $xmlText );
2010-09-02 00:37:32 +00:00
}
2008-07-31 23:50:32 +00:00
2010-09-07 03:31:50 +00:00
/**
* testNamespace
*
2012-02-23 23:29:53 +00:00
* @ return void
2010-09-07 03:31:50 +00:00
*/
public function testNamespace () {
$xmlResponse = Xml :: build ( '<root xmlns:ns="http://cakephp.org"><ns:tag id="1"><child>good</child><otherchild>bad</otherchild></ns:tag><tag>Tag without ns</tag></root>' );
2008-08-10 16:26:43 +00:00
$expected = array (
2010-09-07 03:31:50 +00:00
'root' => array (
'ns:tag' => array (
'@id' => '1' ,
'child' => 'good' ,
'otherchild' => 'bad'
),
'tag' => 'Tag without ns'
2008-07-31 23:50:32 +00:00
)
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( $xmlResponse ));
2008-08-10 16:26:43 +00:00
2010-09-07 03:31:50 +00:00
$xmlResponse = Xml :: build ( '<root xmlns:ns="http://cakephp.org"><ns:tag id="1" /><tag><id>1</id></tag></root>' );
2008-08-10 16:26:43 +00:00
$expected = array (
2010-09-07 03:31:50 +00:00
'root' => array (
'ns:tag' => array (
'@id' => '1'
),
'tag' => array (
'id' => '1'
2008-07-31 23:50:32 +00:00
)
)
2010-09-07 03:31:50 +00:00
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( $xmlResponse ));
2010-09-07 03:31:50 +00:00
$xmlResponse = Xml :: build ( '<root xmlns:ns="http://cakephp.org"><ns:attr>1</ns:attr></root>' );
$expected = array (
'root' => array (
'ns:attr' => '1'
)
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( $xmlResponse ));
2010-09-07 03:31:50 +00:00
$xmlResponse = Xml :: build ( '<root><ns:attr xmlns:ns="http://cakephp.org">1</ns:attr></root>' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , Xml :: toArray ( $xmlResponse ));
2010-09-11 15:36:43 +00:00
$xml = array (
'root' => array (
'ns:attr' => array (
'xmlns:ns' => 'http://cakephp.org' ,
'@' => 1
2008-09-04 15:34:08 +00:00
)
)
2010-09-11 15:36:43 +00:00
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><ns:attr xmlns:ns="http://cakephp.org">1</ns:attr></root>' ;
$xmlResponse = Xml :: fromArray ( $xml );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $xmlResponse -> asXML ()), $expected );
2010-09-11 15:36:43 +00:00
$xml = array (
'root' => array (
'tag' => array (
'xmlns:pref' => 'http://cakephp.org' ,
'pref:item' => array (
'item 1' ,
'item 2'
2008-09-05 17:20:18 +00:00
)
)
)
2010-09-11 15:36:43 +00:00
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><tag xmlns:pref="http://cakephp.org"><pref:item>item 1</pref:item><pref:item>item 2</pref:item></tag></root>' ;
$xmlResponse = Xml :: fromArray ( $xml );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $xmlResponse -> asXML ()), $expected );
2010-09-11 15:36:43 +00:00
$xml = array (
'root' => array (
'tag' => array (
'xmlns:' => 'http://cakephp.org'
2009-09-22 20:47:11 +00:00
)
)
);
2010-09-11 15:36:43 +00:00
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><tag xmlns="http://cakephp.org"/></root>' ;
$xmlResponse = Xml :: fromArray ( $xml );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $xmlResponse -> asXML ()), $expected );
2010-03-26 08:59:09 +00:00
2010-09-11 15:36:43 +00:00
$xml = array (
'root' => array (
'xmlns:' => 'http://cakephp.org'
)
2010-03-26 08:59:09 +00:00
);
2010-09-11 15:36:43 +00:00
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root xmlns="http://cakephp.org"/>' ;
$xmlResponse = Xml :: fromArray ( $xml );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $xmlResponse -> asXML ()), $expected );
2010-03-26 08:59:09 +00:00
2010-09-11 15:36:43 +00:00
$xml = array (
'root' => array (
'xmlns:ns' => 'http://cakephp.org'
)
2010-03-26 08:59:09 +00:00
);
2010-09-11 15:36:43 +00:00
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root xmlns:ns="http://cakephp.org"/>' ;
$xmlResponse = Xml :: fromArray ( $xml );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( str_replace ( array ( " \r " , " \n " ), '' , $xmlResponse -> asXML ()), $expected );
2008-07-31 23:50:32 +00:00
}
2009-07-24 19:18:37 +00:00
2010-10-23 15:01:13 +00:00
/**
* test that CDATA blocks don ' t get screwed up by SimpleXml
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testCdata () {
2010-10-23 15:01:13 +00:00
$xml = '<' . '?xml version="1.0" encoding="UTF-8"?>' .
'<people><name><![CDATA[ Mark ]]></name></people>' ;
$result = Xml :: build ( $xml );
$this -> assertEquals ( ' Mark ' , ( string ) $result -> name );
}
2009-03-18 17:55:58 +00:00
/**
2010-08-23 21:30:03 +00:00
* data provider for toArray () failures
2009-03-18 17:55:58 +00:00
*
2010-08-23 21:30:03 +00:00
* @ return array
2009-03-18 17:55:58 +00:00
*/
2010-08-23 21:30:03 +00:00
public static function invalidToArrayDataProvider () {
return array (
array ( new DateTime ()),
array ( array ())
);
2008-08-26 01:18:15 +00:00
}
2009-07-24 19:18:37 +00:00
2009-03-18 17:55:58 +00:00
/**
2010-08-23 21:30:03 +00:00
* testToArrayFail method
2009-03-18 17:55:58 +00:00
*
2010-08-23 21:30:03 +00:00
* @ dataProvider invalidToArrayDataProvider
2011-11-03 03:44:22 +00:00
* @ expectedException XmlException
2009-03-18 17:55:58 +00:00
*/
2010-09-01 23:09:03 +00:00
public function testToArrayFail ( $value ) {
2010-08-23 21:30:03 +00:00
Xml :: toArray ( $value );
2008-11-26 18:21:21 +00:00
}
2009-07-24 19:18:37 +00:00
2009-03-18 17:55:58 +00:00
/**
2010-09-13 03:43:11 +00:00
* testWithModel method
2009-03-18 17:55:58 +00:00
*
* @ return void
*/
2010-09-13 03:43:11 +00:00
public function testWithModel () {
$this -> loadFixtures ( 'User' , 'Article' );
2008-10-04 19:50:38 +00:00
2010-10-14 02:30:40 +00:00
$user = new XmlUser ();
2010-09-13 03:43:11 +00:00
$data = $user -> read ( null , 1 );
2008-10-04 19:50:38 +00:00
2010-09-13 03:43:11 +00:00
$obj = Xml :: build ( compact ( 'data' ));
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><data>' ;
$expected .= '<User><id>1</id><user>mariano</user><password>5f4dcc3b5aa765d61d8327deb882cf99</password>' ;
$expected .= '<created>2007-03-17 01:16:23</created><updated>2007-03-17 01:18:31</updated></User>' ;
$expected .= '<Article><id>1</id><user_id>1</user_id><title>First Article</title><body>First Article Body</body>' ;
$expected .= '<published>Y</published><created>2007-03-18 10:39:23</created><updated>2007-03-18 10:41:31</updated></Article>' ;
$expected .= '<Article><id>3</id><user_id>1</user_id><title>Third Article</title><body>Third Article Body</body>' ;
$expected .= '<published>Y</published><created>2007-03-18 10:43:23</created><updated>2007-03-18 10:45:31</updated></Article>' ;
$expected .= '</data>' ;
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , str_replace ( array ( " \r " , " \n " ), '' , $obj -> asXML ()));
2012-03-14 02:59:20 +00:00
2011-11-26 17:09:08 +00:00
//multiple model results - without a records key it would fatal error
2011-12-01 07:21:31 +00:00
$data = $user -> find ( 'all' , array ( 'limit' => 2 ));
2011-11-30 15:44:11 +00:00
$data = array ( 'records' => $data );
2011-11-26 17:09:08 +00:00
$obj = Xml :: build ( compact ( 'data' ));
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><data>' ;
$expected .= '<records>' ;
$expected .= '<User><id>1</id><user>mariano</user><password>5f4dcc3b5aa765d61d8327deb882cf99</password>' ;
$expected .= '<created>2007-03-17 01:16:23</created><updated>2007-03-17 01:18:31</updated></User>' ;
$expected .= '<Article><id>1</id><user_id>1</user_id><title>First Article</title><body>First Article Body</body>' ;
$expected .= '<published>Y</published><created>2007-03-18 10:39:23</created><updated>2007-03-18 10:41:31</updated></Article>' ;
$expected .= '<Article><id>3</id><user_id>1</user_id><title>Third Article</title><body>Third Article Body</body>' ;
$expected .= '<published>Y</published><created>2007-03-18 10:43:23</created><updated>2007-03-18 10:45:31</updated></Article>' ;
$expected .= '</records><records><User><id>2</id><user>nate</user><password>5f4dcc3b5aa765d61d8327deb882cf99</password>' ;
$expected .= '<created>2007-03-17 01:18:23</created><updated>2007-03-17 01:20:31</updated></User><Article/>' ;
$expected .= '</records>' ;
$expected .= '</data>' ;
$result = $obj -> asXML ();
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , str_replace ( array ( " \r " , " \n " ), '' , $obj -> asXML ()));
2008-10-04 19:50:38 +00:00
}
2010-03-27 16:48:31 +00:00
2011-11-26 02:19:31 +00:00
/**
* Test ampersand in text elements .
*
* @ return void
*/
public function testAmpInText () {
$data = array (
'outer' => array (
'inner' => array ( 'name' => 'mark & mark' )
)
);
$obj = Xml :: build ( $data );
$result = $obj -> asXml ();
$this -> assertContains ( 'mark & mark' , $result );
}
2008-05-30 11:40:08 +00:00
}