Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,20 +2,20 @@
/**
* XmlTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Xml', 'Utility');
App::uses('CakeTestModel', 'TestSuite/Fixture');
@ -29,7 +29,7 @@ class XmlArticle extends CakeTestModel {
/**
* name property
*
* @var string 'Article'
* @var string
*/
public $name = 'Article';
@ -56,7 +56,7 @@ class XmlUser extends CakeTestModel {
/**
* name property
*
* @var string 'User'
* @var string
*/
public $name = 'User';
@ -82,7 +82,7 @@ class XmlTest extends CakeTestCase {
/**
* autoFixtures property
*
* @var bool false
* @var bool
*/
public $autoFixtures = false;
@ -167,6 +167,40 @@ class XmlTest extends CakeTestCase {
$this->assertNotRegExp('/encoding/', $obj->saveXML());
}
/**
* test build() method with huge option
*
* @return void
*/
public function testBuildHuge() {
$xml = '<tag>value</tag>';
$obj = Xml::build($xml, array('parseHuge' => true));
$this->assertEquals('tag', $obj->getName());
$this->assertEquals('value', (string)$obj);
}
/**
* Test that the readFile option disables local file parsing.
*
* @expectedException XmlException
* @return void
*/
public function testBuildFromFileWhenDisabled() {
$xml = CAKE . 'Test' . DS . 'Fixture' . DS . 'sample.xml';
Xml::build($xml, array('readFile' => false));
}
/**
* Test that the readFile option disables local file parsing.
*
* @expectedException XmlException
* @return void
*/
public function testBuildFromUrlWhenDisabled() {
$xml = 'http://www.google.com';
Xml::build($xml, array('readFile' => false));
}
/**
* data provider function for testBuildInvalidData
*
@ -186,16 +220,27 @@ class XmlTest extends CakeTestCase {
*
* @dataProvider invalidDataProvider
* @expectedException XmlException
* return void
* @return void
*/
public function testBuildInvalidData($value) {
Xml::build($value);
}
/**
* Test that building SimpleXmlElement with invalid XML causes the right exception.
*
* @expectedException XmlException
* @return void
*/
public function testBuildInvalidDataSimpleXml() {
$input = '<derp';
Xml::build($input, array('return' => 'simplexml'));
}
/**
* test build with a single empty tag
*
* return void
* @return void
*/
public function testBuildEmptyTag() {
try {
@ -364,6 +409,36 @@ XML;
$this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
}
/**
* Test fromArray() with zero values.
*
* @return void
*/
public function testFromArrayZeroValue() {
$xml = array(
'tag' => array(
'@' => 0,
'@test' => 'A test'
)
);
$obj = Xml::fromArray($xml);
$xmlText = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<tag test="A test">0</tag>
XML;
$this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
$xml = array(
'tag' => array('0')
);
$obj = Xml::fromArray($xml);
$xmlText = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<tag>0</tag>
XML;
$this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
}
/**
* Test non-sequential keys in list types.
*
@ -401,6 +476,87 @@ XML;
$this->assertXmlStringEqualsXmlString($expected, $obj->asXML());
}
/**
* testFromArrayPretty method
*
* @return void
*/
public function testFromArrayPretty() {
$xml = array(
'tags' => array(
'tag' => array(
array(
'id' => '1',
'name' => 'defect'
),
array(
'id' => '2',
'name' => 'enhancement'
)
)
)
);
$expected = <<<XML
<?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>
XML;
$xmlResponse = Xml::fromArray($xml, array('pretty' => false));
$this->assertTextEquals($expected, $xmlResponse->asXML());
$expected = <<<XML
<?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>
XML;
$xmlResponse = Xml::fromArray($xml, array('pretty' => true));
$this->assertTextEquals($expected, $xmlResponse->asXML());
$xml = array(
'tags' => array(
'tag' => array(
array(
'id' => '1',
'name' => 'defect'
),
array(
'id' => '2',
'name' => 'enhancement'
)
)
)
);
$expected = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<tags><tag id="1" name="defect"/><tag id="2" name="enhancement"/></tags>
XML;
$xmlResponse = Xml::fromArray($xml, array('pretty' => false, 'format' => 'attributes'));
$this->assertTextEquals($expected, $xmlResponse->asXML());
$expected = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<tags>
<tag id="1" name="defect"/>
<tag id="2" name="enhancement"/>
</tags>
XML;
$xmlResponse = Xml::fromArray($xml, array('pretty' => true, 'format' => 'attributes'));
$this->assertTextEquals($expected, $xmlResponse->asXML());
}
/**
* data provider for fromArray() failures
*
@ -448,6 +604,7 @@ XML;
* testFromArrayFail method
*
* @dataProvider invalidArrayDataProvider
* @return void
*/
public function testFromArrayFail($value) {
try {
@ -458,6 +615,41 @@ XML;
}
}
/**
* Test that there are not unterminated errors when building xml
*
* @return void
*/
public function testFromArrayUnterminatedError() {
$data = array(
'product_ID' => 'GENERT-DL',
'deeplink' => 'http://example.com/deep',
'image_URL' => 'http://example.com/image',
'thumbnail_image_URL' => 'http://example.com/thumb',
'brand' => 'Malte Lange & Co',
'availability' => 'in stock',
'authors' => array(
'author' => array('Malte Lange & Co')
)
);
$xml = Xml::fromArray(array('products' => $data), 'tags');
$expected = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product_ID>GENERT-DL</product_ID>
<deeplink>http://example.com/deep</deeplink>
<image_URL>http://example.com/image</image_URL>
<thumbnail_image_URL>http://example.com/thumb</thumbnail_image_URL>
<brand>Malte Lange &amp; Co</brand>
<availability>in stock</availability>
<authors>
<author>Malte Lange &amp; Co</author>
</authors>
</products>
XML;
$this->assertXmlStringEqualsXmlString($expected, $xml->asXML());
}
/**
* testToArray method
*
@ -608,6 +800,16 @@ XML;
)
);
$this->assertEquals($expected, Xml::toArray($obj));
$xml = '<tag type="myType">0</tag>';
$obj = Xml::build($xml);
$expected = array(
'tag' => array(
'@type' => 'myType',
'@' => 0
)
);
$this->assertEquals($expected, Xml::toArray($obj));
}
/**
@ -632,7 +834,7 @@ XML;
'pubDate' => 'Tue, 31 Aug 2010 01:42:00 -0500',
'guid' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn'
);
$this->assertSame($rssAsArray['rss']['channel']['item'][1], $expected);
$this->assertSame($expected, $rssAsArray['rss']['channel']['item'][1]);
$rss = array(
'rss' => array(
@ -698,7 +900,7 @@ XML;
'params' => ''
)
);
$this->assertSame(Xml::toArray($xml), $expected);
$this->assertSame($expected, Xml::toArray($xml));
$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(
@ -722,7 +924,7 @@ XML;
)
)
);
$this->assertSame(Xml::toArray($xml), $expected);
$this->assertSame($expected, Xml::toArray($xml));
$xmlText = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
@ -764,7 +966,7 @@ XML;
)
)
);
$this->assertSame(Xml::toArray($xml), $expected);
$this->assertSame($expected, Xml::toArray($xml));
$xml = Xml::fromArray($expected, 'tags');
$this->assertXmlStringEqualsXmlString($xmlText, $xml->asXML());
@ -888,7 +1090,7 @@ XML;
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><ns:attr xmlns:ns="http://cakephp.org">1</ns:attr></root>';
$xmlResponse = Xml::fromArray($xml);
$this->assertEquals(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
$this->assertEquals($expected, str_replace(array("\r", "\n"), '', $xmlResponse->asXML()));
$xml = array(
'root' => array(
@ -973,6 +1175,7 @@ XML;
*
* @dataProvider invalidToArrayDataProvider
* @expectedException XmlException
* @return void
*/
public function testToArrayFail($value) {
Xml::toArray($value);
@ -1020,7 +1223,7 @@ XML;
</records>
</data>
XML;
$result = $obj->asXML();
$obj->asXML();
$this->assertXmlStringEqualsXmlString($expected, $obj->asXML());
}