mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Updated Model tests to reflect diffs related to ticket #4444
Fixed issue with testing of model::query with incorrect table name git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6810 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f653e203b8
commit
a70cc25eed
3 changed files with 91 additions and 18 deletions
|
@ -47,7 +47,7 @@ class ModelTest extends CakeTestCase {
|
|||
'core.syfile', 'core.image', 'core.device_type', 'core.device_type_category', 'core.feature_set', 'core.exterior_type_category',
|
||||
'core.document', 'core.device', 'core.document_directory', 'core.primary_model', 'core.secondary_model', 'core.something',
|
||||
'core.something_else', 'core.join_thing', 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_b', 'core.join_a_c',
|
||||
'core.uuid', 'core.data_test', 'core.posts_tag', 'core.the_paper_monkies', 'core.person'
|
||||
'core.uuid', 'core.data_test', 'core.posts_tag', 'core.the_paper_monkies', 'core.person', 'core.underscore_field'
|
||||
);
|
||||
|
||||
function start() {
|
||||
|
@ -3687,18 +3687,18 @@ class ModelTest extends CakeTestCase {
|
|||
$this->loadFixtures('Article');
|
||||
$this->Article =& new Article();
|
||||
|
||||
$query = "SELECT title FROM articles WHERE articles.id IN (1,2)";
|
||||
$query = "SELECT title FROM test_suite_articles WHERE test_suite_articles.id IN (1,2)";
|
||||
$results = $this->Article->query($query);
|
||||
$this->assertTrue(is_array($results));
|
||||
$this->assertEqual(count($results), 2);
|
||||
|
||||
$query = "SELECT title, body FROM articles WHERE articles.id = 1";
|
||||
$query = "SELECT title, body FROM test_suite_articles WHERE test_suite_articles.id = 1";
|
||||
$results = $this->Article->query($query, false);
|
||||
$db =& ConnectionManager::getDataSource($this->Article->useDbConfig);
|
||||
$this->assertTrue(!isset($db->_queryCache[$query]));
|
||||
$this->assertTrue(is_array($results));
|
||||
|
||||
$query = "SELECT title, id FROM articles WHERE articles.published = 'Y'";
|
||||
$query = "SELECT title, id FROM test_suite_articles WHERE test_suite_articles.published = 'Y'";
|
||||
$results = $this->Article->query($query, true);
|
||||
$this->assertTrue(isset($db->_queryCache[$query]));
|
||||
$this->assertTrue(is_array($results));
|
||||
|
@ -3709,38 +3709,38 @@ class ModelTest extends CakeTestCase {
|
|||
$this->Article =& new Article();
|
||||
$db =& ConnectionManager::getDataSource($this->Article->useDbConfig);
|
||||
|
||||
$finalQuery = "SELECT title, published FROM articles WHERE articles.id = 1 AND articles.published = 'Y'";
|
||||
$query = "SELECT title, published FROM articles WHERE articles.id = ? AND articles.published = ?";
|
||||
$finalQuery = "SELECT title, published FROM test_suite_articles WHERE test_suite_articles.id = 1 AND test_suite_articles.published = 'Y'";
|
||||
$query = "SELECT title, published FROM test_suite_articles WHERE test_suite_articles.id = ? AND test_suite_articles.published = ?";
|
||||
$params = array(1, 'Y');
|
||||
$result = $this->Article->query($query, $params);
|
||||
$expected = array('0' => array('articles' => array('title' => 'First Article', 'published' => 'Y')));
|
||||
$expected = array('0' => array('test_suite_articles' => array('title' => 'First Article', 'published' => 'Y')));
|
||||
if (isset($result[0][0])) {
|
||||
$expected[0][0] = $expected[0]['articles'];
|
||||
unset($expected[0]['articles']);
|
||||
$expected[0][0] = $expected[0]['test_suite_articles'];
|
||||
unset($expected[0]['test_suite_articles']);
|
||||
}
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertTrue(isset($db->_queryCache[$finalQuery]));
|
||||
|
||||
$finalQuery = "SELECT id, created FROM articles WHERE articles.title = 'First Article'";
|
||||
$query = "SELECT id, created FROM articles WHERE articles.title = ?";
|
||||
$finalQuery = "SELECT id, created FROM test_suite_articles WHERE test_suite_articles.title = 'First Article'";
|
||||
$query = "SELECT id, created FROM test_suite_articles WHERE test_suite_articles.title = ?";
|
||||
$params = array('First Article');
|
||||
$result = $this->Article->query($query, $params, false);
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertTrue(isset($result[0]['articles']) || isset($result[0][0]));
|
||||
$this->assertTrue(isset($result[0]['test_suite_articles']) || isset($result[0][0]));
|
||||
$this->assertFalse(isset($db->_queryCache[$finalQuery]));
|
||||
|
||||
$query = "SELECT title FROM articles WHERE articles.title LIKE ?";
|
||||
$query = "SELECT title FROM test_suite_articles WHERE test_suite_articles.title LIKE ?";
|
||||
$params = array('%First%');
|
||||
$result = $this->Article->query($query, $params);
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertTrue(isset($result[0]['articles']['title']));
|
||||
$this->assertTrue(isset($result[0]['test_suite_articles']['title']));
|
||||
}
|
||||
|
||||
function testParameterMismatch() {
|
||||
$this->loadFixtures('Article');
|
||||
$this->Article =& new Article();
|
||||
|
||||
$query = "SELECT * FROM articles WHERE articles.published = ? AND articles.user_id = ?";
|
||||
$query = "SELECT * FROM test_suite_articles WHERE test_suite_articles.published = ? AND test_suite_articles.user_id = ?";
|
||||
$params = array('Y');
|
||||
$result = $this->Article->query($query, $params);
|
||||
$this->assertEqual($result, null);
|
||||
|
@ -3756,13 +3756,33 @@ class ModelTest extends CakeTestCase {
|
|||
$this->Article =& new Article();
|
||||
|
||||
$query = "SELECT * FROM ? WHERE ? = ? AND ? = ?";
|
||||
$param = array('articles', 'articles.user_id', '3', 'articles.published', 'Y');
|
||||
$param = array('test_suite_articles', 'test_suite_articles.user_id', '3', 'test_suite_articles.published', 'Y');
|
||||
$this->expectError();
|
||||
ob_start();
|
||||
$result = $this->Article->query($query, $param);
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
function testUnderscoreFieldSave() {
|
||||
$this->loadFixtures('UnderscoreField');
|
||||
$this->UnderscoreField =& new UnderscoreField();
|
||||
|
||||
$currentCount = $this->UnderscoreField->find('count');
|
||||
$this->assertEqual($currentCount, 3);
|
||||
$data = array('UnderscoreField' =>
|
||||
array( 'user_id' => '1',
|
||||
'my_model_has_a_field' => 'Content here',
|
||||
'body' => 'Body',
|
||||
'published' => 'Y',
|
||||
'another_field' => 4
|
||||
));
|
||||
$ret = $this->UnderscoreField->save($data);
|
||||
$this->assertTrue($ret);
|
||||
|
||||
$currentCount = $this->UnderscoreField->find('count');
|
||||
$this->assertEqual($currentCount, 4);
|
||||
}
|
||||
|
||||
function endTest() {
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
|
|
@ -613,4 +613,8 @@ class Person extends CakeTestModel {
|
|||
'className' => 'Person',
|
||||
'foreignKey' => 'father_id'));
|
||||
}
|
||||
|
||||
class UnderscoreField extends CakeTestModel {
|
||||
var $name = 'UnderscoreField';
|
||||
}
|
||||
?>
|
49
cake/tests/fixtures/underscore_field_fixture.php
vendored
Normal file
49
cake/tests/fixtures/underscore_field_fixture.php
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Short description for 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.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* 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.
|
||||
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.fixtures
|
||||
* @since CakePHP(tm) v 1.2.0.4667
|
||||
* @version $Revision: 6571 $
|
||||
* @modifiedby $LastChangedBy: nate $
|
||||
* @lastmodified $Date: 2008-03-15 01:08:06 -0400 (Sat, 15 Mar 2008) $
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
class UnderscoreFieldFixture extends CakeTestFixture {
|
||||
var $name = 'UnderscoreField';
|
||||
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'user_id' => array('type' => 'integer', 'null' => false),
|
||||
'my_model_has_a_field' => array('type' => 'string', 'null' => false),
|
||||
'body_field' => 'text',
|
||||
'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'),
|
||||
'another_field' => array('type' => 'integer', 'length' => 3),
|
||||
);
|
||||
|
||||
var $records = array(
|
||||
array('user_id' => 1, 'my_model_has_a_field' => 'First Article', 'body_field' => 'First Article Body', 'published' => 'Y', 'another_field' => 2),
|
||||
array('user_id' => 3, 'my_model_has_a_field' => 'Second Article', 'body_field' => 'Second Article Body', 'published' => 'Y', 'another_field' => 3),
|
||||
array('user_id' => 1, 'my_model_has_a_field' => 'Third Article', 'body_field' => 'Third Article Body', 'published' => 'Y', 'another_field' => 5),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Reference in a new issue