Skip to content

Commit

Permalink
Merge branch 'master' into 2.3
Browse files Browse the repository at this point in the history
Conflicts:
	lib/Cake/Test/Case/View/MediaViewTest.php
  • Loading branch information
markstory committed Nov 2, 2012
2 parents b18550c + 9ce7004 commit 60f9626
Show file tree
Hide file tree
Showing 20 changed files with 289 additions and 64 deletions.
2 changes: 2 additions & 0 deletions lib/Cake/Controller/CakeErrorController.php
Expand Up @@ -20,6 +20,8 @@
*/
App::uses('AppController', 'Controller');

App::uses('AppController', 'Controller');

/**
* Error Handling Controller
*
Expand Down
9 changes: 7 additions & 2 deletions lib/Cake/Core/Object.php
Expand Up @@ -73,9 +73,13 @@ public function requestAction($url, $extra = array()) {
$extra['autoRender'] = 1;
unset($extra[$index]);
}
if (is_array($url) && !isset($extra['url'])) {
$arrayUrl = is_array($url);
if ($arrayUrl && !isset($extra['url'])) {
$extra['url'] = array();
}
if ($arrayUrl && !isset($extra['data'])) {
$extra['data'] = array();
}
$extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
$data = isset($extra['data']) ? $extra['data'] : null;
unset($extra['data']);
Expand All @@ -88,11 +92,12 @@ public function requestAction($url, $extra = array()) {
} elseif (is_array($url)) {
$params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
$params = array_merge($params, $extra);
$request = new CakeRequest(Router::reverse($params), false);
$request = new CakeRequest(Router::reverse($params));
}
if (isset($data)) {
$request->data = $data;
}

$dispatcher = new Dispatcher();
$result = $dispatcher->dispatch($request, new CakeResponse(), $extra);
Router::popRequest();
Expand Down
5 changes: 2 additions & 3 deletions lib/Cake/Error/ExceptionRenderer.php
Expand Up @@ -138,6 +138,7 @@ public function __construct(Exception $exception) {
* @return Controller
*/
protected function _getController($exception) {
App::uses('AppController', 'Controller');
App::uses('CakeErrorController', 'Controller');
if (!$request = Router::getRequest(true)) {
$request = new CakeRequest();
Expand All @@ -149,9 +150,7 @@ protected function _getController($exception) {
}

try {
if (class_exists('AppController')) {
$controller = new CakeErrorController($request, $response);
}
$controller = new CakeErrorController($request, $response);
} catch (Exception $e) {
}
if (empty($controller)) {
Expand Down
15 changes: 15 additions & 0 deletions lib/Cake/Model/Behavior/TranslateBehavior.php
Expand Up @@ -384,6 +384,21 @@ protected function _setRuntimeData(Model $Model) {
$this->runtime[$Model->alias]['beforeSave'] = $tempData;
}

/**
* Restores model data to the original data.
* This solves issues with saveAssociated and validate = first.
*
* @param Model $model
* @return void
*/
public function afterValidate(Model $Model) {
$Model->data[$Model->alias] = array_merge(
$Model->data[$Model->alias],
$this->runtime[$Model->alias]['beforeSave']
);
return true;
}

/**
* afterSave Callback
*
Expand Down
16 changes: 8 additions & 8 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -2489,16 +2489,16 @@ public function conditionKeysToString($conditions, $quoteValues = true, $model =
$count = count($value);
if ($count === 1 && !preg_match("/\s+NOT$/", $key)) {
$data = $this->_quoteFields($key) . ' = (';
} else {
$data = $this->_quoteFields($key) . ' IN (';
}
if ($quoteValues) {
if (is_object($model)) {
$columnType = $model->getColumnType($key);
if ($quoteValues) {
if (is_object($model)) {
$columnType = $model->getColumnType($key);
}
$data .= implode(', ', $this->value($value, $columnType));
}
$data .= implode(', ', $this->value($value, $columnType));
$data .= ')';
} else {
$data = $this->_parseKey($model, $key, $value);
}
$data .= ')';
} else {
$ret = $this->conditionKeysToString($value, $quoteValues, $model);
if (count($ret) > 1) {
Expand Down
11 changes: 6 additions & 5 deletions lib/Cake/Network/CakeRequest.php
Expand Up @@ -162,11 +162,12 @@ public function __construct($url = null, $parseEnvironment = true) {
protected function _processPost() {
if ($_POST) {
$this->data = $_POST;
} elseif ($this->is('put') || $this->is('delete')) {
$this->data = $this->_readInput();
if (strpos(env('CONTENT_TYPE'), 'application/x-www-form-urlencoded') === 0) {
parse_str($this->data, $this->data);
}
} elseif (
($this->is('put') || $this->is('delete')) &&
strpos(env('CONTENT_TYPE'), 'application/x-www-form-urlencoded') === 0
) {
$data = $this->_readInput();
parse_str($data, $this->data);
}
if (ini_get('magic_quotes_gpc') === '1') {
$this->data = stripslashes_deep($this->data);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Network/Http/HttpSocket.php
Expand Up @@ -403,7 +403,7 @@ public function request($request = array()) {
}

if ($this->request['redirect'] && $this->response->isRedirect()) {
$request['uri'] = $this->response->getHeader('Location');
$request['uri'] = trim(urldecode($this->response->getHeader('Location')), '=');
$request['redirect'] = is_int($this->request['redirect']) ? $this->request['redirect'] - 1 : $this->request['redirect'];
$this->response = $this->request($request);
}
Expand Down
19 changes: 18 additions & 1 deletion lib/Cake/Test/Case/Core/ObjectTest.php
Expand Up @@ -619,6 +619,24 @@ public function testRequestActionParamParseAndPass() {
$this->assertEquals($expected, $result['named']);
}

/**
* Test that requestAction handles get parameters correctly.
*
* @return void
*/
public function testRequestActionGetParameters() {
$result = $this->object->requestAction(
'/request_action/params_pass?get=value&limit=5'
);
$this->assertEquals('value', $result->query['get']);

$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'params_pass'),
array('url' => array('get' => 'value', 'limit' => 5))
);
$this->assertEquals('value', $result->query['get']);
}

/**
* test that requestAction does not fish data out of the POST
* superglobal.
Expand All @@ -632,7 +650,6 @@ public function testRequestActionNoPostPassing() {
'item' => 'value'
));
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
$expected = null;
$this->assertEmpty($result);

$result = $this->object->requestAction(
Expand Down
1 change: 0 additions & 1 deletion lib/Cake/Test/Case/Error/ExceptionRendererTest.php
Expand Up @@ -19,7 +19,6 @@

App::uses('ExceptionRenderer', 'Error');
App::uses('Controller', 'Controller');
App::uses('AppController', 'Controller');
App::uses('Component', 'Controller');
App::uses('Router', 'Routing');

Expand Down
32 changes: 32 additions & 0 deletions lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php
Expand Up @@ -530,6 +530,38 @@ public function testSaveCreate() {
$this->assertEquals($expected, $result);
}

/**
* testSaveAssociatedCreate method
*
* @return void
*/
public function testSaveAssociatedMultipleLocale() {
$this->loadFixtures('Translate', 'TranslatedItem');

$TestModel = new TranslatedItem();
$data = array(
'slug' => 'fourth_translated',
'title' => array(
'eng' => 'Title #4',
'spa' => 'Leyenda #4',
),
'content' => array(
'eng' => 'Content #4',
'spa' => 'Contenido #4',
),
'translated_article_id' => 1,
);
$TestModel->create();
$TestModel->saveAssociated($data);

$translations = array('title' => 'Title', 'content' => 'Content');
$TestModel->bindTranslation($translations, false);
$TestModel->locale = array('eng', 'spa');
$result = $TestModel->read();
$this->assertCount(2, $result['Title']);
$this->assertCount(2, $result['Content']);
}

/**
* Test that saving only some of the translated fields allows the record to be found again.
*
Expand Down
67 changes: 43 additions & 24 deletions lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php
Expand Up @@ -169,20 +169,22 @@ public function testMoveDownWithScope() {
public function testTranslatingTree() {
$this->Tree = new FlagTree();
$this->Tree->cacheQueries = false;
$this->Tree->Behaviors->attach('Translate', array('name'));
$this->Tree->Behaviors->attach('Translate', array('title'));

//Save
$this->Tree->locale = 'eng';
$data = array('FlagTree' => array(
'name' => 'name #1',
'title' => 'name #1',
'name' => 'test',
'locale' => 'eng',
'parent_id' => null,
));
$this->Tree->save($data);
$result = $this->Tree->find('all');
$expected = array(array('FlagTree' => array(
'id' => 1,
'name' => 'name #1',
'title' => 'name #1',
'name' => 'test',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
Expand All @@ -191,15 +193,16 @@ public function testTranslatingTree() {
)));
$this->assertEquals($expected, $result);

//update existing record, same locale
// update existing record, same locale
$this->Tree->create();
$data['FlagTree']['name'] = 'Named 2';
$data['FlagTree']['title'] = 'Named 2';
$this->Tree->id = 1;
$this->Tree->save($data);
$result = $this->Tree->find('all');
$expected = array(array('FlagTree' => array(
'id' => 1,
'name' => 'Named 2',
'title' => 'Named 2',
'name' => 'test',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
Expand All @@ -208,51 +211,67 @@ public function testTranslatingTree() {
)));
$this->assertEquals($expected, $result);

//update different locale, same record
// update different locale, same record
$this->Tree->create();
$this->Tree->locale = 'deu';
$this->Tree->id = 1;
$data = array('FlagTree' => array(
'id' => 1,
'parent_id' => null,
'name' => 'namen #1',
'title' => 'namen #1',
'name' => 'test',
'locale' => 'deu',
));
$this->Tree->save($data);

$this->Tree->locale = 'deu';
$result = $this->Tree->find('all');
$expected = array(array('FlagTree' => array(
'id' => 1,
'name' => 'namen #1',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
'flag' => 0,
'locale' => 'deu',
)));
$expected = array(
array(
'FlagTree' => array(
'id' => 1,
'title' => 'namen #1',
'name' => 'test',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
'flag' => 0,
'locale' => 'deu',
)
)
);
$this->assertEquals($expected, $result);

//Save with bindTranslation
// Save with bindTranslation
$this->Tree->locale = 'eng';
$data = array(
'name' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'),
'title' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'),
'name' => 'test',
'parent_id' => null
);
$this->Tree->create($data);
$this->Tree->save();

$this->Tree->unbindTranslation();
$translations = array('name' => 'Name');
$translations = array('title' => 'Title');
$this->Tree->bindTranslation($translations, false);
$this->Tree->locale = array('eng', 'spa');

$result = $this->Tree->read();
$expected = array(
'FlagTree' => array('id' => 2, 'parent_id' => null, 'locale' => 'eng', 'name' => 'New title', 'flag' => 0, 'lft' => 3, 'rght' => 4),
'Name' => array(
array('id' => 21, 'locale' => 'eng', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'name', 'content' => 'New title'),
array('id' => 22, 'locale' => 'spa', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'name', 'content' => 'Nuevo leyenda')
'FlagTree' => array(
'id' => 2,
'parent_id' => null,
'locale' => 'eng',
'name' => 'test',
'title' => 'New title',
'flag' => 0,
'lft' => 3,
'rght' => 4
),
'Title' => array(
array('id' => 21, 'locale' => 'eng', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'title', 'content' => 'New title'),
array('id' => 22, 'locale' => 'spa', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Nuevo leyenda')
),
);
$this->assertEquals($expected, $result);
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -2009,7 +2009,7 @@ public function testStringConditionsParsing() {
$this->assertEquals($expected, $result);

$result = $this->Dbo->conditions(array('score' => array(2 => 1, 2, 10)));
$expected = " WHERE score IN (1, 2, 10)";
$expected = " WHERE `score` IN (1, 2, 10)";
$this->assertEquals($expected, $result);

$result = $this->Dbo->conditions("Aro.rght = Aro.lft + 1.1");
Expand Down Expand Up @@ -2289,7 +2289,7 @@ public function testArrayConditionsParsing() {
$this->assertEquals($expected, $result);

$result = $this->Dbo->conditions(array('score' => array(1, 2, 10)));
$expected = " WHERE score IN (1, 2, 10)";
$expected = " WHERE `score` IN (1, 2, 10)";
$this->assertEquals($expected, $result);

$result = $this->Dbo->conditions(array('score' => array()));
Expand Down Expand Up @@ -2380,7 +2380,7 @@ public function testArrayConditionsParsing() {
'NOT' => array('Course.id' => null, 'Course.vet' => 'N', 'level_of_education_id' => array(912,999)),
'Enrollment.yearcompleted >' => '0')
);
$this->assertRegExp('/^\s*WHERE\s+\(NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(level_of_education_id IN \(912, 999\)\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+\'0\'\s*$/', $result);
$this->assertRegExp('/^\s*WHERE\s+\(NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(`level_of_education_id` IN \(912, 999\)\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+\'0\'\s*$/', $result);

$result = $this->Dbo->conditions(array('id <>' => '8'));
$this->assertRegExp('/^\s*WHERE\s+`id`\s+<>\s+\'8\'\s*$/', $result);
Expand Down Expand Up @@ -2416,7 +2416,7 @@ public function testArrayConditionsParsing() {

$conditions = array('id' => array(2, 5, 6, 9, 12, 45, 78, 43, 76));
$result = $this->Dbo->conditions($conditions);
$expected = " WHERE id IN (2, 5, 6, 9, 12, 45, 78, 43, 76)";
$expected = " WHERE `id` IN (2, 5, 6, 9, 12, 45, 78, 43, 76)";
$this->assertEquals($expected, $result);

$conditions = array('title' => 'user(s)');
Expand Down

0 comments on commit 60f9626

Please sign in to comment.