Merge branch 'master' into 2.3

This commit is contained in:
mark_story 2012-08-15 21:00:49 -04:00
commit c83e941497
13 changed files with 85 additions and 15 deletions

View file

@ -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>

View file

@ -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.

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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

View file

@ -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]);
}

View file

@ -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);
}
}

View file

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

View file

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

View file

@ -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();

View file

@ -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')

View file

@ -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]));
}
/**

View file

@ -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);
}
$this->Html->scriptBlock($script, $opts);
}
$return = $this->Html->scriptBlock($script, $opts);
if ($options['inline']) {
return $return;
}
return null;
}