Permalink
Browse files

Merge branch 'master' into 2.3

Conflicts:
	lib/Cake/Test/Case/View/MediaViewTest.php
  • Loading branch information...
2 parents b18550c + 9ce7004 commit 60f9626838142d637ee6097a1857f478b6eb5f76 @markstory markstory committed Nov 2, 2012
@@ -20,6 +20,8 @@
*/
App::uses('AppController', 'Controller');
+App::uses('AppController', 'Controller');
+
/**
* Error Handling Controller
*
View
@@ -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']);
@@ -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();
@@ -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();
@@ -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)) {
@@ -385,6 +385,21 @@ protected function _setRuntimeData(Model $Model) {
}
/**
+ * 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
*
* @param Model $Model Model the callback is called on
@@ -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) {
@@ -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);
@@ -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);
}
@@ -620,6 +620,24 @@ public function testRequestActionParamParseAndPass() {
}
/**
+ * 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.
*
@@ -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(
@@ -19,7 +19,6 @@
App::uses('ExceptionRenderer', 'Error');
App::uses('Controller', 'Controller');
-App::uses('AppController', 'Controller');
App::uses('Component', 'Controller');
App::uses('Router', 'Routing');
@@ -531,6 +531,38 @@ public function testSaveCreate() {
}
/**
+ * 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.
*
* @return void
@@ -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,
@@ -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,
@@ -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);
@@ -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");
@@ -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()));
@@ -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);
@@ -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)');
Oops, something went wrong.

0 comments on commit 60f9626

Please sign in to comment.