Merge branch '2.1' into 2.2

This commit is contained in:
Ceeram 2012-06-02 01:47:21 +02:00
commit 4c6453501e
11 changed files with 185 additions and 20 deletions

View file

@ -267,6 +267,12 @@ class ExceptionRenderer {
$this->controller->render($template);
$this->controller->afterFilter();
$this->controller->response->send();
} catch (MissingViewException $e) {
try {
$this->_outputMessage('error500');
} catch (Exception $e) {
$this->_outputMessageSafe('error500');
}
} catch (Exception $e) {
$this->controller->set(array(
'error' => $e,

View file

@ -53,9 +53,8 @@ class DboSource extends DataSource {
/**
* Caches result from query parsing operations. Cached results for both DboSource::name() and
* DboSource::conditions() will be stored here. Method caching uses `crc32()` which is
* fast but can collisions more easily than other hashing algorithms. If you have problems
* with collisions, set DboSource::$cacheMethods to false.
* DboSource::conditions() will be stored here. Method caching uses `md5()`. If you have
* problems with collisions, set DboSource::$cacheMethods to false.
*
* @var array
*/
@ -791,7 +790,7 @@ class DboSource extends DataSource {
* Strips fields out of SQL functions before quoting.
*
* Results of this method are stored in a memory cache. This improves performance, but
* because the method uses a simple hashing algorithm it can infrequently have collisions.
* because the method uses a hashing algorithm it can have collisions.
* Setting DboSource::$cacheMethods to false will disable the memory cache.
*
* @param mixed $data Either a string with a column to quote. An array of columns to quote or an
@ -811,7 +810,7 @@ class DboSource extends DataSource {
}
return $data;
}
$cacheKey = crc32($this->startQuote . $data . $this->endQuote);
$cacheKey = md5($this->startQuote . $data . $this->endQuote);
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
return $return;
}
@ -2284,7 +2283,8 @@ class DboSource extends DataSource {
$model->alias,
$virtualFields,
$fields,
$quote
$quote,
ConnectionManager::getSourceName($this)
);
$cacheKey = md5(serialize($cacheKey));
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
@ -2384,7 +2384,7 @@ class DboSource extends DataSource {
* is given it will be integer cast as condition. Null will return 1 = 1.
*
* Results of this method are stored in a memory cache. This improves performance, but
* because the method uses a simple hashing algorithm it can infrequently have collisions.
* because the method uses a hashing algorithm it can have collisions.
* Setting DboSource::$cacheMethods to false will disable the memory cache.
*
* @param mixed $conditions Array or string of conditions, or any value.

View file

@ -1175,7 +1175,7 @@ class Model extends Object implements CakeEventListener {
*/
protected function _setAliasData($data) {
$models = array_keys($this->getAssociated());
$schema = array_keys($this->schema());
$schema = array_keys((array)$this->schema());
foreach ($data as $field => $value) {
if (in_array($field, $schema) || !in_array($field, $models)) {
$data[$this->alias][$field] = $value;

View file

@ -690,7 +690,8 @@ class BasicsTest extends CakeTestCase {
'this-is-a-test'
###########################
EXPECTED;
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result);
ob_start();
@ -704,7 +705,7 @@ EXPECTED;
</pre>
</div>
EXPECTED;
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result);
ob_start();
@ -718,7 +719,7 @@ EXPECTED;
</pre>
</div>
EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result);
ob_start();
@ -732,7 +733,7 @@ EXPECTED;
</pre>
</div>
EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result);
ob_start();
@ -753,9 +754,9 @@ EXPECTED;
###########################
EXPECTED;
if (php_sapi_name() == 'cli') {
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17);
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
} else {
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19);
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
}
$this->assertEquals($expected, $result);
@ -777,9 +778,9 @@ EXPECTED;
###########################
EXPECTED;
if (php_sapi_name() == 'cli') {
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17);
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
} else {
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19);
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
}
$this->assertEquals($expected, $result);
@ -792,7 +793,7 @@ EXPECTED;
'<div>this-is-a-test</div>'
###########################
EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result);
ob_start();
@ -804,7 +805,7 @@ EXPECTED;
'<div>this-is-a-test</div>'
###########################
EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result);
ob_start();
@ -816,7 +817,7 @@ EXPECTED;
'<div>this-is-a-test</div>'
###########################
EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result);
}

View file

