Permalink
Browse files

Merge branch 'master' into 2.3

Conflicts:
	lib/Cake/Event/CakeEventManager.php
	lib/Cake/VERSION.txt
	lib/Cake/View/ViewBlock.php
  • Loading branch information...
2 parents 41ae19b + f6c5ceb commit 1aea9ac0c958a65f6c4fbb5c3bcfa0894a22b7c3 @markstory markstory committed Oct 16, 2012
@@ -98,11 +98,11 @@
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
'engine' => 'FileLog',
- 'scopes' => array('notice', 'info', 'debug'),
+ 'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
- 'scopes' => array('warning', 'error', 'critical', 'alert', 'emergency'),
+ 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));
@@ -179,7 +179,7 @@ public function beforeSave(Model $Model) {
extract($this->settings[$Model->alias]);
$this->_addToWhitelist($Model, array($left, $right));
- if (!$Model->id) {
+ if (!$Model->id || !$Model->exists()) {
if (array_key_exists($parent, $Model->data[$Model->alias]) && $Model->data[$Model->alias][$parent]) {
$parentNode = $Model->find('first', array(
'conditions' => array($scope, $Model->escapeField() => $Model->data[$Model->alias][$parent]),
@@ -921,14 +921,14 @@ public function logQuery($sql, $params = array()) {
$this->_queriesCnt++;
$this->_queriesTime += $this->took;
$this->_queriesLog[] = array(
- 'query' => $sql,
- 'params' => $params,
- 'affected' => $this->affected,
- 'numRows' => $this->numRows,
- 'took' => $this->took
+ 'query' => $sql,
+ 'params' => $params,
+ 'affected' => $this->affected,
+ 'numRows' => $this->numRows,
+ 'took' => $this->took
);
if (count($this->_queriesLog) > $this->_queriesLogMax) {
- array_pop($this->_queriesLog);
+ array_shift($this->_queriesLog);
}
}
View
@@ -1093,7 +1093,7 @@ protected function _generateAssociation($type, $assocKey) {
}
/**
- * Sets a custom table for your controller class. Used by your controller to select a database table.
+ * Sets a custom table for your model class. Used by your controller to select a database table.
*
* @param string $tableName Name of the custom table
* @throws MissingTableException when database table $tableName is not found on data source
@@ -2760,8 +2760,8 @@ protected function _findCount($state, $query, $results = array()) {
} elseif ($state === 'after') {
foreach (array(0, $this->alias) as $key) {
if (isset($results[0][$key]['count'])) {
- if (($count = count($results)) > 1) {
- return $count;
+ if ($query['group']) {
+ return count($results);
} else {
return intval($results[0][$key]['count']);
}
@@ -280,7 +280,7 @@ protected function _processValidationResponse($name, $rule) {
$message = __d($this->_validationDomain, $name);
}
} else {
- $message = __d('cake_dev', 'This field cannot be left blank');
+ $message = __d('cake', 'This field cannot be left blank');
}
return $message;
@@ -229,8 +229,10 @@ protected function _processGet() {
protected function _url() {
if (!empty($_SERVER['PATH_INFO'])) {
return $_SERVER['PATH_INFO'];
- } elseif (isset($_SERVER['REQUEST_URI'])) {
+ } elseif (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '://') === false) {
$uri = $_SERVER['REQUEST_URI'];
+ } elseif (isset($_SERVER['REQUEST_URI'])) {
+ $uri = substr($_SERVER['REQUEST_URI'], strlen(FULL_BASE_URL));
} elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) {
$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
} elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
@@ -319,7 +321,7 @@ protected function _base() {
protected function _processFiles() {
if (isset($_FILES) && is_array($_FILES)) {
foreach ($_FILES as $name => $data) {
- if ($name != 'data') {
+ if ($name !== 'data') {
$this->params['form'][$name] = $data;
}
}
@@ -651,7 +651,7 @@ public static function getRequest($current = false) {
* @return array Parameter information
*/
public static function getParams($current = false) {
- if ($current) {
+ if ($current && self::$_requests) {
return self::$_requests[count(self::$_requests) - 1]->params;
}
if (isset(self::$_requests[0])) {
@@ -234,18 +234,23 @@ public function testDispatchWithKeyName() {
* @return void
*/
public function testDispatchReturnValue() {
+ $this->skipIf(
+ version_compare(PHPUnit_Runner_Version::VERSION, '3.7', '<'),
+ 'These tests fail in PHPUnit 3.6'
+ );
$manager = new CakeEventManager;
$listener = $this->getMock('CakeEventTestListener');
$anotherListener = $this->getMock('CakeEventTestListener');
$manager->attach(array($listener, 'listenerFunction'), 'fake.event');
$manager->attach(array($anotherListener, 'listenerFunction'), 'fake.event');
$event = new CakeEvent('fake.event');
- $firstStep = clone $event;
$listener->expects($this->at(0))->method('listenerFunction')
- ->with($firstStep)
+ ->with($event)
->will($this->returnValue('something special'));
- $anotherListener->expects($this->at(0))->method('listenerFunction')->with($event);
+ $anotherListener->expects($this->at(0))
+ ->method('listenerFunction')
+ ->with($event);
$manager->dispatch($event);
$this->assertEquals('something special', $event->result);
}
@@ -256,18 +261,23 @@ public function testDispatchReturnValue() {
* @return void
*/
public function testDispatchFalseStopsEvent() {
+ $this->skipIf(
+ version_compare(PHPUnit_Runner_Version::id(), '3.7', '<'),
+ 'These tests fail in PHPUnit 3.6'
+ );
+
$manager = new CakeEventManager;
$listener = $this->getMock('CakeEventTestListener');
$anotherListener = $this->getMock('CakeEventTestListener');
$manager->attach(array($listener, 'listenerFunction'), 'fake.event');
$manager->attach(array($anotherListener, 'listenerFunction'), 'fake.event');
$event = new CakeEvent('fake.event');
- $originalEvent = clone $event;
$listener->expects($this->at(0))->method('listenerFunction')
- ->with($originalEvent)
+ ->with($event)
->will($this->returnValue(false));
- $anotherListener->expects($this->never())->method('listenerFunction');
+ $anotherListener->expects($this->never())
+ ->method('listenerFunction');
$manager->dispatch($event);
$this->assertTrue($event->isStopped());
}
@@ -355,8 +355,6 @@ public function testAddMiddle() {
$this->assertSame($expected, $result);
$laterCount = $this->Tree->find('count');
-
- $laterCount = $this->Tree->find('count');
$this->assertEquals($initialCount + 1, $laterCount);
$children = $this->Tree->children($data[$modelClass]['id'], true, array('name'));
@@ -370,6 +368,36 @@ public function testAddMiddle() {
}
/**
+ * testAddWithPreSpecifiedId method
+ *
+ * @return void
+ */
+ public function testAddWithPreSpecifiedId() {
+ extract($this->settings);
+ $this->Tree = new $modelClass();
+ $this->Tree->initialize(2, 2);
+
+ $data = $this->Tree->find('first', array(
+ 'fields' => array('id'),
+ 'conditions' => array($modelClass . '.name' => '1.1')
+ ));
+
+ $this->Tree->create();
+ $result = $this->Tree->save(array($modelClass => array(
+ 'id' => 100,
+ 'name' => 'testAddMiddle',
+ $parentField => $data[$modelClass]['id'])
+ ));
+ $expected = array_merge(
+ array($modelClass => array('id' => 100, 'name' => 'testAddMiddle', $parentField => '2')),
+ $result
+ );
+ $this->assertSame($expected, $result);
+
+ $this->assertTrue($this->Tree->verify());
+ }
+
+/**
* testAddInvalid method
*
* @return void
@@ -21,6 +21,7 @@
App::uses('Model', 'Model');
App::uses('AppModel', 'Model');
+App::uses('String', 'Utility');
require_once dirname(dirname(__FILE__)) . DS . 'models.php';
/**
@@ -57,6 +58,37 @@ class TreeBehaviorUuidTest extends CakeTestCase {
public $fixtures = array('core.uuid_tree');
/**
+ * testAddWithPreSpecifiedId method
+ *
+ * @return void
+ */
+ public function testAddWithPreSpecifiedId() {
+ extract($this->settings);
+ $this->Tree = new $modelClass();
+ $this->Tree->initialize(2, 2);
+
+ $data = $this->Tree->find('first', array(
+ 'fields' => array('id'),
+ 'conditions' => array($modelClass . '.name' => '1.1')
+ ));
+
+ $id = String::uuid();
+ $this->Tree->create();
+ $result = $this->Tree->save(array($modelClass => array(
+ 'id' => $id,
+ 'name' => 'testAddMiddle',
+ $parentField => $data[$modelClass]['id'])
+ ));
+ $expected = array_merge(
+ array($modelClass => array('id' => $id, 'name' => 'testAddMiddle', $parentField => '2')),
+ $result
+ );
+ $this->assertSame($expected, $result);
+
+ $this->assertTrue($this->Tree->verify());
+ }
+
+/**
* testMovePromote method
*
* @return void
@@ -6860,6 +6860,17 @@ public function testFindCount() {
));
$result = $Article->find('count', array('group' => array('Article.user_id')));
$this->assertEquals($expected, $result);
+
+ $expected = count($Article->find('all', array(
+ 'fields' => array('Article.user_id'),
+ 'conditions' => array('Article.user_id' => 1),
+ 'group' => 'Article.user_id')
+ ));
+ $result = $Article->find('count', array(
+ 'conditions' => array('Article.user_id' => 1),
+ 'group' => array('Article.user_id'),
+ ));
+ $this->assertEquals($expected, $result);
}
/**
@@ -6886,7 +6897,7 @@ public function testFindCountDistinct() {
$this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.');
$this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');
- $this->loadFixtures('Project');
+ $this->loadFixtures('Project', 'Thread');
$TestModel = new Project();
$TestModel->create(array('name' => 'project')) && $TestModel->save();
$TestModel->create(array('name' => 'project')) && $TestModel->save();
@@ -588,6 +588,24 @@ public function testFilesParsing() {
}
/**
+ * Test that files in the 0th index work.
+ */
+ public function testFilesZeroithIndex() {
+ $_FILES = array(
+ 0 => array(
+ 'name' => 'cake_sqlserver_patch.patch',
+ 'type' => 'text/plain',
+ 'tmp_name' => '/private/var/tmp/phpy05Ywj',
+ 'error' => 0,
+ 'size' => 6271,
+ ),
+ );
+
+ $request = new CakeRequest('some/path');
+ $this->assertEquals($_FILES, $request->params['form']);
+ }
+
+/**
* test method overrides coming in from POST data.
*
* @return void
@@ -1629,6 +1647,30 @@ public static function environmentGenerator() {
),
),
array(
+ 'Apache - w/rewrite, document root set above top level cake dir, request root, absolute REQUEST_URI',
+ array(
+ 'App' => array(
+ 'base' => false,
+ 'baseUrl' => false,
+ 'dir' => 'app',
+ 'webroot' => 'webroot'
+ ),
+ 'SERVER' => array(
+ 'SERVER_NAME' => 'localhost',
+ 'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
+ 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
+ 'REQUEST_URI' => FULL_BASE_URL . '/site/posts/index',
+ 'SCRIPT_NAME' => '/site/app/webroot/index.php',
+ 'PHP_SELF' => '/site/app/webroot/index.php',
+ ),
+ ),
+ array(
+ 'url' => 'posts/index',
+ 'base' => '/site',
+ 'webroot' => '/site/',
+ ),
+ ),
+ array(
'Nginx - w/rewrite, document root set to webroot, request root, no PATH_INFO',
array(
'App' => array(
Oops, something went wrong.

0 comments on commit 1aea9ac

Please sign in to comment.