diff --git a/lib/Cake/Model/Datasource/DataSource.php b/lib/Cake/Model/Datasource/DataSource.php
index 085a2c910..70f4d436f 100644
--- a/lib/Cake/Model/Datasource/DataSource.php
+++ b/lib/Cake/Model/Datasource/DataSource.php
@@ -416,6 +416,14 @@ class DataSource extends Object {
return null;
}
+/**
+ * Close the connection to the datasource.
+ *
+ * @return void
+ */
+ public function close() {
+ }
+
/**
* Closes the current datasource.
*
diff --git a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php
index af124be1d..cf6bbb85a 100644
--- a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php
+++ b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php
@@ -542,4 +542,23 @@ class ControllerTestCaseTest extends CakeTestCase {
$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);
+ }
+
}
diff --git a/lib/Cake/Test/Case/Utility/XmlTest.php b/lib/Cake/Test/Case/Utility/XmlTest.php
index d1bf8d1b2..cd1fc87b4 100644
--- a/lib/Cake/Test/Case/Utility/XmlTest.php
+++ b/lib/Cake/Test/Case/Utility/XmlTest.php
@@ -141,8 +141,14 @@ class XmlTest extends CakeTestCase {
$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 @@ class XmlTest extends CakeTestCase {
$this->assertTrue($obj instanceof SimpleXMLElement);
$this->assertEquals('tags', $obj->getName());
$this->assertEquals(2, count($obj));
- $xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?>';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
+ $xmlText = <<
+
+
+
+
+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"?>1defect2enhancement';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
+ $xmlText = <<
+
+
+ 1
+ defect
+
+
+ 2
+ enhancement
+
+
+XML;
+ $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
$xml = array(
'tags' => array(
@@ -286,8 +310,18 @@ class XmlTest extends CakeTestCase {
)
);
$obj = Xml::fromArray($xml, 'tags');
- $xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?>defectenhancement';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
+ $xmlText = <<
+
+
+ defect
+
+
+ enhancement
+
+
+XML;
+ $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
$xml = array(
'tags' => array(
@@ -306,8 +340,11 @@ class XmlTest extends CakeTestCase {
)
);
$obj = Xml::fromArray($xml, 'tags');
- $xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?>All tagsTag 1defectenhancement';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
+ $xmlText = <<
+All tagsTag 1defectenhancement
+XML;
+ $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
$xml = array(
'tags' => array(
@@ -319,7 +356,44 @@ class XmlTest extends CakeTestCase {
);
$obj = Xml::fromArray($xml, 'attributes');
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?>defect';
- $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 = <<
+
+ 235
+
+ 9646
+
+
+ 9647
+
+
+XML;
+ $this->assertXmlStringEqualsXmlString($expected, $obj->asXML());
}
/**
@@ -477,9 +551,11 @@ class XmlTest extends CakeTestCase {
$this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, 'attributes')));
$this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, array('format' => 'attributes', 'return' => 'domdocument'))));
- $xml = '';
- $xml .= 'defect';
- $xml .= '';
+ $xml = <<
+defect
+
+XML;
$obj = Xml::build($xml);
$expected = array(
@@ -492,11 +568,13 @@ class XmlTest extends CakeTestCase {
);
$this->assertEquals($expected, Xml::toArray($obj));
- $xml = '';
- $xml .= '';
- $xml .= '';
- $xml .= 'The book is on the table.
';
- $xml .= '';
+ $xml = <<
+
+
+ The book is on the table.
+
+XML;
$obj = Xml::build($xml);
$expected = array(
@@ -510,10 +588,12 @@ class XmlTest extends CakeTestCase {
);
$this->assertEquals($expected, Xml::toArray($obj));
- $xml = '';
- $xml .= 'defect';
- $xml .= '1';
- $xml .= '';
+ $xml = <<
+defect
+1
+
+XML;
$obj = Xml::build($xml);
$expected = array(
@@ -577,18 +657,27 @@ class XmlTest extends CakeTestCase {
)
);
$rssAsSimpleXML = Xml::fromArray($rss);
- $xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?>';
- $xmlText .= '';
- $xmlText .= '';
- $xmlText .= '';
- $xmlText .= 'The Bakery: ';
- $xmlText .= 'http://bakery.cakephp.org/';
- $xmlText .= 'Recent Articles at The Bakery.';
- $xmlText .= 'Sun, 12 Sep 2010 04:18:26 -0500';
- $xmlText .= '- CakePHP 1.3.4 releasedhttp://bakery.cakephp.org/articles/view/cakephp-1-3-4-released
';
- $xmlText .= '- Wizard Component 1.2 Tutorialhttp://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial
';
- $xmlText .= '';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $rssAsSimpleXML->asXML()), $xmlText);
+ $xmlText = <<
+
+
+
+ The Bakery:
+ http://bakery.cakephp.org/
+ Recent Articles at The Bakery.
+ Sun, 12 Sep 2010 04:18:26 -0500
+ -
+ CakePHP 1.3.4 released
+ http://bakery.cakephp.org/articles/view/cakephp-1-3-4-released
+
+ -
+ Wizard Component 1.2 Tutorial
+ http://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial
+
+
+
+XML;
+ $this->assertXmlStringEqualsXmlString($xmlText, $rssAsSimpleXML->asXML());
}
/**
@@ -630,7 +719,27 @@ class XmlTest extends CakeTestCase {
);
$this->assertSame(Xml::toArray($xml), $expected);
- $xmlText = '1testing';
+ $xmlText = <<
+
+
+
+
+
+
+
+ 1
+
+
+ testing
+
+
+
+
+
+
+
+XML;
$xml = Xml::build($xmlText);
$expected = array(
'methodResponse' => array(
@@ -653,7 +762,7 @@ class XmlTest extends CakeTestCase {
$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 @@ class XmlTest extends CakeTestCase {
)
);
$xmlRequest = Xml::fromArray($xml, array('encoding' => null));
- $xmlText = '<' . '?xml version="1.0"?>';
- $xmlText .= '';
- $xmlText .= '';
- $xmlText .= 'IBM';
- $xmlText .= '';
- $this->assertEquals(str_replace(array("\r", "\n"), '', $xmlRequest->asXML()), $xmlText);
+ $xmlText = <<
+
+
+ IBM
+
+
+XML;
+ $this->assertXmlStringEqualsXmlString($xmlText, $xmlRequest->asXML());
}
/**
@@ -715,7 +827,16 @@ class XmlTest extends CakeTestCase {
* @return void
*/
public function testNamespace() {
- $xmlResponse = Xml::build('goodbadTag without ns');
+ $xml = <<
+
+ good
+ bad
+
+ Tag without ns
+
+XML;
+ $xmlResponse = Xml::build($xml);
$expected = array(
'root' => array(
'ns:tag' => array(
@@ -775,9 +896,17 @@ class XmlTest extends CakeTestCase {
)
)
);
- $expected = '<' . '?xml version="1.0" encoding="UTF-8"?>item 1item 2';
+ $expected = <<
+
+
+ item 1
+ item 2
+
+
+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 @@ class XmlTest extends CakeTestCase {
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?>';
$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 @@ class XmlTest extends CakeTestCase {
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?>';
$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 @@ class XmlTest extends CakeTestCase {
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?>';
$xmlResponse = Xml::fromArray($xml);
- $this->assertEquals(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
+ $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());
}
/**
@@ -856,34 +985,38 @@ class XmlTest extends CakeTestCase {
$data = $user->read(null, 1);
$obj = Xml::build(compact('data'));
- $expected = '<' . '?xml version="1.0" encoding="UTF-8"?>';
- $expected .= '1mariano5f4dcc3b5aa765d61d8327deb882cf99';
- $expected .= '2007-03-17 01:16:232007-03-17 01:18:31';
- $expected .= '11First ArticleFirst Article Body';
- $expected .= 'Y2007-03-18 10:39:232007-03-18 10:41:31';
- $expected .= '31Third ArticleThird Article Body';
- $expected .= 'Y2007-03-18 10:43:232007-03-18 10:45:31';
- $expected .= '';
- $this->assertEquals($expected, str_replace(array("\r", "\n"), '', $obj->asXML()));
+ $expected = <<
+1mariano5f4dcc3b5aa765d61d8327deb882cf99
+2007-03-17 01:16:232007-03-17 01:18:31
+11First ArticleFirst Article Body
+Y2007-03-18 10:39:232007-03-18 10:41:31
+31Third ArticleThird Article Body
+Y2007-03-18 10:43:232007-03-18 10:45:31
+
+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"?>';
- $expected .= '';
- $expected .= '1mariano5f4dcc3b5aa765d61d8327deb882cf99';
- $expected .= '2007-03-17 01:16:232007-03-17 01:18:31';
- $expected .= '11First ArticleFirst Article Body';
- $expected .= 'Y2007-03-18 10:39:232007-03-18 10:41:31';
- $expected .= '31Third ArticleThird Article Body';
- $expected .= 'Y2007-03-18 10:43:232007-03-18 10:45:31';
- $expected .= '2nate5f4dcc3b5aa765d61d8327deb882cf99';
- $expected .= '2007-03-17 01:18:232007-03-17 01:20:31';
- $expected .= '';
- $expected .= '';
+ $expected = <<
+
+1mariano5f4dcc3b5aa765d61d8327deb882cf99
+2007-03-17 01:16:232007-03-17 01:18:31
+11First ArticleFirst Article Body
+Y2007-03-18 10:39:232007-03-18 10:41:31
+31Third ArticleThird Article Body
+Y2007-03-18 10:43:232007-03-18 10:45:31
+2nate5f4dcc3b5aa765d61d8327deb882cf99
+2007-03-17 01:18:232007-03-17 01:20:31
+
+
+XML;
$result = $obj->asXML();
- $this->assertEquals($expected, str_replace(array("\r", "\n"), '', $obj->asXML()));
+ $this->assertXmlStringEqualsXmlString($expected, $obj->asXML());
}
/**
@@ -901,4 +1034,5 @@ class XmlTest extends CakeTestCase {
$result = $obj->asXml();
$this->assertContains('mark & mark', $result);
}
+
}
diff --git a/lib/Cake/TestSuite/ControllerTestCase.php b/lib/Cake/TestSuite/ControllerTestCase.php
index c017942d3..ad279785f 100644
--- a/lib/Cake/TestSuite/ControllerTestCase.php
+++ b/lib/Cake/TestSuite/ControllerTestCase.php
@@ -217,6 +217,8 @@ abstract class ControllerTestCase extends CakeTestCase {
'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') {
@@ -272,6 +274,10 @@ abstract class ControllerTestCase extends CakeTestCase {
}
$this->__dirtyController = true;
$this->headers = $Dispatch->response->header();
+
+ $_GET = $restore['get'];
+ $_POST = $restore['post'];
+
return $this->{$options['return']};
}
diff --git a/lib/Cake/Utility/Xml.php b/lib/Cake/Utility/Xml.php
index 70044471e..1f9f69caf 100644
--- a/lib/Cake/Utility/Xml.php
+++ b/lib/Cake/Utility/Xml.php
@@ -230,7 +230,7 @@ class Xml {
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;