mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge branch '1.3' of git://github.com/cakephp/cakephp into 1.3
This commit is contained in:
commit
72f4ce8dd9
6 changed files with 85 additions and 64 deletions
|
@ -382,7 +382,8 @@ class AuthComponent extends Object {
|
|||
$controller->data[$model->alias][$this->fields['password']] = null;
|
||||
return false;
|
||||
} else {
|
||||
if (!$this->user()) {
|
||||
$user = $this->user();
|
||||
if (!$user) {
|
||||
if (!$this->RequestHandler->isAjax()) {
|
||||
$this->Session->setFlash($this->authError, $this->flashElement, array(), 'auth');
|
||||
if (!empty($controller->params['url']) && count($controller->params['url']) >= 2) {
|
||||
|
@ -442,7 +443,7 @@ class AuthComponent extends Object {
|
|||
break;
|
||||
}
|
||||
|
||||
if ($this->isAuthorized($type)) {
|
||||
if ($this->isAuthorized($type, null, $user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -218,12 +218,21 @@ class DboMysqlBase extends DboSource {
|
|||
if (empty($conditions)) {
|
||||
$alias = $joins = false;
|
||||
}
|
||||
$conditions = $this->conditions($this->defaultConditions($model, $conditions, $alias), true, true, $model);
|
||||
$complexConditions = false;
|
||||
foreach ((array)$conditions as $key => $value) {
|
||||
if (strpos($key, $model->alias) === false) {
|
||||
$complexConditions = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$complexConditions) {
|
||||
$joins = false;
|
||||
}
|
||||
|
||||
$conditions = $this->conditions($this->defaultConditions($model, $conditions, $alias), true, true, $model);
|
||||
if ($conditions === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->execute($this->renderStatement('delete', compact('alias', 'table', 'joins', 'conditions'))) === false) {
|
||||
$model->onError();
|
||||
return false;
|
||||
|
|
|
@ -2439,7 +2439,7 @@ class DboSource extends DataSource {
|
|||
}
|
||||
|
||||
if (strpos($key, '.')) {
|
||||
$key = preg_replace_callback('/([a-zA-Z0-9_]{1,})\\.([a-zA-Z0-9_]{1,})/', array(&$this, '__quoteMatchedField'), $key);
|
||||
$key = preg_replace_callback('/([a-zA-Z0-9_-]{1,})\\.([a-zA-Z0-9_-]{1,})/', array(&$this, '__quoteMatchedField'), $key);
|
||||
}
|
||||
if (!preg_match('/\s/', $key) && !strpos($key, '.')) {
|
||||
$key = $this->name($key);
|
||||
|
|
|
@ -18,58 +18,10 @@
|
|||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', array('Model', 'DataSource', 'DboSource', 'DboMysql'));
|
||||
App::import('Core', array('AppModel', 'Model'));
|
||||
require_once dirname(dirname(dirname(__FILE__))) . DS . 'models.php';
|
||||
|
||||
Mock::generatePartial('DboMysql', 'QueryMockDboMysql', array('query'));
|
||||
|
||||
/**
|
||||
* DboMysqlTestDb class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model.datasources
|
||||
*/
|
||||
class DboMysqlTestDb extends DboMysql {
|
||||
|
||||
/**
|
||||
* simulated property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $simulated = array();
|
||||
|
||||
/**
|
||||
* testing property
|
||||
*
|
||||
* @var bool true
|
||||
* @access public
|
||||
*/
|
||||
var $testing = true;
|
||||
|
||||
/**
|
||||
* execute method
|
||||
*
|
||||
* @param mixed $sql
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
function _execute($sql) {
|
||||
if ($this->testing) {
|
||||
$this->simulated[] = $sql;
|
||||
return null;
|
||||
}
|
||||
return parent::_execute($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* getLastQuery method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function getLastQuery() {
|
||||
return $this->simulated[count($this->simulated) - 1];
|
||||
}
|
||||
}
|
||||
Mock::generatePartial('DboMysql', 'QueryMockDboMysql', array('query', 'execute'));
|
||||
|
||||
/**
|
||||
* MysqlTestModel class
|
||||
|
@ -160,7 +112,7 @@ class MysqlTestModel extends Model {
|
|||
* @subpackage cake.tests.cases.libs.model.datasources.dbo
|
||||
*/
|
||||
class DboMysqlTest extends CakeTestCase {
|
||||
var $fixtures = array('core.binary_test');
|
||||
var $fixtures = array('core.binary_test', 'core.post', 'core.author');
|
||||
/**
|
||||
* The Dbo instance to be tested
|
||||
*
|
||||
|
@ -583,7 +535,7 @@ class DboMysqlTest extends CakeTestCase {
|
|||
*/
|
||||
function testAlterSchemaIndexes() {
|
||||
App::import('Model', 'CakeSchema');
|
||||
$this->db->cacheSources = $this->db->testing = false;
|
||||
$this->db->cacheSources = false;
|
||||
|
||||
$schema1 =& new CakeSchema(array(
|
||||
'name' => 'AlterTest1',
|
||||
|
@ -673,7 +625,7 @@ class DboMysqlTest extends CakeTestCase {
|
|||
*/
|
||||
function testAlteringTableParameters() {
|
||||
App::import('Model', 'CakeSchema');
|
||||
$this->db->cacheSources = $this->db->testing = false;
|
||||
$this->db->cacheSources = false;
|
||||
|
||||
$schema1 =& new CakeSchema(array(
|
||||
'name' => 'AlterTest1',
|
||||
|
@ -757,7 +709,7 @@ class DboMysqlTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testReadTableParameters() {
|
||||
$this->db->cacheSources = $this->db->testing = false;
|
||||
$this->db->cacheSources = false;
|
||||
$this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;');
|
||||
$result = $this->db->readTableParameters('tinyint');
|
||||
$expected = array(
|
||||
|
@ -784,7 +736,7 @@ class DboMysqlTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testBuildTableParameters() {
|
||||
$this->db->cacheSources = $this->db->testing = false;
|
||||
$this->db->cacheSources = false;
|
||||
$data = array(
|
||||
'charset' => 'utf8',
|
||||
'collate' => 'utf8_unicode_ci',
|
||||
|
@ -804,7 +756,7 @@ class DboMysqlTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGetCharsetName() {
|
||||
$this->db->cacheSources = $this->db->testing = false;
|
||||
$this->db->cacheSources = false;
|
||||
$result = $this->db->getCharsetName('utf8_unicode_ci');
|
||||
$this->assertEqual($result, 'utf8');
|
||||
$result = $this->db->getCharsetName('cp1250_general_ci');
|
||||
|
@ -863,4 +815,47 @@ class DboMysqlTest extends CakeTestCase {
|
|||
$this->db->execute($this->db->dropSchema($schema));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that simple delete conditions don't create joins using a mock.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSimpleDeleteConditionsNoJoins() {
|
||||
$model =& new Post();
|
||||
$mockDbo =& new QueryMockDboMysql($this);
|
||||
$mockDbo->expectAt(0, 'execute', array(new PatternExpectation('/AS\s+`Post`\s+WHERE\s+`Post/')));
|
||||
$mockDbo->setReturnValue('execute', true);
|
||||
|
||||
$mockDbo->delete($model, array('Post.id' => 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* test deleting with joins, a MySQL specific feature.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteWithJoins() {
|
||||
$model =& new Post();
|
||||
$mockDbo =& new QueryMockDboMysql($this);
|
||||
$mockDbo->expectAt(0, 'execute', array(new PatternExpectation('/LEFT JOIN `authors`/')));
|
||||
$mockDbo->setReturnValue('execute', true);
|
||||
|
||||
$mockDbo->delete($model, array('Author.id' => 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* test joins on delete with multiple conditions.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteWithJoinsAndMultipleConditions() {
|
||||
$model =& new Post();
|
||||
$mockDbo =& new QueryMockDboMysql($this);
|
||||
$mockDbo->expectAt(0, 'execute', array(new PatternExpectation('/LEFT JOIN `authors`/')));
|
||||
$mockDbo->expectAt(1, 'execute', array(new PatternExpectation('/LEFT JOIN `authors`/')));
|
||||
$mockDbo->setReturnValue('execute', true);
|
||||
|
||||
$mockDbo->delete($model, array('Author.id' => 1, 'Post.id' => 2));
|
||||
$mockDbo->delete($model, array('Post.id' => 2, 'Author.id' => 1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3512,6 +3512,10 @@ class DboSourceTest extends CakeTestCase {
|
|||
$result = $this->testDb->order(array('Property.sale_price IS NULL'));
|
||||
$expected = ' ORDER BY `Property`.`sale_price` IS NULL ASC';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->testDb->order(array('Export.column-name' => 'ASC'));
|
||||
$expected = ' ORDER BY `Export`.`column-name` ASC';
|
||||
$this->assertEqual($result, $expected, 'Columns with -s are not working with order()');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3890,6 +3890,18 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$this->assertEqual($resultsFkFalse, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test updateAll with empty values.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testUpdateAllEmptyValues() {
|
||||
$this->loadFixtures('Author', 'Post');
|
||||
$model = new Author();
|
||||
$result = $model->updateAll(array('user' => '""'));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testProductUpdateAllWithForeignKey
|
||||
*
|
||||
|
@ -3897,7 +3909,7 @@ class ModelWriteTest extends BaseModelTest {
|
|||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testProductUpdateAll() {
|
||||
function testUpdateAllWithJoins() {
|
||||
$this->skipIf(
|
||||
$this->db->config['driver'] == 'postgres',
|
||||
'%s Currently, there is no way of doing joins in an update statement in postgresql'
|
||||
|
@ -3948,7 +3960,7 @@ class ModelWriteTest extends BaseModelTest {
|
|||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testProductUpdateAllWithoutForeignKey() {
|
||||
function testUpdateAllWithoutForeignKey() {
|
||||
$this->skipIf(
|
||||
$this->db->config['driver'] == 'postgres',
|
||||
'%s Currently, there is no way of doing joins in an update statement in postgresql'
|
||||
|
|
Loading…
Reference in a new issue