Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch '2.1' into 2.2

Conflicts:
	lib/Cake/Model/Datasource/DataSource.php
	lib/Cake/VERSION.txt
  • Loading branch information...
commit 7b5e45b965f1fd75d726214d719c608c729c0249 2 parents 3a18384 + 4ab6d37
@markstory markstory authored
View
19 lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php
@@ -542,4 +542,23 @@ public function testComponentsSameRequestAndResponse() {
$this->assertSame($this->Case->controller->request, $this->Case->controller->RequestHandler->request);
}
+/**
+ * Test that testAction() doesn't destroy data in GET & POST
+ *
+ * @return void
+ */
+ public function testRestoreGetPost() {
+ $restored = array('new' => 'value');
+
+ $_GET = $restored;
+ $_POST = $restored;
+
+ $this->Case->generate('TestsApps');
+ $options = array('method' => 'get');
+ $this->Case->testAction('/tests_apps/index', $options);
+
+ $this->assertEquals($restored, $_GET);
+ $this->assertEquals($restored, $_POST);
+ }
+
}
View
276 lib/Cake/Test/Case/Utility/XmlTest.php
@@ -141,8 +141,14 @@ public function testBuild() {
$obj = Xml::build($xml, array('return' => 'domdocument'));
$this->assertEquals('tags', $obj->firstChild->nodeName);
- $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'));
+ $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')
+ );
$xml = array('tag' => 'value');
$obj = Xml::build($xml);
@@ -234,15 +240,33 @@ public function testFromArray() {
$this->assertTrue($obj instanceof SimpleXMLElement);
$this->assertEquals('tags', $obj->getName());
$this->assertEquals(2, count($obj));
- $xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1" name="defect"/><tag id="2" name="enhancement"/></tags>';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
+ $xmlText = <<<XML
+<?xml version="1.0" encoding="UTF-8"?>
+<tags>
+ <tag id="1" name="defect"/>
+ <tag id="2" name="enhancement"/>
+</tags>
+XML;
+ $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
$obj = Xml::fromArray($xml);
$this->assertTrue($obj instanceof SimpleXMLElement);
$this->assertEquals('tags', $obj->getName());
$this->assertEquals(2, count($obj));
- $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>';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
+ $xmlText = <<<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;
+ $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
$xml = array(
'tags' => array(
@@ -286,8 +310,18 @@ public function testFromArray() {
)
);
$obj = Xml::fromArray($xml, 'tags');
- $xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1"><name>defect</name></tag><tag id="2"><name>enhancement</name></tag></tags>';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
+ $xmlText = <<<XML
+<?xml version="1.0" encoding="UTF-8"?>
+<tags>
+ <tag id="1">
+ <name>defect</name>
+ </tag>
+ <tag id="2">
+ <name>enhancement</name>
+ </tag>
+</tags>
+XML;
+ $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
$xml = array(
'tags' => array(
@@ -306,8 +340,11 @@ public function testFromArray() {
)
);
$obj = Xml::fromArray($xml, 'tags');
- $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>';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
+ $xmlText = <<<XML
+<?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>
+XML;
+ $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
$xml = array(
'tags' => array(
@@ -319,7 +356,44 @@ public function testFromArray() {
);
$obj = Xml::fromArray($xml, 'attributes');
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1">defect</tag></tags>';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
+ $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
+ }
+
+/**
+ * Test non-sequential keys in list types.
+ *
+ * @return void
+ */
+ public function testFromArrayNonSequentialKeys() {
+ $xmlArray = array(
+ 'Event' => array(
+ array(
+ 'id' => '235',
+ 'Attribute' => array(
+ 0 => array(
+ 'id' => '9646',
+ ),
+ 2 => array(
+ 'id' => '9647',
+ )
+ )
+ )
+ )
+ );
+ $obj = Xml::fromArray($xmlArray);
+ $expected = <<<XML
+<?xml version="1.0" encoding="UTF-8"?>
+<Event>
+ <id>235</id>
+ <Attribute>
+ <id>9646</id>
+ </Attribute>
+ <Attribute>
+ <id>9647</id>
+ </Attribute>
+</Event>
+XML;
+ $this->assertXmlStringEqualsXmlString($expected, $obj->asXML());
}
/**
@@ -477,9 +551,11 @@ public function testToArray() {
$this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, 'attributes')));
$this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, array('format' => 'attributes', 'return' => 'domdocument'))));
- $xml = '<root>';
- $xml .= '<tag id="1">defect</tag>';
- $xml .= '</root>';
+ $xml = <<<XML
+<root>
+<tag id="1">defect</tag>
+</root>
+XML;
$obj = Xml::build($xml);
$expected = array(
@@ -492,11 +568,13 @@ public function testToArray() {
);
$this->assertEquals($expected, Xml::toArray($obj));
- $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>';
+ $xml = <<<XML
+<root>
+ <table xmlns="http://www.w3.org/TR/html4/"><tr><td>Apples</td><td>Bananas</td></tr></table>
+ <table xmlns="http://www.cakephp.org"><name>CakePHP</name><license>MIT</license></table>
+ <table>The book is on the table.</table>
+</root>
+XML;
$obj = Xml::build($xml);
$expected = array(
@@ -510,10 +588,12 @@ public function testToArray() {
);
$this->assertEquals($expected, Xml::toArray($obj));
- $xml = '<root xmlns:cake="http://www.cakephp.org/">';
- $xml .= '<tag>defect</tag>';
- $xml .= '<cake:bug>1</cake:bug>';
- $xml .= '</root>';
+ $xml = <<<XML
+<root xmlns:cake="http://www.cakephp.org/">
+<tag>defect</tag>
+<cake:bug>1</cake:bug>
+</root>
+XML;
$obj = Xml::build($xml);
$expected = array(
@@ -577,18 +657,27 @@ public function testRss() {
)
);
$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>';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $rssAsSimpleXML->asXML()), $xmlText);
+ $xmlText = <<<XML
+<?xml version="1.0" encoding="UTF-8"?>
+<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
+<channel>
+ <atom:link href="http://bakery.cakephp.org/articles/rss" rel="self" type="application/rss+xml"/>
+ <title>The Bakery: </title>
+ <link>http://bakery.cakephp.org/</link>
+ <description>Recent Articles at The Bakery.</description>
+ <pubDate>Sun, 12 Sep 2010 04:18:26 -0500</pubDate>
+ <item>
+ <title>CakePHP 1.3.4 released</title>
+ <link>http://bakery.cakephp.org/articles/view/cakephp-1-3-4-released</link>
+ </item>
+ <item>
+ <title>Wizard Component 1.2 Tutorial</title>
+ <link>http://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial</link>
+ </item>
+</channel>
+</rss>
+XML;
+ $this->assertXmlStringEqualsXmlString($xmlText, $rssAsSimpleXML->asXML());
}
/**
@@ -630,7 +719,27 @@ public function testXmlRpc() {
);
$this->assertSame(Xml::toArray($xml), $expected);
- $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>';
+ $xmlText = <<<XML
+<?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>
+XML;
$xml = Xml::build($xmlText);
$expected = array(
'methodResponse' => array(
@@ -653,7 +762,7 @@ public function testXmlRpc() {
$this->assertSame(Xml::toArray($xml), $expected);
$xml = Xml::fromArray($expected, 'tags');
- $this->assertEquals(str_replace(array("\r", "\n"), '', $xml->asXML()), $xmlText);
+ $this->assertXmlStringEqualsXmlString($xmlText, $xml->asXML());
}
/**
@@ -701,12 +810,15 @@ public function testSoap() {
)
);
$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>';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $xmlRequest->asXML()), $xmlText);
+ $xmlText = <<<XML
+<?xml version="1.0"?>
+<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
+ <soap:Body xmlns:m="http://www.example.org/stock">
+ <m:GetStockPrice><m:StockName>IBM</m:StockName></m:GetStockPrice>
+ </soap:Body>
+</soap:Envelope>
+XML;
+ $this->assertXmlStringEqualsXmlString($xmlText, $xmlRequest->asXML());
}
/**
@@ -715,7 +827,16 @@ public function testSoap() {
* @return void
*/
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>');
+ $xml = <<<XML
+<root xmlns:ns="http://cakephp.org">
+ <ns:tag id="1">
+ <child>good</child>
+ <otherchild>bad</otherchild>
+ </ns:tag>
+ <tag>Tag without ns</tag>
+</root>
+XML;
+ $xmlResponse = Xml::build($xml);
$expected = array(
'root' => array(
'ns:tag' => array(
@@ -775,9 +896,17 @@ public function testNamespace() {
)
)
);
- $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>';
+ $expected = <<<XML
+<?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>
+XML;
$xmlResponse = Xml::fromArray($xml);
- $this->assertEquals(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
+ $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());
$xml = array(
'root' => array(
@@ -788,7 +917,7 @@ public function testNamespace() {
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><tag xmlns="http://cakephp.org"/></root>';
$xmlResponse = Xml::fromArray($xml);
- $this->assertEquals(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
+ $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());
$xml = array(
'root' => array(
@@ -797,7 +926,7 @@ public function testNamespace() {
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root xmlns="http://cakephp.org"/>';
$xmlResponse = Xml::fromArray($xml);
- $this->assertEquals(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
+ $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());
$xml = array(
'root' => array(
@@ -806,7 +935,7 @@ public function testNamespace() {
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root xmlns:ns="http://cakephp.org"/>';
$xmlResponse = Xml::fromArray($xml);
- $this->assertEquals(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
+ $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());
}
/**
@@ -856,34 +985,38 @@ public function testWithModel() {
$data = $user->read(null, 1);
$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>';
- $this->assertEquals($expected, str_replace(array("\r", "\n"), '', $obj->asXML()));
+ $expected = <<<XML
+<?xml version="1.0" encoding="UTF-8"?><data>
+<User><id>1</id><user>mariano</user><password>5f4dcc3b5aa765d61d8327deb882cf99</password>
+<created>2007-03-17 01:16:23</created><updated>2007-03-17 01:18:31</updated></User>
+<Article><id>1</id><user_id>1</user_id><title>First Article</title><body>First Article Body</body>
+<published>Y</published><created>2007-03-18 10:39:23</created><updated>2007-03-18 10:41:31</updated></Article>
+<Article><id>3</id><user_id>1</user_id><title>Third Article</title><body>Third Article Body</body>
+<published>Y</published><created>2007-03-18 10:43:23</created><updated>2007-03-18 10:45:31</updated></Article>
+</data>
+XML;
+ $this->assertXmlStringEqualsXmlString($expected, $obj->asXML());
//multiple model results - without a records key it would fatal error
$data = $user->find('all', array('limit' => 2));
$data = array('records' => $data);
$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>';
+ $expected = <<<XML
+<?xml version="1.0" encoding="UTF-8"?><data>
+<records>
+<User><id>1</id><user>mariano</user><password>5f4dcc3b5aa765d61d8327deb882cf99</password>
+<created>2007-03-17 01:16:23</created><updated>2007-03-17 01:18:31</updated></User>
+<Article><id>1</id><user_id>1</user_id><title>First Article</title><body>First Article Body</body>
+<published>Y</published><created>2007-03-18 10:39:23</created><updated>2007-03-18 10:41:31</updated></Article>
+<Article><id>3</id><user_id>1</user_id><title>Third Article</title><body>Third Article Body</body>
+<published>Y</published><created>2007-03-18 10:43:23</created><updated>2007-03-18 10:45:31</updated></Article>
+</records><records><User><id>2</id><user>nate</user><password>5f4dcc3b5aa765d61d8327deb882cf99</password>
+<created>2007-03-17 01:18:23</created><updated>2007-03-17 01:20:31</updated></User><Article/>
+</records>
+</data>
+XML;
$result = $obj->asXML();
- $this->assertEquals($expected, str_replace(array("\r", "\n"), '', $obj->asXML()));
+ $this->assertXmlStringEqualsXmlString($expected, $obj->asXML());
}
/**
@@ -901,4 +1034,5 @@ public function testAmpInText() {
$result = $obj->asXml();
$this->assertContains('mark &amp; mark', $result);
}
+
}
View
6 lib/Cake/TestSuite/ControllerTestCase.php
@@ -218,6 +218,8 @@ protected function _testAction($url = '', $options = array()) {
'return' => 'result'
), $options);
+ $restore = array('get' => $_GET, 'post' => $_POST);
+
$_SERVER['REQUEST_METHOD'] = strtoupper($options['method']);
if (is_array($options['data'])) {
if (strtoupper($options['method']) == 'GET') {
@@ -273,6 +275,10 @@ protected function _testAction($url = '', $options = array()) {
}
$this->__dirtyController = true;
$this->headers = $Dispatch->response->header();
+
+ $_GET = $restore['get'];
+ $_POST = $restore['post'];
+
return $this->{$options['return']};
}
View
2  lib/Cake/Utility/Xml.php
@@ -230,7 +230,7 @@ protected static function _fromArray($dom, $node, &$data, $format) {
if ($key[0] === '@') {
throw new XmlException(__d('cake_dev', 'Invalid array'));
}
- if (array_keys($value) === range(0, count($value) - 1)) { // List
+ if (is_numeric(implode(array_keys($value), ''))) { // List
foreach ($value as $item) {
$itemData = compact('dom', 'node', 'key', 'format');
$itemData['value'] = $item;
Please sign in to comment.
Something went wrong with that request. Please try again.