From 4a483b489756bfe3aff5658ba8454b6d38ce12f8 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 11 Aug 2012 03:31:46 +0530 Subject: [PATCH 1/9] If cache is disabled in app and js cache file is not written don't return script tag with file url. Instead return script block with inline js content. --- lib/Cake/Test/Case/View/Helper/JsHelperTest.php | 9 ++++++++- lib/Cake/View/Helper/JsHelper.php | 17 +++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/JsHelperTest.php b/lib/Cake/Test/Case/View/Helper/JsHelperTest.php index 8589850a8..4b173d81d 100644 --- a/lib/Cake/Test/Case/View/Helper/JsHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/JsHelperTest.php @@ -351,6 +351,7 @@ class JsHelperTest extends CakeTestCase { public function testWriteScriptsInFile() { $this->skipIf(!is_writable(JS), 'webroot/js is not Writable, script caching test has been skipped.'); + Configure::write('Cache.disable', false); $this->Js->request->webroot = '/'; $this->Js->JsBaseEngine = new TestJsEngineHelper($this->View); $this->Js->buffer('one = 1;'); @@ -364,8 +365,14 @@ class JsHelperTest extends CakeTestCase { $this->assertTrue(file_exists(WWW_ROOT . $filename[1])); $contents = file_get_contents(WWW_ROOT . $filename[1]); $this->assertRegExp('/one\s=\s1;\ntwo\s=\s2;/', $contents); - @unlink(WWW_ROOT . $filename[1]); + + Configure::write('Cache.disable', true); + $this->Js->buffer('one = 1;'); + $this->Js->buffer('two = 2;'); + $result = $this->Js->writeBuffer(array('onDomReady' => false, 'cache' => true)); + $this->assertRegExp('/one\s=\s1;\ntwo\s=\s2;/', $result); + $this->assertFalse(file_exists(WWW_ROOT . $filename[1])); } /** diff --git a/lib/Cake/View/Helper/JsHelper.php b/lib/Cake/View/Helper/JsHelper.php index 5490fbb36..93343dde1 100644 --- a/lib/Cake/View/Helper/JsHelper.php +++ b/lib/Cake/View/Helper/JsHelper.php @@ -208,18 +208,19 @@ class JsHelper extends AppHelper { $opts = $options; unset($opts['onDomReady'], $opts['cache'], $opts['clear']); - if (!$options['cache'] && $options['inline']) { - return $this->Html->scriptBlock($script, $opts); - } - if ($options['cache'] && $options['inline']) { $filename = md5($script); - if (!file_exists(JS . $filename . '.js')) { - cache(str_replace(WWW_ROOT, '', JS) . $filename . '.js', $script, '+999 days', 'public'); + if (file_exists(JS . $filename . '.js') + || cache(str_replace(WWW_ROOT, '', JS) . $filename . '.js', $script, '+999 days', 'public') + ) { + return $this->Html->script($filename); } - return $this->Html->script($filename); } - $this->Html->scriptBlock($script, $opts); + + $return = $this->Html->scriptBlock($script, $opts); + if ($options['inline']) { + return $return; + } return null; } From 802f00b6e3bcecfc9b77baf5ab8b1f3d6b29dedc Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 12 Aug 2012 02:13:10 +0530 Subject: [PATCH 2/9] Adding missing calls to parent. --- lib/Cake/Test/Case/I18n/I18nTest.php | 2 ++ lib/Cake/Test/Case/View/Helper/JsHelperTest.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/Cake/Test/Case/I18n/I18nTest.php b/lib/Cake/Test/Case/I18n/I18nTest.php index e86628bb4..bdc17f27a 100644 --- a/lib/Cake/Test/Case/I18n/I18nTest.php +++ b/lib/Cake/Test/Case/I18n/I18nTest.php @@ -31,6 +31,8 @@ class I18nTest extends CakeTestCase { * @return void */ public function setUp() { + parent::setUp(); + Cache::delete('object_map', '_cake_core_'); App::build(array( 'Locale' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS), diff --git a/lib/Cake/Test/Case/View/Helper/JsHelperTest.php b/lib/Cake/Test/Case/View/Helper/JsHelperTest.php index 4b173d81d..12ee9072b 100644 --- a/lib/Cake/Test/Case/View/Helper/JsHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/JsHelperTest.php @@ -123,6 +123,8 @@ class JsHelperTest extends CakeTestCase { * @return void */ public function setUp() { + parent::setUp(); + $this->_asset = Configure::read('Asset.timestamp'); Configure::write('Asset.timestamp', false); From 65e63c51c8f02f511239eee9b80f7d6760b561ac Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 12 Aug 2012 02:28:12 +0530 Subject: [PATCH 3/9] More missing parent calls. --- lib/Cake/Test/Case/I18n/I18nTest.php | 2 ++ lib/Cake/Test/Case/View/Helper/JsHelperTest.php | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/I18n/I18nTest.php b/lib/Cake/Test/Case/I18n/I18nTest.php index bdc17f27a..637494012 100644 --- a/lib/Cake/Test/Case/I18n/I18nTest.php +++ b/lib/Cake/Test/Case/I18n/I18nTest.php @@ -47,6 +47,8 @@ class I18nTest extends CakeTestCase { * @return void */ public function tearDown() { + parent::tearDown(); + Cache::delete('object_map', '_cake_core_'); App::build(); CakePlugin::unload(); diff --git a/lib/Cake/Test/Case/View/Helper/JsHelperTest.php b/lib/Cake/Test/Case/View/Helper/JsHelperTest.php index 12ee9072b..950e5c221 100644 --- a/lib/Cake/Test/Case/View/Helper/JsHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/JsHelperTest.php @@ -125,7 +125,6 @@ class JsHelperTest extends CakeTestCase { public function setUp() { parent::setUp(); - $this->_asset = Configure::read('Asset.timestamp'); Configure::write('Asset.timestamp', false); $controller = null; @@ -148,7 +147,7 @@ class JsHelperTest extends CakeTestCase { * @return void */ public function tearDown() { - Configure::write('Asset.timestamp', $this->_asset); + parent::tearDown(); unset($this->Js); } From e183e91b178995564c56c2379fa02b331c223705 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 14 Aug 2012 12:40:33 -0400 Subject: [PATCH 4/9] Make CakeRequest work with content-type headers that include a charset. Refs #3113 --- lib/Cake/Network/CakeRequest.php | 2 +- lib/Cake/Test/Case/Network/CakeRequestTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index cadbbbd0c..1ac08cf8f 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -165,7 +165,7 @@ class CakeRequest implements ArrayAccess { $this->data = $_POST; } elseif ($this->is('put') || $this->is('delete')) { $this->data = $this->_readInput(); - if (env('CONTENT_TYPE') === 'application/x-www-form-urlencoded') { + if (strpos(env('CONTENT_TYPE'), 'application/x-www-form-urlencoded') === 0) { parse_str($this->data, $this->data); } } diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 8ef0e1868..86f6f6039 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -233,7 +233,7 @@ class CakeRequestTest extends CakeTestCase { */ public function testPutParsing() { $_SERVER['REQUEST_METHOD'] = 'PUT'; - $_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; + $_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=UTF-8'; $data = array('data' => array( 'Article' => array('title') From cdc70fc4270fe97a4761b03daba552cd92911cc1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 14 Aug 2012 12:43:24 -0400 Subject: [PATCH 5/9] Make RequestHandlerComponent better simulate GET requests. Modify the global state to simulate a GET request. This avoids issues where PUT data would be processed during simulated redirect. Fixes #3113 --- lib/Cake/Controller/Component/RequestHandlerComponent.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Cake/Controller/Component/RequestHandlerComponent.php b/lib/Cake/Controller/Component/RequestHandlerComponent.php index 544e01cd1..d731c2885 100644 --- a/lib/Cake/Controller/Component/RequestHandlerComponent.php +++ b/lib/Cake/Controller/Component/RequestHandlerComponent.php @@ -217,6 +217,7 @@ class RequestHandlerComponent extends Component { /** * Handles (fakes) redirects for Ajax requests using requestAction() + * Modifies the $_POST and $_SERVER['REQUEST_METHOD'] to simulate a new GET request. * * @param Controller $controller A reference to the controller * @param string|array $url A string or array containing the redirect location @@ -228,6 +229,7 @@ class RequestHandlerComponent extends Component { if (!$this->request->is('ajax')) { return; } + $_SERVER['REQUEST_METHOD'] = 'GET'; foreach ($_POST as $key => $val) { unset($_POST[$key]); } From 18c5a4aee56a995f1f569ae4590990726789072c Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 15 Aug 2012 19:38:58 +0530 Subject: [PATCH 6/9] Make file extension optional for Configure reader adapter's dump function. --- lib/Cake/Configure/IniReader.php | 5 +++++ lib/Cake/Configure/PhpReader.php | 5 +++++ lib/Cake/Test/Case/Configure/IniReaderTest.php | 7 +++++++ lib/Cake/Test/Case/Configure/PhpReaderTest.php | 7 +++++++ 4 files changed, 24 insertions(+) diff --git a/lib/Cake/Configure/IniReader.php b/lib/Cake/Configure/IniReader.php index debd685c6..f8fe2077f 100644 --- a/lib/Cake/Configure/IniReader.php +++ b/lib/Cake/Configure/IniReader.php @@ -142,6 +142,7 @@ class IniReader implements ConfigReaderInterface { * Dumps the state of Configure data into an ini formatted string. * * @param string $filename The filename on $this->_path to save into. + * Extension ".ini" will be automatically appended if not included in filename. * @param array $data The data to convert to ini file. * @return int Bytes saved. */ @@ -159,6 +160,10 @@ class IniReader implements ConfigReaderInterface { } } $contents = join("\n", $result); + + if (substr($filename, -4) !== '.ini') { + $filename .= '.ini'; + } return file_put_contents($this->_path . $filename, $contents); } diff --git a/lib/Cake/Configure/PhpReader.php b/lib/Cake/Configure/PhpReader.php index f5d961961..32d1f5264 100644 --- a/lib/Cake/Configure/PhpReader.php +++ b/lib/Cake/Configure/PhpReader.php @@ -92,11 +92,16 @@ class PhpReader implements ConfigReaderInterface { * be used saved into a file and loaded later. * * @param string $filename The filename to create on $this->_path. + * Extension ".php" will be automatically appended if not included in filename. * @param array $data Data to dump. * @return int Bytes saved. */ public function dump($filename, $data) { $contents = '_path . $filename, $contents); } diff --git a/lib/Cake/Test/Case/Configure/IniReaderTest.php b/lib/Cake/Test/Case/Configure/IniReaderTest.php index e4b463450..dd1f087b4 100644 --- a/lib/Cake/Test/Case/Configure/IniReaderTest.php +++ b/lib/Cake/Test/Case/Configure/IniReaderTest.php @@ -166,6 +166,13 @@ INI; unlink($file); $this->assertTextEquals($expected, $result); + + $result = $reader->dump('test', $this->testData); + $this->assertTrue($result > 0); + + $contents = file_get_contents($file); + $this->assertTextEquals($expected, $contents); + unlink($file); } /** diff --git a/lib/Cake/Test/Case/Configure/PhpReaderTest.php b/lib/Cake/Test/Case/Configure/PhpReaderTest.php index 08982cb4e..59d4d5178 100644 --- a/lib/Cake/Test/Case/Configure/PhpReaderTest.php +++ b/lib/Cake/Test/Case/Configure/PhpReaderTest.php @@ -151,6 +151,13 @@ PHP; unlink($file); $this->assertTextEquals($expected, $contents); + + $result = $reader->dump('test', $this->testData); + $this->assertTrue($result > 0); + + $contents = file_get_contents($file); + $this->assertTextEquals($expected, $contents); + unlink($file); } /** From 3f1c8318001013e1cb2455983e51ff117c428dd7 Mon Sep 17 00:00:00 2001 From: Andras Kende Date: Wed, 15 Aug 2012 14:24:15 -0700 Subject: [PATCH 7/9] update to use fetch --- app/View/Layouts/Emails/html/default.ctp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/View/Layouts/Emails/html/default.ctp b/app/View/Layouts/Emails/html/default.ctp index 4d360d908..e574a9ba1 100644 --- a/app/View/Layouts/Emails/html/default.ctp +++ b/app/View/Layouts/Emails/html/default.ctp @@ -22,7 +22,7 @@ <?php echo $title_for_layout;?> - + fetch('content');?>

This email was sent using the CakePHP Framework

From 8511a6a17803eb470b166d84f0e886196dfb3711 Mon Sep 17 00:00:00 2001 From: Andras Kende Date: Wed, 15 Aug 2012 14:24:38 -0700 Subject: [PATCH 8/9] update to use fetch --- app/View/Layouts/Emails/text/default.ctp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/View/Layouts/Emails/text/default.ctp b/app/View/Layouts/Emails/text/default.ctp index 94ed22249..c2a683a7c 100644 --- a/app/View/Layouts/Emails/text/default.ctp +++ b/app/View/Layouts/Emails/text/default.ctp @@ -16,6 +16,6 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> - +fetch('content');?> This email was sent using the CakePHP Framework, http://cakephp.org. From 73f29069de3561d2b497a3564ca089ceec16a88d Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 15 Aug 2012 20:50:11 -0400 Subject: [PATCH 9/9] Fix issue where omitting a base class would break test generation. Fixes #3115 --- lib/Cake/Console/Command/Task/TestTask.php | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/Cake/Console/Command/Task/TestTask.php b/lib/Cake/Console/Command/Task/TestTask.php index b49296ee1..edee2d21b 100644 --- a/lib/Cake/Console/Command/Task/TestTask.php +++ b/lib/Cake/Console/Command/Task/TestTask.php @@ -54,6 +54,21 @@ class TestTask extends BakeTask { 'Helper' => 'View/Helper' ); +/** + * Mapping between packages, and their baseclass + package. + * This is used to generate App::uses() call to autoload base + * classes if a developer has forgotten to do so. + * + * @var array + */ + public $baseTypes = array( + 'Model' => array('Model', 'Model'), + 'Behavior' => array('ModelBehavior', 'Model'), + 'Controller' => array('Controller', 'Controller'), + 'Component' => array('Component', 'Controller'), + 'Helper' => array('Helper', 'View') + ); + /** * Internal list of fixtures that have been added so far. * @@ -132,6 +147,8 @@ class TestTask extends BakeTask { } elseif ($this->interactive) { $this->getUserFixtures(); } + list($baseClass, $baseType) = $this->getBaseType($type); + App::uses($baseClass, $baseType); App::uses($fullClassName, $realType); $methods = array(); @@ -311,6 +328,20 @@ class TestTask extends BakeTask { return $real; } +/** + * Get the base class and package name for a given type. + * + * @param string $package The package the class having a test + * generated for is in. + * @return array Array of class, type) + */ + public function getBaseType($type) { + if (empty($this->baseTypes[$type])) { + throw new CakeException(__d('cake_dev', 'Invalid package name')); + } + return $this->baseTypes[$type]; + } + /** * Get methods declared in the class given. * No parent methods will be returned