Updating test suite

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4443 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-02-04 07:42:35 +00:00
parent 28a050bace
commit 1a391e4d2c
6 changed files with 101 additions and 29 deletions

View file

@ -117,7 +117,21 @@ if(!vendor('simpletest' . DS . 'reporter')) {
function CakePHPTestRunMore() {
switch (CAKE_TEST_OUTPUT) {
case CAKE_TEST_OUTPUT_HTML:
echo "<p><a href='" . $_SERVER['PHP_SELF'] . "'>Run more tests</a></p>\n";
if (isset($_GET['group'])) {
if(isset($_GET['app'])) {
$show = '?show=groups&amp;app=true';
} else {
$show = '?show=groups';
}
}
if (isset($_GET['case'])) {
if(isset($_GET['app'])) {
$show = '??show=cases&amp;app=truee';
} else {
$show = '?show=cases';
}
}
echo "<p><a href='" . $_SERVER['PHP_SELF'] . $show . "'>Run more tests</a></p>\n";
break;
}
}

View file

@ -130,98 +130,98 @@ class DboSourceTest extends UnitTestCase {
function testStringConditionsParsing() {
$result = $this->db->conditions("Candy.name LIKE 'a' AND HardCandy.name LIKE 'c'");
$expected = " WHERE `Candy`.`name` LIKE 'a' AND `HardCandy`.`name` LIKE 'c'";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions("HardCandy.name LIKE 'a' AND Candy.name LIKE 'c'");
$expected = " WHERE `HardCandy`.`name` LIKE 'a' AND `Candy`.`name` LIKE 'c'";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions("Post.title = '1.1'");
$expected = " WHERE `Post`.`title` = '1.1'";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions("SUM(Post.comments_count) > 500");
$expected = " WHERE SUM( `Post`.`comments_count`) > 500";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
$expected = " WHERE ( `Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR( `Post`.`created`), MONTH( `Post`.`created`)";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions("score BETWEEN 90.1 AND 95.7");
$expected = " WHERE score BETWEEN 90.1 AND 95.7";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions("Aro.rght = Aro.lft + 1.1");
$expected = " WHERE `Aro`.`rght` = `Aro`.`lft` + 1.1";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
$expected = " WHERE ( `Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR( `Post`.`created`), MONTH( `Post`.`created`)";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions('Sportstaette.sportstaette LIKE "%ru%" AND Sportstaette.sportstaettenart_id = 2');
$expected = ' WHERE `Sportstaette`.`sportstaette` LIKE "%ru%" AND `Sportstaette`.`sportstaettenart_id` = 2';
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '" . r('%', '_', $expected) . "', got '" . r('%', '_', $result) . "'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions('Sportstaette.sportstaettenart_id = 2 AND Sportstaette.sportstaette LIKE "%ru%"');
$expected = ' WHERE `Sportstaette`.`sportstaettenart_id` = 2 AND `Sportstaette`.`sportstaette` LIKE "%ru%"';
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '" . r('%', '_', $expected) . "', got '" . r('%', '_', $result) . "'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions('SUM(Post.comments_count) > 500 AND NOT Post.title IS NULL AND NOT Post.extended_title IS NULL');
$expected = ' WHERE SUM( `Post`.`comments_count`) > 500 AND NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL';
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions('NOT Post.title IS NULL AND NOT Post.extended_title IS NULL AND SUM(Post.comments_count) > 500');
$expected = ' WHERE NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL AND SUM( `Post`.`comments_count`) > 500';
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions('NOT Post.extended_title IS NULL AND NOT Post.title IS NULL AND Post.title != "" AND SPOON(SUM(Post.comments_count) + 1.1) > 500');
$expected = ' WHERE NOT `Post`.`extended_title` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title` != "" AND SPOON(SUM( `Post`.`comments_count`) + 1.1) > 500';
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions('NOT Post.title_extended IS NULL AND NOT Post.title IS NULL AND Post.title_extended != Post.title');
$expected = ' WHERE NOT `Post`.`title_extended` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title_extended` != `Post`.`title`';
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
}
function testArrayConditionsParsing() {
$result = $this->db->conditions(array('Candy.name' => 'LIKE a', 'HardCandy.name' => 'LIKE c'));
$expected = " WHERE `Candy`.`name` LIKE 'a' AND `HardCandy`.`name` LIKE 'c'";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions(array('HardCandy.name' => 'LIKE a', 'Candy.name' => 'LIKE c'));
$expected = " WHERE `HardCandy`.`name` LIKE 'a' AND `Candy`.`name` LIKE 'c'";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions(array('score' => 'BETWEEN 90.1 AND 95.7'));
$expected = " WHERE `score` BETWEEN '90.1' AND '95.7'";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions(array('Post.title' => 1.1));
$expected = " WHERE `Post`.`title` = 1.1";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
$result = $this->db->conditions(array('SUM(Post.comments_count)' => '> 500'));
$expected = " WHERE SUM(`Post`.`comments_count`) > 500";
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::conditions(), %s");
}
function testFieldParsing() {
$result = $this->db->fields($this->model, 'Post', "CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name, Node.created");
$expected = array("CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name", "`Node`.`created`");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::fields(), expected '{$expected[0]}', got '{$result[0]}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::fields(), %s");
$result = $this->db->fields($this->model, 'Post', "Node.created, CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name");
$expected = array("`Node`.`created`", "CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::fields(), expected '{$expected[0]}', got '{$result[0]}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::fields(), %s");
$result = $this->db->fields($this->model, 'Post', "2.2,COUNT(*), SUM(Something.else) as sum, Node.created, CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name,Post.title,Post.1,1.1");
$expected = array(
'2.2', 'COUNT(*)', 'SUM(`Something`.`else`) as sum', '`Node`.`created`',
"CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name", '`Post`.`title`', '`Post`.`1`', '1.1'
);
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::fields(), expected '{$expected[0]}', got '{$result[0]}'.");
$this->assertEqual($result, $expected, "Error quoting field names in DboSource::fields(), %s");
}
function testMagicMethodQuerying() {
@ -231,15 +231,15 @@ class DboSourceTest extends UnitTestCase {
$result = $this->db->query('findByFieldName', array(array('value1', 'value2', 'value3')), $this->model);
$expected = array('TestModel.field_name' => array('value1', 'value2', 'value3'));
$this->assertEqual($result, $expected, "Error computing conditions from magic method with array value.");
$this->assertEqual($result, $expected, "Error computing conditions from magic method with array value. %s");
$result = $this->db->query('findByFieldName', array(null), $this->model);
$expected = array('TestModel.field_name' => null);
$this->assertEqual($result, $expected, "Error computing conditions from magic method with null value.");
$this->assertEqual($result, $expected, "Error computing conditions from magic method with null value. %s");
$result = $this->db->query('findByFieldName', array('= a'), $this->model);
$expected = array('TestModel.field_name' => '= = a');
$this->assertEqual($result, $expected, "Error computing conditions from magic method with string value.");
$this->assertEqual($result, $expected, "Error computing conditions from magic method with string value. %s");
}
function testSomething() {

View file

@ -34,9 +34,9 @@
* @subpackage cake.tests.groups
*/
class AllCoreLibGroupTest extends GroupTest {
var $label = 'All cake/libs/* (Not yet implemented)';
function AllCoreLibGroupTest() {
$this->GroupTest('All cake/libs/*');
TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'libs');
}
}

View file

@ -33,9 +33,9 @@
* @subpackage cake.tests.groups
*/
class LibControllerGroupTest extends GroupTest {
var $label = 'All cake/libs/controller/* (Not yet implemented)';
function LibControllerGroupTest() {
$this->GroupTest('All cake/libs/controller/*');
TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller');
}
}

View 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-2007, 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-2007, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake.tests
* @subpackage cake.tests.groups
* @since CakePHP(tm) v 1.2.0.4206
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
/** AllCoreLibGroupTest
*
* This test group will run all test in the cases/libs directory.
*
* @package cake.tests
* @subpackage cake.tests.groups
*/
class AllCoreWithOutDatabaseGroupTest extends GroupTest {
var $label = 'All Test without a database connection';
function AllCoreWithOutDatabaseGroupTest() {
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'router');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'dispatcher');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'validation');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS . 'paginator');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'socket');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS . 'ajax');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'model');
}
}
?>

View file

@ -105,7 +105,11 @@ class TestManager {
$test =& new GroupTest($groupTestName . ' group test');
foreach ($manager->_getGroupTestClassNames($filePath) as $groupTest) {
$test->addTestCase(new $groupTest());
$testCase = new $groupTest();
$test->addTestCase($testCase);
if(isset($testCase->label)) {
$test->_label = $testCase->label;
}
}
$test->run($reporter);
}
@ -118,6 +122,11 @@ class TestManager {
}
}
function addTestFile(&$groupTest, $file) {
$manager =& new TestManager();
$groupTest->addTestFile($file.'.test.php');
}
function &getTestCaseList($directory = '.') {
$manager =& new TestManager();
$return = $manager->_getTestCaseList($directory);