mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch '1.2' into 1.3
This commit is contained in:
commit
986af28de0
18 changed files with 13631 additions and 46 deletions
|
@ -66,7 +66,7 @@ class ApiShell extends Shell {
|
|||
return $this->help();
|
||||
}
|
||||
|
||||
$type = low($this->args[0]);
|
||||
$type = strtolower($this->args[0]);
|
||||
|
||||
if (isset($this->paths[$type])) {
|
||||
$path = $this->paths[$type];
|
||||
|
@ -202,7 +202,7 @@ class ApiShell extends Shell {
|
|||
|
||||
if (strpos($method, '__') === false && $method[0] != '_') {
|
||||
$parsed[$method] = array(
|
||||
'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])),
|
||||
'comment' => str_replace(array('/*', '*/', '*'), '', trim($result[1][$key])),
|
||||
'method' => $method,
|
||||
'parameters' => trim($result[3][$key])
|
||||
);
|
||||
|
|
|
@ -149,10 +149,10 @@ class Shell extends Object {
|
|||
ClassRegistry::map($this->name, $this->alias);
|
||||
|
||||
if (!PHP5 && isset($this->args[0])) {
|
||||
if (strpos($this->name, low(Inflector::camelize($this->args[0]))) !== false) {
|
||||
if (strpos($this->name, strtolower(Inflector::camelize($this->args[0]))) !== false) {
|
||||
$dispatch->shiftArgs();
|
||||
}
|
||||
if (low($this->command) == low(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
|
||||
if (strtolower($this->command) == strtolower(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
|
||||
$dispatch->shiftArgs();
|
||||
}
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ class Shell extends Object {
|
|||
}
|
||||
}
|
||||
if (is_array($options)) {
|
||||
while ($in == '' || ($in && (!in_array(low($in), $options) && !in_array(up($in), $options)) && !in_array($in, $options))) {
|
||||
while ($in == '' || ($in && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) {
|
||||
$in = $this->Dispatch->getInput($prompt, $options, $default);
|
||||
}
|
||||
}
|
||||
|
@ -427,10 +427,10 @@ class Shell extends Object {
|
|||
$this->out("\n" . sprintf(__("Creating file %s", true), $path));
|
||||
if (is_file($path) && $this->interactive === true) {
|
||||
$key = $this->in(__("File exists, overwrite?", true). " {$path}", array('y', 'n', 'q'), 'n');
|
||||
if (low($key) == 'q') {
|
||||
if (strtolower($key) == 'q') {
|
||||
$this->out(__("Quitting.", true) ."\n");
|
||||
exit;
|
||||
} elseif (low($key) != 'y') {
|
||||
} elseif (strtolower($key) != 'y') {
|
||||
$this->out(__("Skip", true) ." {$path}\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -472,7 +472,7 @@ class Shell extends Object {
|
|||
return true;
|
||||
}
|
||||
$unitTest = $this->in('SimpleTest is not installed. Do you want to bake unit test files anyway?', array('y','n'), 'y');
|
||||
$result = low($unitTest) == 'y' || low($unitTest) == 'yes';
|
||||
$result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes';
|
||||
|
||||
if ($result) {
|
||||
$this->out("\nYou can download SimpleTest from http://simpletest.org", true);
|
||||
|
@ -488,8 +488,8 @@ class Shell extends Object {
|
|||
*/
|
||||
function shortPath($file) {
|
||||
$shortPath = str_replace(ROOT, null, $file);
|
||||
$shortPath = str_replace('..'.DS, '', $shortPath);
|
||||
return r(DS.DS, DS, $shortPath);
|
||||
$shortPath = str_replace('..' . DS, '', $shortPath);
|
||||
return str_replace(DS . DS, DS, $shortPath);
|
||||
}
|
||||
/**
|
||||
* Creates the proper controller path for the specified controller class name
|
||||
|
@ -499,7 +499,7 @@ class Shell extends Object {
|
|||
* @access protected
|
||||
*/
|
||||
function _controllerPath($name) {
|
||||
return low(Inflector::underscore($name));
|
||||
return strtolower(Inflector::underscore($name));
|
||||
}
|
||||
/**
|
||||
* Creates the proper controller plural name for the specified controller class name
|
||||
|
|
|
@ -952,11 +952,11 @@ class DboOracle extends DboSource {
|
|||
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
|
||||
if (!isset($resultSet) || !is_array($resultSet)) {
|
||||
if (Configure::read() > 0) {
|
||||
e('<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->alias) . ' ');
|
||||
echo '<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->alias) . ' ';
|
||||
if (isset($this->error) && $this->error != null) {
|
||||
e($this->error);
|
||||
echo $this->error;
|
||||
}
|
||||
e('</div>');
|
||||
echo '</div>';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -742,11 +742,11 @@ class DboSource extends DataSource {
|
|||
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
|
||||
if (!isset($resultSet) || !is_array($resultSet)) {
|
||||
if (Configure::read() > 0) {
|
||||
e('<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->alias) . ' ');
|
||||
echo '<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->alias) . ' ';
|
||||
if (isset($this->error) && $this->error != null) {
|
||||
e($this->error);
|
||||
echo $this->error;
|
||||
}
|
||||
e('</div>');
|
||||
echo '</div>';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -369,7 +369,7 @@ class Model extends Overloadable {
|
|||
} elseif ($table) {
|
||||
$this->useTable = $table;
|
||||
}
|
||||
|
||||
|
||||
if ($ds !== null) {
|
||||
$this->useDbConfig = $ds;
|
||||
}
|
||||
|
@ -824,7 +824,7 @@ class Model extends Overloadable {
|
|||
$type = $this->getColumnType($field);
|
||||
|
||||
if (in_array($type, array('datetime', 'timestamp', 'date', 'time'))) {
|
||||
$useNewDate = (isset($data['year']) || isset($data['month']) ||
|
||||
$useNewDate = (isset($data['year']) || isset($data['month']) ||
|
||||
isset($data['day']) || isset($data['hour']) || isset($data['minute']));
|
||||
|
||||
$dateFields = array('Y' => 'year', 'm' => 'month', 'd' => 'day', 'H' => 'hour', 'i' => 'min', 's' => 'sec');
|
||||
|
@ -1340,7 +1340,7 @@ class Model extends Overloadable {
|
|||
unset($values);
|
||||
} elseif (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
||||
$newData[] = $row;
|
||||
} elseif (isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
||||
} elseif (isset($row[$join]) && isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
||||
$newData[] = $row[$join];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -958,7 +958,7 @@ class AjaxHelper extends AppHelper {
|
|||
$keys = array_keys($this->__ajaxBuffer);
|
||||
|
||||
if (count($divs) == 1 && in_array($divs[0], $keys)) {
|
||||
e($this->__ajaxBuffer[$divs[0]]);
|
||||
echo $this->__ajaxBuffer[$divs[0]];
|
||||
} else {
|
||||
foreach ($this->__ajaxBuffer as $key => $val) {
|
||||
if (in_array($key, $divs)) {
|
||||
|
@ -969,14 +969,13 @@ class AjaxHelper extends AppHelper {
|
|||
$out .= 'for (n in __ajaxUpdater__) { if (typeof __ajaxUpdater__[n] == "string"';
|
||||
$out .= ' && $(n)) Element.update($(n), unescape(decodeURIComponent(';
|
||||
$out .= '__ajaxUpdater__[n]))); }';
|
||||
e($this->Javascript->codeBlock($out, false));
|
||||
echo $this->Javascript->codeBlock($out, false);
|
||||
}
|
||||
$scripts = $this->Javascript->getCache();
|
||||
|
||||
if (!empty($scripts)) {
|
||||
e($this->Javascript->codeBlock($scripts, false));
|
||||
echo $this->Javascript->codeBlock($scripts, false);
|
||||
}
|
||||
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -481,7 +481,7 @@ class TimeHelper extends AppHelper {
|
|||
* @return bool
|
||||
*/
|
||||
function wasWithinLast($timeInterval, $dateString, $userOffset = null) {
|
||||
$tmp = r(' ', '', $timeInterval);
|
||||
$tmp = str_replace(' ', '', $timeInterval);
|
||||
if (is_numeric($tmp)) {
|
||||
$timeInterval = $tmp . ' ' . __('days', true);
|
||||
}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
<?php e($xml->header()); ?>
|
||||
<?php echo $xml->header(); ?>
|
||||
<?php echo $content_for_layout; ?>
|
|
@ -1,9 +1,7 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* TestTaskTest file
|
||||
*
|
||||
* Test Case for test generation shell task
|
||||
* ApiShellTest file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -51,12 +49,12 @@ Mock::generatePartial(
|
|||
);
|
||||
|
||||
/**
|
||||
* TestTaskTest class
|
||||
* ApiShellTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class TestTaskTest extends CakeTestCase {
|
||||
class ApiShellTest extends CakeTestCase {
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
|
|
|
@ -228,6 +228,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
$this->Case->before('start');
|
||||
$this->expectError();
|
||||
$this->Case->loadFixtures('Wrong!');
|
||||
$this->Case->end();
|
||||
}
|
||||
/**
|
||||
* testGetTests Method
|
||||
|
@ -268,6 +269,10 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
$result = $this->Case->testAction('/tests_apps/set_action', array('return' => 'vars'));
|
||||
$this->assertEqual($result, array('var' => 'string'));
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$fixture =& new PostFixture();
|
||||
$fixture->create($db);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps_posts/add', array('return' => 'vars'));
|
||||
$this->assertTrue(array_key_exists('posts', $result));
|
||||
$this->assertEqual(count($result['posts']), 1);
|
||||
|
@ -309,7 +314,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
)
|
||||
));
|
||||
$this->assertEqual(array_keys($result['data']), array('name', 'pork'));
|
||||
|
||||
$fixture->drop($db);
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$_backPrefix = $db->config['prefix'];
|
||||
|
@ -319,11 +324,11 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
$config['prefix'] = 'cake_testcase_test_';
|
||||
|
||||
ConnectionManager::create('cake_test_case', $config);
|
||||
$db =& ConnectionManager::getDataSource('cake_test_case');
|
||||
$db2 =& ConnectionManager::getDataSource('cake_test_case');
|
||||
|
||||
$fixture =& new PostFixture($db);
|
||||
$fixture->create($db);
|
||||
$fixture->insert($db);
|
||||
$fixture =& new PostFixture($db2);
|
||||
$fixture->create($db2);
|
||||
$fixture->insert($db2);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps_posts/fixtured', array(
|
||||
'return' => 'vars',
|
||||
|
@ -332,15 +337,12 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
));
|
||||
$this->assertTrue(isset($result['posts']));
|
||||
$this->assertEqual(count($result['posts']), 3);
|
||||
$tables = $db->listSources(true);
|
||||
$tables = $db2->listSources();
|
||||
$this->assertFalse(in_array('cake_testaction_test_suite_posts', $tables));
|
||||
|
||||
$fixture->drop($db);
|
||||
$fixture->drop($db2);
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$db->config['prefix'] = $_backPrefix;
|
||||
$fixture->drop($db);
|
||||
|
||||
|
||||
//test that drop tables behaves as exepected with testAction
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
|
|
571
cake/tests/cases/libs/model/model_delete.test.php
Normal file
571
cake/tests/cases/libs/model/model_delete.test.php
Normal file
|
@ -0,0 +1,571 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id: model.test.php 8225 2009-07-08 03:25:30Z mark_story $ */
|
||||
/**
|
||||
* ModelDeleteTest file
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @version $Revision: 8225 $
|
||||
* @modifiedby $LastChangedBy: mark_story $
|
||||
* @lastmodified $Date: 2009-07-07 23:25:30 -0400 (Tue, 07 Jul 2009) $
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
require_once dirname(__FILE__) . DS . 'model.test.php';
|
||||
require_once dirname(__FILE__) . DS . 'model_delete.test.php';
|
||||
/**
|
||||
* ModelDeleteTest
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model.operations
|
||||
*/
|
||||
class ModelDeleteTest extends BaseModelTest {
|
||||
/**
|
||||
* testDeleteHabtmReferenceWithConditions method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteHabtmReferenceWithConditions() {
|
||||
$this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio');
|
||||
|
||||
$Portfolio =& new Portfolio();
|
||||
$Portfolio->hasAndBelongsToMany['Item']['conditions'] = array('ItemsPortfolio.item_id >' => 1);
|
||||
|
||||
$result = $Portfolio->find('first', array(
|
||||
'conditions' => array('Portfolio.id' => 1)
|
||||
));
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 3,
|
||||
'syfile_id' => 3,
|
||||
'published' => 0,
|
||||
'name' => 'Item 3',
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 3,
|
||||
'item_id' => 3,
|
||||
'portfolio_id' => 1
|
||||
)),
|
||||
array(
|
||||
'id' => 4,
|
||||
'syfile_id' => 4,
|
||||
'published' => 0,
|
||||
'name' => 'Item 4',
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 4,
|
||||
'item_id' => 4,
|
||||
'portfolio_id' => 1
|
||||
)),
|
||||
array(
|
||||
'id' => 5,
|
||||
'syfile_id' => 5,
|
||||
'published' => 0,
|
||||
'name' => 'Item 5',
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 5,
|
||||
'item_id' => 5,
|
||||
'portfolio_id' => 1
|
||||
)));
|
||||
$this->assertEqual($result['Item'], $expected);
|
||||
|
||||
$result = $Portfolio->ItemsPortfolio->find('all', array(
|
||||
'conditions' => array('ItemsPortfolio.portfolio_id' => 1)
|
||||
));
|
||||
$expected = array(
|
||||
array(
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 1,
|
||||
'item_id' => 1,
|
||||
'portfolio_id' => 1
|
||||
)),
|
||||
array(
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 3,
|
||||
'item_id' => 3,
|
||||
'portfolio_id' => 1
|
||||
)),
|
||||
array(
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 4,
|
||||
'item_id' => 4,
|
||||
'portfolio_id' => 1
|
||||
)),
|
||||
array(
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 5,
|
||||
'item_id' => 5,
|
||||
'portfolio_id' => 1
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$Portfolio->delete(1);
|
||||
|
||||
$result = $Portfolio->find('first', array(
|
||||
'conditions' => array('Portfolio.id' => 1)
|
||||
));
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $Portfolio->ItemsPortfolio->find('all', array(
|
||||
'conditions' => array('ItemsPortfolio.portfolio_id' => 1)
|
||||
));
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
/**
|
||||
* testDeleteArticleBLinks method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteArticleBLinks() {
|
||||
$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
|
||||
$TestModel =& new ArticleB();
|
||||
|
||||
$result = $TestModel->ArticlesTag->find('all');
|
||||
$expected = array(
|
||||
array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '1')),
|
||||
array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '2')),
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')),
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3'))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$TestModel->delete(1);
|
||||
$result = $TestModel->ArticlesTag->find('all');
|
||||
|
||||
$expected = array(
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')),
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3'))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testDeleteDependentWithConditions method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteDependentWithConditions() {
|
||||
$this->loadFixtures('Cd','Book','OverallFavorite');
|
||||
|
||||
$Cd =& new Cd();
|
||||
$OverallFavorite =& new OverallFavorite();
|
||||
|
||||
$Cd->del(1);
|
||||
|
||||
$result = $OverallFavorite->find('all', array(
|
||||
'fields' => array('model_type', 'model_id', 'priority')
|
||||
));
|
||||
$expected = array(
|
||||
array(
|
||||
'OverallFavorite' => array(
|
||||
'model_type' => 'Book',
|
||||
'model_id' => 1,
|
||||
'priority' => 2
|
||||
)));
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testDel method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDel() {
|
||||
$this->loadFixtures('Article');
|
||||
$TestModel =& new Article();
|
||||
|
||||
$result = $TestModel->del(2);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $TestModel->read(null, 2);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$TestModel->recursive = -1;
|
||||
$result = $TestModel->find('all', array(
|
||||
'fields' => array('id', 'title')
|
||||
));
|
||||
$expected = array(
|
||||
array('Article' => array(
|
||||
'id' => 1,
|
||||
'title' => 'First Article'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 3,
|
||||
'title' => 'Third Article'
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $TestModel->del(3);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $TestModel->read(null, 3);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$TestModel->recursive = -1;
|
||||
$result = $TestModel->find('all', array(
|
||||
'fields' => array('id', 'title')
|
||||
));
|
||||
$expected = array(
|
||||
array('Article' => array(
|
||||
'id' => 1,
|
||||
'title' => 'First Article'
|
||||
)));
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
||||
// make sure deleting a non-existent record doesn't break save()
|
||||
// ticket #6293
|
||||
$this->loadFixtures('Uuid');
|
||||
$Uuid =& new Uuid();
|
||||
$data = array(
|
||||
'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3',
|
||||
'52C8865C-10EE-4302-AE6C-6E7D8E12E2C8',
|
||||
'8208C7FE-E89C-47C5-B378-DED6C271F9B8');
|
||||
foreach ($data as $id) {
|
||||
$Uuid->save(array('id' => $id));
|
||||
}
|
||||
$Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
|
||||
$Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
|
||||
foreach ($data as $id) {
|
||||
$Uuid->save(array('id' => $id));
|
||||
}
|
||||
$result = $Uuid->find('all', array(
|
||||
'conditions' => array('id' => $data),
|
||||
'fields' => array('id'),
|
||||
'order' => 'id'));
|
||||
$expected = array(
|
||||
array('Uuid' => array(
|
||||
'id' => '52C8865C-10EE-4302-AE6C-6E7D8E12E2C8')),
|
||||
array('Uuid' => array(
|
||||
'id' => '8208C7FE-E89C-47C5-B378-DED6C271F9B8')),
|
||||
array('Uuid' => array(
|
||||
'id' => 'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3')));
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testDeleteAll method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteAll() {
|
||||
$this->loadFixtures('Article');
|
||||
$TestModel =& new Article();
|
||||
|
||||
$data = array('Article' => array(
|
||||
'user_id' => 2,
|
||||
'id' => 4,
|
||||
'title' => 'Fourth Article',
|
||||
'published' => 'N'
|
||||
));
|
||||
$result = $TestModel->set($data) && $TestModel->save();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$data = array('Article' => array(
|
||||
'user_id' => 2,
|
||||
'id' => 5,
|
||||
'title' => 'Fifth Article',
|
||||
'published' => 'Y'
|
||||
));
|
||||
$result = $TestModel->set($data) && $TestModel->save();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$data = array('Article' => array(
|
||||
'user_id' => 1,
|
||||
'id' => 6,
|
||||
'title' => 'Sixth Article',
|
||||
'published' => 'N'
|
||||
));
|
||||
$result = $TestModel->set($data) && $TestModel->save();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$TestModel->recursive = -1;
|
||||
$result = $TestModel->find('all', array(
|
||||
'fields' => array('id', 'user_id', 'title', 'published')
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
array('Article' => array(
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'title' => 'First Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 2,
|
||||
'user_id' => 3,
|
||||
'title' => 'Second Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 3,
|
||||
'user_id' => 1,
|
||||
'title' => 'Third Article',
|
||||
'published' => 'Y')),
|
||||
array('Article' => array(
|
||||
'id' => 4,
|
||||
'user_id' => 2,
|
||||
'title' => 'Fourth Article',
|
||||
'published' => 'N'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 5,
|
||||
'user_id' => 2,
|
||||
'title' => 'Fifth Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 6,
|
||||
'user_id' => 1,
|
||||
'title' => 'Sixth Article',
|
||||
'published' => 'N'
|
||||
)));
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $TestModel->deleteAll(array('Article.published' => 'N'));
|
||||
$this->assertTrue($result);
|
||||
|
||||
$TestModel->recursive = -1;
|
||||
$result = $TestModel->find('all', array(
|
||||
'fields' => array('id', 'user_id', 'title', 'published')
|
||||
));
|
||||
$expected = array(
|
||||
array('Article' => array(
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'title' => 'First Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 2,
|
||||
'user_id' => 3,
|
||||
'title' => 'Second Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 3,
|
||||
'user_id' => 1,
|
||||
'title' => 'Third Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 5,
|
||||
'user_id' => 2,
|
||||
'title' => 'Fifth Article',
|
||||
'published' => 'Y'
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$data = array('Article.user_id' => array(2, 3));
|
||||
$result = $TestModel->deleteAll($data, true, true);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$TestModel->recursive = -1;
|
||||
$result = $TestModel->find('all', array(
|
||||
'fields' => array('id', 'user_id', 'title', 'published')
|
||||
));
|
||||
$expected = array(
|
||||
array('Article' => array(
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'title' => 'First Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 3,
|
||||
'user_id' => 1,
|
||||
'title' => 'Third Article',
|
||||
'published' => 'Y'
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $TestModel->deleteAll(array('Article.user_id' => 999));
|
||||
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
|
||||
}
|
||||
/**
|
||||
* testRecursiveDel method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testRecursiveDel() {
|
||||
$this->loadFixtures('Article', 'Comment', 'Attachment');
|
||||
$TestModel =& new Article();
|
||||
|
||||
$result = $TestModel->del(2);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$TestModel->recursive = 2;
|
||||
$result = $TestModel->read(null, 2);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $TestModel->Comment->read(null, 5);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $TestModel->Comment->read(null, 6);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $TestModel->Comment->Attachment->read(null, 1);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $TestModel->find('count');
|
||||
$this->assertEqual($result, 2);
|
||||
|
||||
$result = $TestModel->Comment->find('count');
|
||||
$this->assertEqual($result, 4);
|
||||
|
||||
$result = $TestModel->Comment->Attachment->find('count');
|
||||
$this->assertEqual($result, 0);
|
||||
}
|
||||
/**
|
||||
* testDependentExclusiveDelete method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDependentExclusiveDelete() {
|
||||
$this->loadFixtures('Article', 'Comment');
|
||||
$TestModel =& new Article10();
|
||||
|
||||
$result = $TestModel->find('all');
|
||||
$this->assertEqual(count($result[0]['Comment']), 4);
|
||||
$this->assertEqual(count($result[1]['Comment']), 2);
|
||||
$this->assertEqual($TestModel->Comment->find('count'), 6);
|
||||
|
||||
$TestModel->delete(1);
|
||||
$this->assertEqual($TestModel->Comment->find('count'), 2);
|
||||
}
|
||||
/**
|
||||
* testDeleteLinks method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteLinks() {
|
||||
$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
|
||||
$TestModel =& new Article();
|
||||
|
||||
$result = $TestModel->ArticlesTag->find('all');
|
||||
$expected = array(
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '1',
|
||||
'tag_id' => '1'
|
||||
)),
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '1',
|
||||
'tag_id' => '2'
|
||||
)),
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '2',
|
||||
'tag_id' => '1'
|
||||
)),
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '2',
|
||||
'tag_id' => '3'
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$TestModel->delete(1);
|
||||
$result = $TestModel->ArticlesTag->find('all');
|
||||
|
||||
$expected = array(
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '2',
|
||||
'tag_id' => '1'
|
||||
)),
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '2',
|
||||
'tag_id' => '3'
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $TestModel->deleteAll(array('Article.user_id' => 999));
|
||||
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
|
||||
}
|
||||
/**
|
||||
* testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable() {
|
||||
|
||||
$this->loadFixtures('Apple', 'Device', 'ThePaperMonkies');
|
||||
$ThePaper =& new ThePaper();
|
||||
$ThePaper->id = 1;
|
||||
$ThePaper->save(array('Monkey' => array(2, 3)));
|
||||
|
||||
$result = $ThePaper->findById(1);
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 2',
|
||||
'typ' => '1'
|
||||
),
|
||||
array(
|
||||
'id' => '3',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 3',
|
||||
'typ' => '2'
|
||||
));
|
||||
$this->assertEqual($result['Monkey'], $expected);
|
||||
|
||||
$ThePaper =& new ThePaper();
|
||||
$ThePaper->id = 2;
|
||||
$ThePaper->save(array('Monkey' => array(2, 3)));
|
||||
|
||||
$result = $ThePaper->findById(2);
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 2',
|
||||
'typ' => '1'
|
||||
),
|
||||
array(
|
||||
'id' => '3',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 3',
|
||||
'typ' => '2'
|
||||
));
|
||||
$this->assertEqual($result['Monkey'], $expected);
|
||||
|
||||
$ThePaper->delete(1);
|
||||
$result = $ThePaper->findById(2);
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 2',
|
||||
'typ' => '1'
|
||||
),
|
||||
array(
|
||||
'id' => '3',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 3',
|
||||
'typ' => '2'
|
||||
));
|
||||
$this->assertEqual($result['Monkey'], $expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
1837
cake/tests/cases/libs/model/model_integration.test.php
Normal file
1837
cake/tests/cases/libs/model/model_integration.test.php
Normal file
File diff suppressed because it is too large
Load diff
7151
cake/tests/cases/libs/model/model_read.test.php
Normal file
7151
cake/tests/cases/libs/model/model_read.test.php
Normal file
File diff suppressed because it is too large
Load diff
126
cake/tests/cases/libs/model/model_validation.test.php
Normal file
126
cake/tests/cases/libs/model/model_validation.test.php
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id: model.test.php 8225 2009-07-08 03:25:30Z mark_story $ */
|
||||
/**
|
||||
* ModelValidationTest file
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @version $Revision: 8225 $
|
||||
* @modifiedby $LastChangedBy: mark_story $
|
||||
* @lastmodified $Date: 2009-07-07 23:25:30 -0400 (Tue, 07 Jul 2009) $
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
require_once dirname(__FILE__) . DS . 'model.test.php';
|
||||
require_once dirname(__FILE__) . DS . 'model_validation.test.php';
|
||||
/**
|
||||
* ModelValidationTest
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model.operations
|
||||
*/
|
||||
class ModelValidationTest extends BaseModelTest {
|
||||
/**
|
||||
* Tests validation parameter order in custom validation methods
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testValidationParams() {
|
||||
$TestModel =& new ValidationTest1();
|
||||
$TestModel->validate['title'] = array(
|
||||
'rule' => 'customValidatorWithParams',
|
||||
'required' => true
|
||||
);
|
||||
$TestModel->create(array('title' => 'foo'));
|
||||
$TestModel->invalidFields();
|
||||
|
||||
$expected = array(
|
||||
'data' => array(
|
||||
'title' => 'foo'
|
||||
),
|
||||
'validator' => array(
|
||||
'rule' => 'customValidatorWithParams',
|
||||
'on' => null,
|
||||
'last' => false,
|
||||
'allowEmpty' => false,
|
||||
'required' => true
|
||||
),
|
||||
'or' => true,
|
||||
'ignore_on_same' => 'id'
|
||||
);
|
||||
$this->assertEqual($TestModel->validatorParams, $expected);
|
||||
|
||||
$TestModel->validate['title'] = array(
|
||||
'rule' => 'customValidatorWithMessage',
|
||||
'required' => true
|
||||
);
|
||||
$expected = array(
|
||||
'title' => 'This field will *never* validate! Muhahaha!'
|
||||
);
|
||||
|
||||
$this->assertEqual($TestModel->invalidFields(), $expected);
|
||||
}
|
||||
/**
|
||||
* Tests validation parameter fieldList in invalidFields
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testInvalidFieldsWithFieldListParams() {
|
||||
$TestModel =& new ValidationTest1();
|
||||
$TestModel->validate = $validate = array(
|
||||
'title' => array(
|
||||
'rule' => 'customValidator',
|
||||
'required' => true
|
||||
),
|
||||
'name' => array(
|
||||
'rule' => 'allowEmpty',
|
||||
'required' => true
|
||||
));
|
||||
$TestModel->invalidFields(array('fieldList' => array('title')));
|
||||
$expected = array(
|
||||
'title' => 'This field cannot be left blank'
|
||||
);
|
||||
$this->assertEqual($TestModel->validationErrors, $expected);
|
||||
$TestModel->validationErrors = array();
|
||||
|
||||
$TestModel->invalidFields(array('fieldList' => array('name')));
|
||||
$expected = array(
|
||||
'name' => 'This field cannot be left blank'
|
||||
);
|
||||
$this->assertEqual($TestModel->validationErrors, $expected);
|
||||
$TestModel->validationErrors = array();
|
||||
|
||||
$TestModel->invalidFields(array('fieldList' => array('name', 'title')));
|
||||
$expected = array(
|
||||
'name' => 'This field cannot be left blank',
|
||||
'title' => 'This field cannot be left blank'
|
||||
);
|
||||
$this->assertEqual($TestModel->validationErrors, $expected);
|
||||
$TestModel->validationErrors = array();
|
||||
|
||||
$TestModel->whitelist = array('name');
|
||||
$TestModel->invalidFields();
|
||||
$expected = array('name' => 'This field cannot be left blank');
|
||||
$this->assertEqual($TestModel->validationErrors, $expected);
|
||||
$TestModel->validationErrors = array();
|
||||
|
||||
$this->assertEqual($TestModel->validate, $validate);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
3894
cake/tests/cases/libs/model/model_write.test.php
Normal file
3894
cake/tests/cases/libs/model/model_write.test.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -425,10 +425,11 @@ class CakeTestCase extends UnitTestCase {
|
|||
return;
|
||||
}
|
||||
foreach ($this->_fixtures as $fixture) {
|
||||
if (in_array($fixture->table, $sources)) {
|
||||
$table = $this->db->config['prefix'] . $fixture->table;
|
||||
if (in_array($table, $sources)) {
|
||||
$fixture->drop($this->db);
|
||||
$fixture->create($this->db);
|
||||
} elseif (!in_array($fixture->table, $sources)) {
|
||||
} elseif (!in_array($table, $sources)) {
|
||||
$fixture->create($this->db);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,12 @@
|
|||
* @subpackage cake.cake.tests.lib
|
||||
*/
|
||||
class CakeTestFixture extends Object {
|
||||
/**
|
||||
* Name of the object
|
||||
*
|
||||
* @var string
|
||||
**/
|
||||
var $name = null;
|
||||
/**
|
||||
* Cake's DBO driver (e.g: DboMysql).
|
||||
*
|
||||
|
@ -43,7 +49,6 @@ class CakeTestFixture extends Object {
|
|||
* @access public
|
||||
*/
|
||||
var $table = null;
|
||||
|
||||
/**
|
||||
* Instantiate the fixture.
|
||||
*
|
||||
|
@ -185,4 +190,4 @@ class CakeTestFixture extends Object {
|
|||
return $return;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
|
@ -33,7 +33,8 @@ class TestsAppsPostsController extends AppController {
|
|||
$data = array(
|
||||
'Post' => array(
|
||||
'title' => 'Test article',
|
||||
'body' => 'Body of article.'
|
||||
'body' => 'Body of article.',
|
||||
'author_id' => 1
|
||||
)
|
||||
);
|
||||
$this->Post->save($data);
|
||||
|
|
Loading…
Reference in a new issue