Merge branch 'master' into 2.4

Conflicts:
	lib/Cake/Console/Command/ConsoleShell.php
This commit is contained in:
ADmad 2013-08-04 19:26:55 +05:30
commit 38b050a711
52 changed files with 407 additions and 122 deletions

View file

@ -79,8 +79,7 @@ if (!defined('WWW_ROOT')) {
// for built-in server
if (php_sapi_name() == 'cli-server') {
$uri = str_replace($_SERVER['SCRIPT_FILENAME'], WWW_ROOT, '');
if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $uri)) {
if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $_SERVER['PHP_SELF'])) {
return false;
}
$_SERVER['PHP_SELF'] = '/' . basename(__FILE__);

View file

@ -223,40 +223,67 @@ class FileEngine extends CacheEngine {
if (!$this->_init) {
return false;
}
$dir = dir($this->settings['path']);
$threshold = $now = false;
if ($check) {
$now = time();
$threshold = $now - $this->settings['duration'];
}
$this->_clearDirectory($this->settings['path'], $now, $threshold);
$directory = new RecursiveDirectoryIterator($this->settings['path']);
$contents = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
foreach ($contents as $path) {
if ($path->isFile()) {
continue;
}
$this->_clearDirectory($path->getRealPath() . DS, $now, $threshold);
}
return true;
}
/**
* Used to clear a directory of matching files.
*
* @param string $path The path to search.
* @param integer $now The current timestamp
* @param integer $threshold Any file not modified after this value will be deleted.
* @return void
*/
protected function _clearDirectory($path, $now, $threshold) {
$prefixLength = strlen($this->settings['prefix']);
if (!is_dir($path)) {
return;
}
$dir = dir($path);
while (($entry = $dir->read()) !== false) {
if (substr($entry, 0, $prefixLength) !== $this->settings['prefix']) {
continue;
}
if ($this->_setKey($entry) === false) {
$filePath = $path . $entry;
if (is_dir($filePath)) {
continue;
}
if ($check) {
$mtime = $this->_File->getMTime();
$file = new SplFileObject($path . $entry, 'r');
if ($threshold) {
$mtime = $file->getMTime();
if ($mtime > $threshold) {
continue;
}
$expires = (int)$this->_File->current();
$expires = (int)$file->current();
if ($expires > $now) {
continue;
}
}
$path = $this->_File->getRealPath();
$this->_File = null;
if (file_exists($path)) {
unlink($path);
if ($file->isFile()) {
unlink($file->getRealPath());
}
}
$dir->close();
return true;
}
/**

View file

@ -56,7 +56,7 @@
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
$this->redirect(array('action' => 'index'));
return $this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.'), array('action' => 'index'));
<?php endif; ?>
@ -99,7 +99,7 @@
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
$this->redirect(array('action' => 'index'));
return $this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
<?php endif; ?>
@ -145,7 +145,7 @@
if ($this-><?php echo $currentModelName; ?>->delete()) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'));
$this->redirect(array('action' => 'index'));
return $this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'), array('action' => 'index'));
<?php endif; ?>
@ -155,5 +155,5 @@
<?php else: ?>
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'), array('action' => 'index'));
<?php endif; ?>
$this->redirect(array('action' => 'index'));
return $this->redirect(array('action' => 'index'));
}

View file

@ -70,8 +70,7 @@ if (!defined('WWW_ROOT')) {
// for built-in server
if (php_sapi_name() === 'cli-server') {
$uri = str_replace($_SERVER['SCRIPT_FILENAME'], WWW_ROOT, '');
if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $uri)) {
if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $_SERVER['PHP_SELF'])) {
return false;
}
$_SERVER['PHP_SELF'] = '/' . basename(__FILE__);

View file

@ -233,7 +233,7 @@ class SecurityComponent extends Component {
);
if ($this->_action == $this->blackHoleCallback) {
return $this->blackhole($controller, 'auth');
return $this->blackHole($controller, 'auth');
}
if (!in_array($this->_action, (array)$this->unlockedActions) && $isPost && $isNotRequestAction) {

View file

@ -54,6 +54,16 @@ class ComponentCollection extends ObjectCollection implements CakeEventListener
}
}
/**
* Set the controller associated with the collection.
*
* @param Controller $Controller Controller to set
* @return void
*/
public function setController(Controller $Controller) {
$this->_Controller = $Controller;
}
/**
* Get the controller associated with the collection.
*

View file

@ -347,7 +347,7 @@ class Controller extends Object implements CakeEventListener {
* Lazy loads models using the loadModel() method if declared in $uses
*
* @param string $name
* @return void
* @return boolean
*/
public function __isset($name) {
switch ($name) {
@ -384,8 +384,8 @@ class Controller extends Object implements CakeEventListener {
* Provides backwards compatibility access to the request object properties.
* Also provides the params alias.
*
* @param string $name
* @return void
* @param string $name The name of the requested value
* @return mixed The requested value for valid variables/aliases else null
*/
public function __get($name) {
switch ($name) {
@ -422,15 +422,19 @@ class Controller extends Object implements CakeEventListener {
case 'here':
case 'webroot':
case 'data':
return $this->request->{$name} = $value;
$this->request->{$name} = $value;
return;
case 'action':
return $this->request->params['action'] = $value;
$this->request->params['action'] = $value;
return;
case 'params':
return $this->request->params = $value;
$this->request->params = $value;
return;
case 'paginate':
return $this->Components->load('Paginator')->settings = $value;
$this->Components->load('Paginator')->settings = $value;
return;
}
return $this->{$name} = $value;
$this->{$name} = $value;
}
/**
@ -714,7 +718,7 @@ class Controller extends Object implements CakeEventListener {
*
* @param string $modelClass Name of model class to load
* @param integer|string $id Initial ID the instanced model class should have
* @return mixed true when single model found and instance created, error returned if model not found.
* @return bool True if the model was found
* @throws MissingModelException if the model class cannot be found.
*/
public function loadModel($modelClass = null, $id = null) {

View file

@ -72,8 +72,8 @@ class Configure {
if (!include APP . 'Config' . DS . 'core.php') {
trigger_error(__d('cake_dev', "Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", APP . 'Config' . DS), E_USER_ERROR);
}
App::$bootstrapping = false;
App::init();
App::$bootstrapping = false;
App::build();
$exception = array(

View file

@ -124,12 +124,14 @@ class I18n {
*
* @param string $singular String to translate
* @param string $plural Plural string (if any)
* @param string $domain Domain The domain of the translation. Domains are often used by plugin translations
* @param string $domain Domain The domain of the translation. Domains are often used by plugin translations.
* If null, the default domain will be used.
* @param string $category Category The integer value of the category to use.
* @param integer $count Count Count is used with $plural to choose the correct plural form.
* @param string $language Language to translate string to.
* If null it checks for language in session followed by Config.language configuration variable.
* @return string translated string.
* @throws CakeException When '' is provided as a domain.
*/
public static function translate($singular, $plural = null, $domain = null, $category = 6, $count = null, $language = null) {
$_this = I18n::getInstance();
@ -162,6 +164,9 @@ class I18n {
if (is_null($domain)) {
$domain = self::$defaultDomain;
}
if ($domain === '') {
throw new CakeException(__d('cake_dev', 'You cannot use "" as a domain.'));
}
$_this->domain = $domain . '_' . $_this->l10n->lang;

View file

@ -1637,9 +1637,10 @@ class Model extends Object implements CakeEventListener {
}
if (!empty($options['fieldList'])) {
$this->whitelist = $options['fieldList'];
if (!empty($options['fieldList'][$this->alias]) && is_array($options['fieldList'][$this->alias])) {
$this->whitelist = $options['fieldList'][$this->alias];
} elseif (Hash::dimensions($options['fieldList']) < 2) {
$this->whitelist = $options['fieldList'];
}
} elseif ($options['fieldList'] === null) {
$this->whitelist = array();
@ -2360,7 +2361,10 @@ class Model extends Object implements CakeEventListener {
$options['fieldList'][$this->alias][] = $key;
return $options;
}
if (!empty($options['fieldList']) && is_array($options['fieldList'])) {
if (!empty($options['fieldList']) &&
is_array($options['fieldList']) &&
Hash::dimensions($options['fieldList']) < 2
) {
$options['fieldList'][] = $key;
}
return $options;

View file

@ -21,6 +21,7 @@
*/
App::uses('CakeValidationSet', 'Model/Validator');
App::uses('Hash', 'Utility');
/**
* ModelValidator object encapsulates all methods related to data validations for a model
@ -394,11 +395,11 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
}
unset($fieldList);
$validateList = array();
if (empty($whitelist)) {
if (empty($whitelist) || Hash::dimensions($whitelist) > 1) {
return $this->_fields;
}
$validateList = array();
$this->validationErrors = array();
foreach ((array)$whitelist as $f) {
if (!empty($this->_fields[$f])) {

View file

@ -378,6 +378,9 @@ class CakeRoute {
* @return array An array with persistent parameters applied.
*/
public function persistParams($url, $params) {
if (empty($this->options['persist']) || !is_array($this->options['persist'])) {
return $url;
}
foreach ($this->options['persist'] as $persistKey) {
if (array_key_exists($persistKey, $params) && !isset($url[$persistKey])) {
$url[$persistKey] = $params[$persistKey];

View file

@ -856,9 +856,7 @@ class Router {
for ($i = 0, $len = count(self::$routes); $i < $len; $i++) {
$originalUrl = $url;
if (isset(self::$routes[$i]->options['persist'], $params)) {
$url = self::$routes[$i]->persistParams($url, $params);
}
if ($match = self::$routes[$i]->match($url)) {
$output = trim($match, '/');

View file

@ -52,7 +52,7 @@ class FileEngineTest extends CakeTestCase {
*/
public function tearDown() {
parent::tearDown();
Cache::clear(false, 'file_test');
// Cache::clear(false, 'file_test');
Cache::drop('file_test');
Cache::drop('file_groups');
Cache::drop('file_groups2');
@ -255,6 +255,41 @@ class FileEngineTest extends CakeTestCase {
$FileTwo->clear(false);
}
/**
* Test that clear() also removes files with group tags.
*
* @return void
*/
public function testClearWithGroups() {
$engine = new FileEngine();
$engine->init(array(
'prefix' => 'cake_test_',
'duration' => DAY,
'groups' => array('short', 'round')
));
$key = 'cake_test_test_key';
$engine->write($key, 'it works', DAY);
$engine->clear(false);
$this->assertFalse($engine->read($key), 'Key should have been removed');
}
/**
* Test that clear() also removes files with group tags.
*
* @return void
*/
public function testClearWithNoKeys() {
$engine = new FileEngine();
$engine->init(array(
'prefix' => 'cake_test_',
'duration' => DAY,
'groups' => array('one', 'two')
));
$key = 'cake_test_test_key';
$engine->clear(false);
$this->assertFalse($engine->read($key), 'No errors should be found');
}
/**
* testKeyPath method
*

View file

@ -34,6 +34,7 @@ class RedisEngineTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
$this->skipIf(!class_exists('Redis'), 'Redis is not installed or configured properly.');
$this->_cacheDisable = Configure::read('Cache.disable');
@ -51,6 +52,7 @@ class RedisEngineTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
Configure::write('Cache.disable', $this->_cacheDisable);
Cache::drop('');
Cache::drop('redis_groups');

View file

@ -72,6 +72,7 @@ class CookieComponentTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
$_COOKIE = array();
$this->Controller = new CookieComponentTestController(new CakeRequest(), new CakeResponse());
$this->Controller->constructClasses();
@ -93,6 +94,7 @@ class CookieComponentTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
$this->Cookie->destroy();
}

View file

@ -320,6 +320,8 @@ class PaginatorComponentTest extends CakeTestCase {
$Controller->request->query = array();
$Controller->constructClasses();
$Controller->PaginatorControllerPost->order = null;
$Controller->Paginator->settings = array(
'order' => array('PaginatorControllerComment.id' => 'ASC')
);

View file

@ -1854,6 +1854,16 @@ class I18nTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* Test that the '' domain causes exceptions.
*
* @expectedException CakeException
* @return void
*/
public function testTranslateEmptyDomain() {
I18n::translate('Plural Rule 1', null, '');
}
/**
* Singular method
*

View file

@ -226,6 +226,7 @@ class AclBehaviorTest extends CakeTestCase {
* @return void
*/
public function testSetup() {
parent::setUp();
$User = new AclUser();
$this->assertTrue(isset($User->Behaviors->Acl->settings['User']));
$this->assertEquals('requester', $User->Behaviors->Acl->settings['User']['type']);

View file

@ -62,6 +62,7 @@ class TreeBehaviorAfterTest extends CakeTestCase {
*/
public function testAftersaveCallback() {
$this->Tree = new AfterTree();
$this->Tree->order = null;
$expected = array('AfterTree' => array('name' => 'Six and One Half Changed in AfterTree::afterSave() but not in database', 'parent_id' => 6, 'lft' => 11, 'rght' => 12));
$result = $this->Tree->save(array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6)));

View file

@ -65,6 +65,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testInitialize() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$result = $this->Tree->find('count');
@ -82,6 +83,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testDetectInvalidLeft() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$result = $this->Tree->findByName('1.1');
@ -108,6 +110,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testDetectInvalidRight() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$result = $this->Tree->findByName('1.1');
@ -134,6 +137,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testDetectInvalidParent() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$result = $this->Tree->findByName('1.1');
@ -159,6 +163,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testDetectNoneExistentParent() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$result = $this->Tree->findByName('1.1');
@ -182,6 +187,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testRecoverUsingParentMode() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->Behaviors->disable('Tree');
$this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0));
@ -233,6 +239,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testRecoverUsingParentModeAndDelete() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->Behaviors->disable('Tree');
$this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0));
@ -301,6 +308,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testRecoverFromMissingParent() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$result = $this->Tree->findByName('1.1');
@ -324,6 +332,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testDetectInvalidParents() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->updateAll(array($parentField => null));
@ -346,6 +355,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testDetectInvalidLftsRghts() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->updateAll(array($leftField => 0, $rightField => 0));
@ -367,6 +377,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testDetectEqualLftsRghts() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(1, 3);
$result = $this->Tree->findByName('1.1');
@ -394,6 +405,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testAddOrphan() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null)));
@ -413,6 +425,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testAddMiddle() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
@ -444,6 +457,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testAddWithPreSpecifiedId() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array(
@ -474,6 +488,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testAddInvalid() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
@ -498,6 +513,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testAddNotIndexedByModel() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->save(array('name' => 'testAddNotIndexed', $parentField => null));
@ -517,6 +533,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMovePromote() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
@ -543,6 +560,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveWithWhitelist() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
@ -570,6 +588,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testInsertWithWhitelist() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->whitelist = array('name', $parentField);
@ -588,6 +607,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveBefore() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
@ -616,6 +636,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveAfter() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
@ -644,6 +665,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveDemoteInvalid() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
@ -676,6 +698,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveInvalid() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
@ -700,6 +723,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveSelfInvalid() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
@ -725,6 +749,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveUpSuccess() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.2')));
@ -746,6 +771,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveUpFail() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.1')));
@ -768,6 +794,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveUp2() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(1, 10);
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
@ -798,6 +825,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveUpFirst() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(1, 10);
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
@ -828,6 +856,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveDownSuccess() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
@ -849,6 +878,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveDownFail() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2')));
@ -870,6 +900,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveDownLast() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(1, 10);
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
@ -900,6 +931,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveDown2() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(1, 10);
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
@ -930,6 +962,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testSaveNoMove() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(1, 10);
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
@ -960,6 +993,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testMoveToRootAndMoveUp() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(1, 1);
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->id = $data[$modelClass]['id'];
@ -984,6 +1018,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testDelete() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$initialCount = $this->Tree->find('count');
@ -1019,6 +1054,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testDeleteDoesNotExist() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->delete(99999);
}
@ -1031,6 +1067,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testRemove() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$initialCount = $this->Tree->find('count');
$result = $this->Tree->findByName('1.1');
@ -1063,6 +1100,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testRemoveLastTopParent() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$initialCount = $this->Tree->find('count');
@ -1096,6 +1134,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testRemoveNoChildren() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$initialCount = $this->Tree->find('count');
@ -1130,6 +1169,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testRemoveAndDelete() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$initialCount = $this->Tree->find('count');
@ -1164,6 +1204,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testRemoveAndDeleteNoChildren() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$initialCount = $this->Tree->find('count');
@ -1196,6 +1237,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testChildren() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
@ -1226,6 +1268,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testCountChildren() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
@ -1251,6 +1294,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testGetParentNode() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2.2')));
@ -1269,6 +1313,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testGetPath() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2.2')));
@ -1289,6 +1334,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testNoAmbiguousColumn() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
$this->Tree->initialize(2, 2);
@ -1321,6 +1367,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testReorderTree() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(3, 3);
$nodes = $this->Tree->find('list', array('order' => $leftField));
@ -1352,6 +1399,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testReorderBigTreeWithQueryCaching() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 10);
$original = $this->Tree->cacheQueries;
@ -1369,6 +1417,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testGenerateTreeListWithSelfJoin() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
$this->Tree->initialize(2, 2);
@ -1386,6 +1435,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testGenerateTreeListFormatting() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$result = $this->Tree->generateTreeList(
@ -1406,6 +1456,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
public function testArraySyntax() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(3, 3);
$this->assertSame($this->Tree->childCount(2), $this->Tree->childCount(array('id' => 2)));
$this->assertSame($this->Tree->getParentNode(2), $this->Tree->getParentNode(array('id' => 2)));

View file

@ -64,6 +64,7 @@ class TreeBehaviorScopedTest extends CakeTestCase {
*/
public function testStringScope() {
$this->Tree = new FlagTree();
$this->Tree->order = null;
$this->Tree->initialize(2, 3);
$this->Tree->id = 1;
@ -100,6 +101,7 @@ class TreeBehaviorScopedTest extends CakeTestCase {
*/
public function testArrayScope() {
$this->Tree = new FlagTree();
$this->Tree->order = null;
$this->Tree->initialize(2, 3);
$this->Tree->id = 1;
@ -136,6 +138,7 @@ class TreeBehaviorScopedTest extends CakeTestCase {
*/
public function testMoveUpWithScope() {
$this->Ad = new Ad();
$this->Ad->order = null;
$this->Ad->Behaviors->attach('Tree', array('scope' => 'Campaign'));
$this->Ad->moveUp(6);
@ -152,6 +155,7 @@ class TreeBehaviorScopedTest extends CakeTestCase {
*/
public function testMoveDownWithScope() {
$this->Ad = new Ad();
$this->Ad->order = null;
$this->Ad->Behaviors->attach('Tree', array('scope' => 'Campaign'));
$this->Ad->moveDown(6);
@ -169,6 +173,7 @@ class TreeBehaviorScopedTest extends CakeTestCase {
*/
public function testTranslatingTree() {
$this->Tree = new FlagTree();
$this->Tree->order = null;
$this->Tree->cacheQueries = false;
$this->Tree->Behaviors->attach('Translate', array('title'));
@ -286,9 +291,11 @@ class TreeBehaviorScopedTest extends CakeTestCase {
public function testAliasesWithScopeInTwoTreeAssociations() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->TreeTwo = new NumberTreeTwo();
$this->TreeTwo->order = null;
$record = $this->Tree->find('first');

View file

@ -66,6 +66,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
public function testAddWithPreSpecifiedId() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array(
@ -97,6 +98,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
public function testMovePromote() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
@ -123,6 +125,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
public function testMoveWithWhitelist() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
@ -150,6 +153,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
public function testRemoveNoChildren() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$initialCount = $this->Tree->find('count');
@ -184,6 +188,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
public function testRemoveAndDeleteNoChildren() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$initialCount = $this->Tree->find('count');
@ -216,6 +221,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
public function testChildren() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
@ -244,6 +250,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
public function testNoAmbiguousColumn() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 2);
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
@ -280,6 +287,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
public function testGenerateTreeListWithSelfJoin() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
$this->Tree->initialize(2, 2);

View file

@ -77,24 +77,6 @@ class MyAppSchema extends CakeSchema {
*/
protected $_foo = array('bar');
/**
* setup method
*
* @param mixed $version
* @return void
*/
public function setup($version) {
}
/**
* teardown method
*
* @param mixed $version
* @return void
*/
public function teardown($version) {
}
/**
* getVar method
*

View file

@ -62,6 +62,7 @@ class MysqlTest extends CakeTestCase {
*
*/
public function setUp() {
parent::setUp();
$this->Dbo = ConnectionManager::getDataSource('test');
if (!($this->Dbo instanceof Mysql)) {
$this->markTestSkipped('The MySQL extension is not available.');
@ -76,6 +77,7 @@ class MysqlTest extends CakeTestCase {
*
*/
public function tearDown() {
parent::tearDown();
unset($this->model);
ClassRegistry::flush();
Configure::write('debug', $this->_debug);
@ -984,7 +986,7 @@ class MysqlTest extends CakeTestCase {
'primary_flag_has_index' => array(
'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
'data' => array('type' => 'integer', 'null' => false),
'indexes' => array (
'indexes' => array(
'some_index' => array('column' => 'data', 'unique' => 1)
),
)

View file

@ -215,6 +215,7 @@ class PostgresTest extends CakeTestCase {
*
*/
public function setUp() {
parent::setUp();
Configure::write('Cache.disable', true);
$this->Dbo = ConnectionManager::getDataSource('test');
$this->skipIf(!($this->Dbo instanceof Postgres));
@ -227,6 +228,7 @@ class PostgresTest extends CakeTestCase {
*
*/
public function tearDown() {
parent::tearDown();
Configure::write('Cache.disable', false);
unset($this->Dbo2);
}

View file

@ -266,6 +266,7 @@ class SqlserverTest extends CakeTestCase {
*
*/
public function setUp() {
parent::setUp();
$this->Dbo = ConnectionManager::getDataSource('test');
if (!($this->Dbo instanceof Sqlserver)) {
$this->markTestSkipped('Please configure the test datasource to use SQL Server.');
@ -280,6 +281,7 @@ class SqlserverTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Dbo);
unset($this->model);
}

View file

@ -570,6 +570,7 @@ class ModelDeleteTest extends BaseModelTest {
'Tag' => array('with' => 'TestPlugin.ArticlesTag')
)), false);
$Article->ArticlesTag->order = null;
$this->assertTrue($Article->delete(1));
}

View file

@ -6302,6 +6302,7 @@ class ModelReadTest extends BaseModelTest {
$this->loadFixtures('User');
$TestModel = new User();
$TestModel->cacheQueries = false;
$TestModel->order = null;
$expected = array(
'conditions' => array(
@ -6849,6 +6850,8 @@ class ModelReadTest extends BaseModelTest {
));
$this->assertEquals('mariano', $result);
$TestModel->order = null;
$result = $TestModel->field('COUNT(*) AS count', true);
$this->assertEquals(4, $result);
@ -6904,7 +6907,9 @@ class ModelReadTest extends BaseModelTest {
$this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']);
$Article = new Article();
$Article->order = null;
$Article->recursive = -1;
$expected = count($Article->find('all', array(
'fields' => array('Article.user_id'),
'group' => 'Article.user_id')
@ -7761,6 +7766,8 @@ class ModelReadTest extends BaseModelTest {
));
$this->assertEquals(2, $result['Post']['id']);
$Post->order = null;
$Post->virtualFields = array('other_field' => 'Post.id + 1');
$result = $Post->find('all', array(
'fields' => array($dbo->calculate($Post, 'max', array('other_field')))

View file

@ -1522,7 +1522,7 @@ class ModelValidationTest extends BaseModelTest {
* @return void
*/
public function testValidateAssociated() {
$this->loadFixtures('Comment', 'Attachment');
$this->loadFixtures('Comment', 'Attachment', 'Article', 'User');
$TestModel = new Comment();
$TestModel->Attachment->validate = array('attachment' => 'notEmpty');
@ -1539,6 +1539,18 @@ class ModelValidationTest extends BaseModelTest {
$result = $TestModel->validateAssociated($data);
$this->assertFalse($result);
$fieldList = array(
'Attachment' => array('comment_id')
);
$result = $TestModel->saveAll($data, array(
'fieldList' => $fieldList, 'validate' => 'only'
));
$this->assertTrue($result);
$this->assertEmpty($TestModel->validationErrors);
$result = $TestModel->validateAssociated($data, array('fieldList' => $fieldList));
$this->assertTrue($result);
$this->assertEmpty($TestModel->validationErrors);
$TestModel->validate = array('comment' => 'notEmpty');
$record = array(
'Comment' => array(

View file

@ -2520,6 +2520,7 @@ class ModelWriteTest extends BaseModelTest {
public function testHabtmSavingWithNoPrimaryKeyUuidJoinTable() {
$this->loadFixtures('UuidTag', 'Fruit', 'FruitsUuidTag');
$Fruit = new Fruit();
$Fruit->FruitsUuidTag->order = null;
$data = array(
'Fruit' => array(
'color' => 'Red',
@ -6557,7 +6558,7 @@ class ModelWriteTest extends BaseModelTest {
'order' => 'Post.id ASC',
));
$expected = array(
'Post' => array (
'Post' => array(
'id' => '4',
'author_id' => '5',
'title' => 'Post without body',
@ -6566,7 +6567,7 @@ class ModelWriteTest extends BaseModelTest {
'created' => self::date(),
'updated' => self::date(),
),
'Author' => array (
'Author' => array(
'id' => '5',
'user' => 'bob',
'password' => null,
@ -6580,6 +6581,66 @@ class ModelWriteTest extends BaseModelTest {
$this->assertEquals('', $result[3]['Post']['body']);
$this->assertEquals('working', $result[3]['Author']['test']);
$fieldList = array(
'Post' => array('title')
);
$data = array(
'Post' => array(
'title' => 'Post without body 2',
'body' => 'This will not be saved'
),
'Author' => array(
'user' => 'jack'
)
);
$TestModel->saveAll($data, array('fieldList' => $fieldList));
$result = $TestModel->find('all', array(
'order' => 'Post.id ASC',
));
$this->assertNull($result[4]['Post']['body']);
$fieldList = array(
'Author' => array('password')
);
$data = array(
'Post' => array(
'id' => '5',
'title' => 'Post title',
'body' => 'Post body'
),
'Author' => array(
'id' => '6',
'user' => 'will not change',
'password' => 'foobar'
)
);
$result = $TestModel->saveAll($data, array('fieldList' => $fieldList));
$this->assertTrue($result);
$result = $TestModel->find('all', array(
'order' => 'Post.id ASC',
));
$expected = array(
'Post' => array(
'id' => '5',
'author_id' => '6',
'title' => 'Post title',
'body' => 'Post body',
'published' => 'N',
'created' => self::date(),
'updated' => self::date()
),
'Author' => array(
'id' => '6',
'user' => 'jack',
'password' => 'foobar',
'created' => self::date(),
'updated' => self::date(),
'test' => 'working'
),
);
$this->assertEquals($expected, $result[4]);
// test multirecord
$this->db->truncate($TestModel);

View file

@ -34,6 +34,7 @@ class DebugTransportTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
$this->DebugTransport = new DebugTransport();
}

View file

@ -34,6 +34,7 @@ class MailTransportTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
$this->MailTransport = $this->getMock('MailTransport', array('_mail'));
$this->MailTransport->config(array('additionalParameters' => '-f'));
}

View file

@ -82,6 +82,7 @@ class SmtpTransportTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
if (!class_exists('MockSocket')) {
$this->getMock('CakeSocket', array('read', 'write', 'connect', 'enableCrypto'), array(), 'MockSocket');
}

View file

@ -73,6 +73,7 @@ class DigestAuthenticationTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
$this->HttpSocket = new DigestHttpSocket();
$this->HttpSocket->request['method'] = 'GET';
$this->HttpSocket->request['uri']['path'] = '/';
@ -84,6 +85,7 @@ class DigestAuthenticationTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->HttpSocket);
}

View file

@ -93,6 +93,7 @@ class HttpResponseTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
$this->HttpResponse = new TestHttpResponse();
}

View file

@ -193,6 +193,7 @@ class HttpSocketTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
if (!class_exists('MockHttpSocket')) {
$this->getMock('TestHttpSocket', array('read', 'write', 'connect'), array(), 'MockHttpSocket');
$this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request'), array(), 'MockHttpSocketRequests');
@ -208,6 +209,7 @@ class HttpSocketTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Socket, $this->RequestSocket);
}

View file

@ -511,6 +511,7 @@ class DispatcherTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
$this->_get = $_GET;
$_GET = array();
$this->_post = $_POST;
@ -538,6 +539,7 @@ class DispatcherTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
$_GET = $this->_get;
$_POST = $this->_post;
$_FILES = $this->_files;

View file

@ -30,6 +30,7 @@ class AssetDispatcherTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
Configure::write('Dispatcher.filters', array());
}

View file

@ -484,6 +484,40 @@ class CakeRouteTest extends CakeTestCase {
$this->assertEquals('red', $result['color']);
}
/**
* test persist with a non array value
*
* @return void
*/
public function testPersistParamsNonArray() {
$url = array('controller' => 'posts', 'action' => 'index');
$params = array('lang' => 'en', 'color' => 'blue');
$route = new CakeRoute(
'/:lang/:color/blog/:action',
array('controller' => 'posts')
// No persist options
);
$result = $route->persistParams($url, $params);
$this->assertEquals($url, $result);
$route = new CakeRoute(
'/:lang/:color/blog/:action',
array('controller' => 'posts'),
array('persist' => false)
);
$result = $route->persistParams($url, $params);
$this->assertEquals($url, $result);
$route = new CakeRoute(
'/:lang/:color/blog/:action',
array('controller' => 'posts'),
array('persist' => 'derp')
);
$result = $route->persistParams($url, $params);
$this->assertEquals($url, $result);
}
/**
* test the parse method of CakeRoute.
*

View file

@ -1078,13 +1078,13 @@ class RouterTest extends CakeTestCase {
Router::connect(
'/:lang/:color/posts/view/*',
array('controller' => 'posts', 'action' => 'view'),
array('persist' => array('lang', 'color')
));
array('persist' => array('lang', 'color'))
);
Router::connect(
'/:lang/:color/posts/index',
array('controller' => 'posts', 'action' => 'index'),
array('persist' => array('lang')
));
array('persist' => array('lang'))
);
Router::connect('/:lang/:color/posts/edit/*', array('controller' => 'posts', 'action' => 'edit'));
Router::connect('/about', array('controller' => 'pages', 'action' => 'view', 'about'));
Router::parse('/en/red/posts/view/5');

View file

@ -189,6 +189,7 @@ class CakeTestFixtureTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
$methods = array_diff(get_class_methods('DboSource'), array('enabled'));
$methods[] = 'connect';
@ -204,6 +205,7 @@ class CakeTestFixtureTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->criticDb);
$this->db->config = $this->_backupConfig;
}

View file

@ -52,6 +52,7 @@ class CakeTimeTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Time);
$this->_restoreSystemTimezone();
}

View file

@ -8054,6 +8054,32 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
}
/**
* Test that required fields are created when only using ModelValidator::add().
*
* @return void
*/
public function testFormInputRequiredDetectionModelValidator() {
ClassRegistry::getObject('ContactTag')->validator()->add('iwillberequired', 'required', array('rule' => 'notEmpty'));
$this->Form->create('ContactTag');
$result = $this->Form->input('ContactTag.iwillberequired');
$expected = array(
'div' => array('class' => 'input text required'),
'label' => array('for' => 'ContactTagIwillberequired'),
'Iwillberequired',
'/label',
'input' => array(
'name' => 'data[ContactTag][iwillberequired]',
'type' => 'text',
'id' => 'ContactTagIwillberequired',
'required' => 'required'
),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testFormMagicInput method
*

View file

@ -79,6 +79,7 @@ class PaginatorHelperTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->View, $this->Paginator);
}

View file

@ -75,24 +75,6 @@ class CakeTestSuiteCommand extends PHPUnit_TextUI_Command {
);
}
if (!count($suite)) {
$skeleton = new PHPUnit_Util_Skeleton_Test(
$suite->getName(),
$this->arguments['testFile']
);
$result = $skeleton->generate(true);
if (!$result['incomplete']) {
//@codingStandardsIgnoreStart
eval(str_replace(array('<?php', '?>'), '', $result['code']));
//@codingStandardsIgnoreEnd
$suite = new PHPUnit_Framework_TestSuite(
$this->arguments['test'] . 'Test'
);
}
}
if ($this->arguments['listGroups']) {
PHPUnit_TextUI_TestRunner::printVersionString();

View file

@ -334,6 +334,7 @@ abstract class ControllerTestCase extends CakeTestCase {
$request = $this->getMock('CakeRequest');
$response = $this->getMock('CakeResponse', array('_sendHeader'));
$controllerObj->__construct($request, $response);
$controllerObj->Components->setController($controllerObj);
$config = ClassRegistry::config('Model');
foreach ($mocks['models'] as $model => $methods) {

View file

@ -32,27 +32,15 @@ class CakeTestModel extends Model {
* incorrect order when no order has been defined in the finds.
* Postgres can return the results in any order it considers appropriate if none is specified
*
* @param array $queryData
* @return array $queryData
* @param integer|string|array $id Set this ID for this model on startup, can also be an array of options, see above.
* @param string $table Name of database table to use.
* @param string $ds DataSource connection name.
*/
public function beforeFind($queryData) {
$pk = $this->primaryKey;
$aliasedPk = $this->alias . '.' . $this->primaryKey;
switch (true) {
case !$pk:
case !$this->useTable:
case !$this->schema('id'):
case !empty($queryData['order'][0]):
case !empty($queryData['group']):
case
(is_string($queryData['fields']) && !($queryData['fields'] == $pk || $queryData['fields'] == $aliasedPk)) ||
(is_array($queryData['fields']) && !(array_key_exists($pk, $queryData['fields']) || array_key_exists($aliasedPk, $queryData['fields']))):
break;
default:
$queryData['order'] = array($this->alias . '.' . $this->primaryKey => 'ASC');
}
return $queryData;
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->order = array($this->alias . '.' . $this->primaryKey => 'ASC');
}
/**
* Overriding save() to set CakeTestSuiteDispatcher::date() as formatter for created, modified and updated fields
*

View file

@ -223,7 +223,7 @@ class Helper extends Object {
*
* @param string $name Name of the property being accessed.
* @param mixed $value
* @return mixed Return the $value
* @return void
*/
public function __set($name, $value) {
switch ($name) {
@ -231,11 +231,13 @@ class Helper extends Object {
case 'here':
case 'webroot':
case 'data':
return $this->request->{$name} = $value;
$this->request->{$name} = $value;
return;
case 'action':
return $this->request->params['action'] = $value;
$this->request->params['action'] = $value;
return;
}
return $this->{$name} = $value;
$this->{$name} = $value;
}
/**
@ -834,7 +836,7 @@ class Helper extends Object {
* @param string $viewFile The file about to be rendered.
* @return void
*/
public function beforeRenderFile($viewfile) {
public function beforeRenderFile($viewFile) {
}
/**
@ -847,7 +849,7 @@ class Helper extends Object {
* @param string $content The content that was rendered.
* @return void
*/
public function afterRenderFile($viewfile, $content) {
public function afterRenderFile($viewFile, $content) {
}
/**

View file

@ -67,7 +67,8 @@ class CacheHelper extends AppHelper {
* Parses the view file and stores content for cache file building.
*
* @param string $viewFile
* @return void
* @param string $output The output for the file.
* @return string Updated content.
*/
public function afterRenderFile($viewFile, $output) {
if ($this->_enabled()) {

View file

@ -218,13 +218,11 @@ class FormHelper extends AppHelper {
if ($key === 'validates' && !isset($this->fieldset[$model]['validates'])) {
$validates = array();
if (!empty($object->validate)) {
foreach ($object->validator() as $validateField => $validateProperties) {
if ($this->_isRequiredField($validateProperties)) {
$validates[$validateField] = true;
}
}
}
$this->fieldset[$model]['validates'] = $validates;
}

View file

@ -621,7 +621,7 @@ class View extends Object {
* @see ViewBlock::start()
*/
public function start($name) {
return $this->Blocks->start($name);
$this->Blocks->start($name);
}
/**
@ -632,7 +632,7 @@ class View extends Object {
* @see ViewBlock::startIfEmpty()
*/
public function startIfEmpty($name) {
return $this->Blocks->startIfEmpty($name);
$this->Blocks->startIfEmpty($name);
}
/**
@ -646,7 +646,7 @@ class View extends Object {
* @see ViewBlock::concat()
*/
public function append($name, $value = null) {
return $this->Blocks->concat($name, $value);
$this->Blocks->concat($name, $value);
}
/**
@ -660,7 +660,7 @@ class View extends Object {
* @see ViewBlock::concat()
*/
public function prepend($name, $value = null) {
return $this->Blocks->concat($name, $value, ViewBlock::PREPEND);
$this->Blocks->concat($name, $value, ViewBlock::PREPEND);
}
/**
@ -674,7 +674,7 @@ class View extends Object {
* @see ViewBlock::set()
*/
public function assign($name, $value) {
return $this->Blocks->set($name, $value);
$this->Blocks->set($name, $value);
}
/**
@ -697,7 +697,7 @@ class View extends Object {
* @see ViewBlock::end()
*/
public function end() {
return $this->Blocks->end();
$this->Blocks->end();
}
/**