From 7fd19551dbb03275298cdf27ce265a4782e7a00a Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sun, 29 Apr 2012 21:07:12 -0430 Subject: [PATCH 1/5] Update version number to 2.1.2 --- lib/Cake/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/VERSION.txt b/lib/Cake/VERSION.txt index f092e3ba8..2225bff48 100644 --- a/lib/Cake/VERSION.txt +++ b/lib/Cake/VERSION.txt @@ -17,4 +17,4 @@ // @license MIT License (http://www.opensource.org/licenses/mit-license.php) // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -2.1.1 +2.1.2 From 004bc5b6e761a039e498e1ec25c6a2f35269c0f0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 30 Apr 2012 20:36:03 -0400 Subject: [PATCH 2/5] Fix overwriting of GET/POST ControllerTestCase was overwriting GET and POST and not restoring them at the end of testAction. Fixes #2841 --- .../Case/TestSuite/ControllerTestCaseTest.php | 19 +++++++++++++++++++ lib/Cake/TestSuite/ControllerTestCase.php | 6 ++++++ 2 files changed, 25 insertions(+) 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/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']}; } From 128c719bd01bc66e3a59b88c2edb287b0bf482b0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 30 Apr 2012 20:52:17 -0400 Subject: [PATCH 3/5] Add no-op method to base class. Fixes #2839 --- lib/Cake/Model/Datasource/DataSource.php | 8 ++++++++ 1 file changed, 8 insertions(+) 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. * From 73b0345ff4c2fc55339a19b204131daf27069b2e Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 3 May 2012 20:35:01 -0400 Subject: [PATCH 4/5] Fix issue with non-sequential array keys. Xml::fromArray() should not cause errors with non-sequential numeric array keys. Fixes #2580 --- lib/Cake/Test/Case/Utility/XmlTest.php | 37 ++++++++++++++++++++++++++ lib/Cake/Utility/Xml.php | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/XmlTest.php b/lib/Cake/Test/Case/Utility/XmlTest.php index d1bf8d1b2..7eb68f823 100644 --- a/lib/Cake/Test/Case/Utility/XmlTest.php +++ b/lib/Cake/Test/Case/Utility/XmlTest.php @@ -322,6 +322,43 @@ class XmlTest extends CakeTestCase { $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText); } +/** + * 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()); + } + /** * data provider for fromArray() failures * diff --git a/lib/Cake/Utility/Xml.php b/lib/Cake/Utility/Xml.php index 70044471e..6b96f7f61 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; From 4ab6d37abb7f52637e2afd68f3344ad0cd72d436 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 3 May 2012 21:00:52 -0400 Subject: [PATCH 5/5] Update assertions. Use assertXmlStringEqualsXmlString() it gives better error reporting. Also update string concat into heredocs. --- lib/Cake/Test/Case/Utility/XmlTest.php | 239 +++++++++++++++++-------- 1 file changed, 168 insertions(+), 71 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/XmlTest.php b/lib/Cake/Test/Case/Utility/XmlTest.php index 7eb68f823..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,7 @@ 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()); } /** @@ -514,9 +551,11 @@ XML; $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( @@ -529,11 +568,13 @@ XML; ); $this->assertEquals($expected, Xml::toArray($obj)); - $xml = ''; - $xml .= '
ApplesBananas
'; - $xml .= 'CakePHPMIT
'; - $xml .= 'The book is on the table.
'; - $xml .= '
'; + $xml = << +
ApplesBananas
+ CakePHPMIT
+ The book is on the table.
+ +XML; $obj = Xml::build($xml); $expected = array( @@ -547,10 +588,12 @@ XML; ); $this->assertEquals($expected, Xml::toArray($obj)); - $xml = ''; - $xml .= 'defect'; - $xml .= '1'; - $xml .= ''; + $xml = << +defect +1 + +XML; $obj = Xml::build($xml); $expected = array( @@ -614,18 +657,27 @@ XML; ) ); $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()); } /** @@ -667,7 +719,27 @@ XML; ); $this->assertSame(Xml::toArray($xml), $expected); - $xmlText = '1testing'; + $xmlText = << + + + + + + + + 1 + + + testing + + + + + + + +XML; $xml = Xml::build($xmlText); $expected = array( 'methodResponse' => array( @@ -690,7 +762,7 @@ XML; $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()); } /** @@ -738,12 +810,15 @@ XML; ) ); $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()); } /** @@ -752,7 +827,16 @@ XML; * @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( @@ -812,9 +896,17 @@ XML; ) ) ); - $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( @@ -825,7 +917,7 @@ XML; ); $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( @@ -834,7 +926,7 @@ XML; ); $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( @@ -843,7 +935,7 @@ XML; ); $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()); } /** @@ -893,34 +985,38 @@ XML; $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()); } /** @@ -938,4 +1034,5 @@ XML; $result = $obj->asXml(); $this->assertContains('mark & mark', $result); } + }