@ -277,6 +277,49 @@ class ExceptionRendererTest extends CakeTestCase {
$this->assertEquals($exception, $ExceptionRenderer->error);
}
/**
* test that helpers in custom CakeErrorController are not lost
*/
public function testCakeErrorHelpersNotLost() {
$testApp = CAKE . 'Test' . DS . 'test_app' . DS;
App::build(array(
'Controller' => array(
$testApp . 'Controller' . DS
),
'View/Helper' => array(
$testApp . 'View' . DS . 'Helper' . DS
),
'View/Layouts' => array(
$testApp . 'View' . DS . 'Layouts' . DS
),
'Error' => array(
$testApp . 'Error' . DS
),
), App::RESET);
Configure::write('Error', array(
'handler' => 'TestAppsErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
Configure::write('Exception', array(
'handler' => 'TestAppsErrorHandler::handleException',
'renderer' => 'TestAppsExceptionRenderer',
'log' => true
));
App::uses('TestAppsErrorController', 'Controller');
App::uses('TestAppsExceptionRenderer', 'Error');
$exception = new SocketException('socket exception');
$renderer = new TestAppsExceptionRenderer($exception);
ob_start();
$renderer->render();
$result = ob_get_clean();
$this->assertContains('<b>peeled</b>', $result);
}
/**
* test that unknown exception types with valid status codes are treated correctly.
*

View file

@ -59,6 +59,30 @@ class DboTestSource extends DboSource {
}
class DboSecondTestSource extends DboSource {
public $startQuote = '_';
public $endQuote = '_';
public function connect($config = array()) {
$this->connected = true;
}
public function mergeAssociation(&$data, &$merge, $association, $type, $selfJoin = false) {
return parent::_mergeAssociation($data, $merge, $association, $type, $selfJoin);
}
public function setConfig($config = array()) {
$this->config = $config;
}
public function setConnection($conn) {
$this->_connection = $conn;
}
}
/**
* DboSourceTest class
*
@ -605,6 +629,21 @@ class DboSourceTest extends CakeTestCase {
$this->assertNull($result);
}
/**
* Test that rare collisions do not happen with method caching
*
* @return void
*/
public function testNameMethodCacheCollisions() {
$this->testDb->cacheMethods = true;
$this->testDb->flushMethodCache();
$this->testDb->name('Model.fieldlbqndkezcoapfgirmjsh');
$result = $this->testDb->name('Model.fieldkhdfjmelarbqnzsogcpi');
$expected = '`Model`.`fieldkhdfjmelarbqnzsogcpi`';
$this->assertEquals($expected, $result);
}
/**
* testLog method
*
@ -837,6 +876,37 @@ class DboSourceTest extends CakeTestCase {
$this->assertTrue(empty(DboTestSource::$methodCache['fields']), 'Cache not empty');
}
/**
* test that fields() method cache detects datasource changes
*
* @return void
*/
public function testFieldsCacheKeyWithDatasourceChange() {
ConnectionManager::create('firstschema', array(
'datasource' => 'DboTestSource'
));
ConnectionManager::create('secondschema', array(
'datasource' => 'DboSecondTestSource'
));
Cache::delete('method_cache', '_cake_core_');
DboTestSource::$methodCache = array();
$Article = ClassRegistry::init('Article');
$Article->setDataSource('firstschema');
$ds = $Article->getDataSource();
$ds->cacheMethods = true;
$first = $ds->fields($Article, null, array('title', 'body', 'published'));
$Article->setDataSource('secondschema');
$ds = $Article->getDataSource();
$ds->cacheMethods = true;
$second = $ds->fields($Article, null, array('title', 'body', 'published'));
$this->assertNotEquals($first, $second);
$this->assertEquals(2, count(DboTestSource::$methodCache['fields']));
}
/**
* Test that group works without a model
*

View file

@ -0,0 +1,14 @@
<?php
App::uses('CakeErrorController', 'Controller');
class TestAppsErrorController extends CakeErrorController {
public $helpers = array(
'Html',
'Session',
'Form',
'Banana',
);
}

View file

@ -0,0 +1,21 @@
<?php
class TestAppsExceptionRenderer extends ExceptionRenderer {
protected function _getController($exception) {
App::uses('TestAppsErrorController', 'Controller');
if (!$request = Router::getRequest(true)) {
$request = new CakeRequest();
}
$response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
try {
$controller = new TestAppsErrorController($request, $response);
$controller->layout = 'banana';
} catch (Exception $e) {
$controller = new Controller($request, $response);
$controller->viewPath = 'Errors';
}
return $controller;
}
}

View file

@ -19,4 +19,9 @@
App::uses('Helper', 'View');
class BananaHelper extends Helper {
public function peel() {
return '<b>peeled</b>';
}
}

View file

@ -0,0 +1,5 @@
<body>
<?php
echo $this->Banana->peel();
?>
</body>

View file

@ -77,7 +77,7 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
$lineInfo = '';
if ($showFrom) {
$trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
$file = substr($trace[0]['file'], strlen(ROOT));
$file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
$line = $trace[0]['line'];
}
$html = <<<HTML