Browse Source

Merge branch 'master' into 2.3

mark_story 13 years ago
parent
commit
c83e941497

+ 1 - 1
app/View/Layouts/Emails/html/default.ctp

@@ -22,7 +22,7 @@
 	<title><?php echo $title_for_layout;?></title>
 </head>
 <body>
-	<?php echo $content_for_layout;?>
+	<?php echo $this->fetch('content');?>
 
 	<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
 </body>

+ 1 - 1
app/View/Layouts/Emails/text/default.ctp

@@ -16,6 +16,6 @@
  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
  */
 ?>
-<?php echo $content_for_layout;?>
+<?php echo $this->fetch('content');?>
 
 This email was sent using the CakePHP Framework, http://cakephp.org.

+ 5 - 0
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);
 	}
 

+ 5 - 0
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 = '<?php' . "\n" . '$config = ' . var_export($data, true) . ';';
+
+		if (substr($filename, -4) !== '.php') {
+			$filename .= '.php';
+		}
 		return file_put_contents($this->_path . $filename, $contents);
 	}
 

+ 31 - 0
lib/Cake/Console/Command/Task/TestTask.php

@@ -55,6 +55,21 @@ class TestTask extends BakeTask {
 	);
 
 /**
+ * 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.
  *
  * @var array
@@ -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();
@@ -312,6 +329,20 @@ class TestTask extends BakeTask {
 	}
 
 /**
+ * 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
  *

+ 2 - 0
lib/Cake/Controller/Component/RequestHandlerComponent.php

@@ -232,6 +232,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
@@ -243,6 +244,7 @@ class RequestHandlerComponent extends Component {
 		if (!$this->request->is('ajax')) {
 			return;
 		}
+		$_SERVER['REQUEST_METHOD'] = 'GET';
 		foreach ($_POST as $key => $val) {
 			unset($_POST[$key]);
 		}

+ 1 - 1
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);
 			}
 		}

+ 7 - 0
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);
 	}
 
 /**

+ 7 - 0
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);
 	}
 
 /**

+ 4 - 0
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),
@@ -45,6 +47,8 @@ class I18nTest extends CakeTestCase {
  * @return void
  */
 	public function tearDown() {
+		parent::tearDown();
+
 		Cache::delete('object_map', '_cake_core_');
 		App::build();
 		CakePlugin::unload();

+ 1 - 1
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')

+ 11 - 3
lib/Cake/Test/Case/View/Helper/JsHelperTest.php

@@ -123,7 +123,8 @@ class JsHelperTest extends CakeTestCase {
  * @return void
  */
 	public function setUp() {
-		$this->_asset = Configure::read('Asset.timestamp');
+		parent::setUp();
+
 		Configure::write('Asset.timestamp', false);
 
 		$controller = null;
@@ -146,7 +147,7 @@ class JsHelperTest extends CakeTestCase {
  * @return void
  */
 	public function tearDown() {
-		Configure::write('Asset.timestamp', $this->_asset);
+		parent::tearDown();
 		unset($this->Js);
 	}
 
@@ -351,6 +352,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 +366,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]));
 	}
 
 /**

+ 9 - 8
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;
 	}