Updating test suite

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4445 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-02-04 09:06:44 +00:00
parent c4b6f522b2
commit 578073b91d
8 changed files with 964 additions and 968 deletions

View file

@ -39,12 +39,12 @@ class DispatcherTest extends UnitTestCase {
function testParseParamsWithoutZerosAndEmptyPost() { function testParseParamsWithoutZerosAndEmptyPost() {
$dispatcher =& new Dispatcher(); $dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3"); $test = $dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3");
$this->assertIdentical($test['controller'], 'testcontroller', "%s"); $this->assertIdentical($test['controller'], 'testcontroller');
$this->assertIdentical($test['action'], 'testaction', "%s"); $this->assertIdentical($test['action'], 'testaction');
$this->assertIdentical($test['pass'][0], 'params1', "%s"); $this->assertIdentical($test['pass'][0], 'params1');
$this->assertIdentical($test['pass'][1], 'params2', "%s"); $this->assertIdentical($test['pass'][1], 'params2');
$this->assertIdentical($test['pass'][2], 'params3', "%s"); $this->assertIdentical($test['pass'][2], 'params3');
$this->assertFalse(!empty($test['form']), "%s"); $this->assertFalse(!empty($test['form']));
} }
function testParseParamsReturnsPostedData() { function testParseParamsReturnsPostedData() {
@ -52,50 +52,50 @@ class DispatcherTest extends UnitTestCase {
$dispatcher =& new Dispatcher(); $dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/"); $test = $dispatcher->parseParams("/");
$this->assertTrue($test['form'], "Parsed URL not returning post data"); $this->assertTrue($test['form'], "Parsed URL not returning post data");
$this->assertIdentical($test['form']['testdata'], "My Posted Content", "%s"); $this->assertIdentical($test['form']['testdata'], "My Posted Content");
} }
function testParseParamsWithSingleZero() { function testParseParamsWithSingleZero() {
$dispatcher =& new Dispatcher(); $dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/1/0/23"); $test = $dispatcher->parseParams("/testcontroller/testaction/1/0/23");
$this->assertIdentical($test['controller'], 'testcontroller', "%s"); $this->assertIdentical($test['controller'], 'testcontroller');
$this->assertIdentical($test['action'], 'testaction', "%s"); $this->assertIdentical($test['action'], 'testaction');
$this->assertIdentical($test['pass'][0], '1', "%s"); $this->assertIdentical($test['pass'][0], '1');
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1], "%s"); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
$this->assertIdentical($test['pass'][2], '23', "%s"); $this->assertIdentical($test['pass'][2], '23');
} }
function testParseParamsWithManySingleZeros() { function testParseParamsWithManySingleZeros() {
$dispatcher =& new Dispatcher(); $dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/0/0/0/0/0/0"); $test = $dispatcher->parseParams("/testcontroller/testaction/0/0/0/0/0/0");
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][0], "%s"); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][0]);
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1], "%s"); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][2], "%s"); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][2]);
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][3], "%s"); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][3]);
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][4], "%s"); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][4]);
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][5], "%s"); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][5]);
} }
function testParseParamsWithManyZerosInEachSectionOfUrl() { function testParseParamsWithManyZerosInEachSectionOfUrl() {
$dispatcher =& new Dispatcher(); $dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000"); $test = $dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
$this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0], "%s"); $this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0]);
$this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1], "%s"); $this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1]);
$this->assertPattern('/\\A(?:00000)\\z/', $test['pass'][2], "%s"); $this->assertPattern('/\\A(?:00000)\\z/', $test['pass'][2]);
$this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][3], "%s"); $this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][3]);
$this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][4], "%s"); $this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][4]);
$this->assertPattern('/\\A(?:0000000)\\z/', $test['pass'][5], "%s"); $this->assertPattern('/\\A(?:0000000)\\z/', $test['pass'][5]);
} }
function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() { function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
$dispatcher =& new Dispatcher(); $dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400"); $test = $dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
$this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0], "%s"); $this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]);
$this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1], "%s"); $this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1]);
$this->assertPattern('/\\A(?:04010)\\z/', $test['pass'][2], "%s"); $this->assertPattern('/\\A(?:04010)\\z/', $test['pass'][2]);
$this->assertPattern('/\\A(?:000002)\\z/', $test['pass'][3], "%s"); $this->assertPattern('/\\A(?:000002)\\z/', $test['pass'][3]);
$this->assertPattern('/\\A(?:000030)\\z/', $test['pass'][4], "%s"); $this->assertPattern('/\\A(?:000030)\\z/', $test['pass'][4]);
$this->assertPattern('/\\A(?:0000400)\\z/', $test['pass'][5], "%s"); $this->assertPattern('/\\A(?:0000400)\\z/', $test['pass'][5]);
} }
} }
?> ?>

View file

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

View file

@ -50,8 +50,7 @@ class ModelTest extends UnitTestCase {
function testIdentity() { function testIdentity() {
$result = $this->test->name; $result = $this->test->name;
$expected = 'Test'; $expected = 'Test';
$this->assertEqual($result, $expected, "Identity test failed, got {$result}, expected {$expected}."); $this->assertEqual($result, $expected);
} }
} }
?> ?>

View file

@ -38,7 +38,7 @@ class RouterTest extends UnitTestCase {
function testReturnedInstanceReference() { function testReturnedInstanceReference() {
$router =& Router::getInstance(); $router =& Router::getInstance();
$router->testVar = 'test'; $router->testVar = 'test';
$this->assertIdentical($router, Router::getInstance(), "Instantiated Router object not referrentially equal to result of Router::getInstance()"); $this->assertIdentical($router, Router::getInstance());
unset($router->testVar); unset($router->testVar);
} }
@ -47,40 +47,40 @@ class RouterTest extends UnitTestCase {
$router->routes = array(); $router->routes = array();
$router->connect('/'); $router->connect('/');
$this->assertEqual($router->routes[0][0], '/', "Route map error for \"/\": expected '/', got '" . $router->routes[0][0] . "'"); $this->assertEqual($router->routes[0][0], '/');
$this->assertEqual($router->routes[0][1], '/^[\/]*$/', "Route map error for \"/\": expected '/^[\/]*$/', got '" . $router->routes[0][1] . "'"); $this->assertEqual($router->routes[0][1], '/^[\/]*$/');
$this->assertEqual($router->routes[0][2], array(), "Route map error for \"/\""); $this->assertEqual($router->routes[0][2], array());
$router->routes = array(); $router->routes = array();
$router->connect('/', array('controller' => 'testing')); $router->connect('/', array('controller' => 'testing'));
$this->assertTrue(is_array($router->routes[0][3]) && !empty($router->routes[0][3]), '/', "Route map error for \"/\" with default controller"); $this->assertTrue(is_array($router->routes[0][3]) && !empty($router->routes[0][3]));
$this->assertEqual($router->routes[0][3]['controller'], 'testing', "Route map error for \"/\" with default controller"); $this->assertEqual($router->routes[0][3]['controller'], 'testing');
$this->assertEqual($router->routes[0][3]['action'], 'index', "Route map error for \"/\" with default controller"); $this->assertEqual($router->routes[0][3]['action'], 'index');
$this->assertEqual(count($router->routes[0][3]), 3, "Route map error for \"/\" with default controller: defaults array length is ".count($router->routes[0][3]).', expected 2'); $this->assertEqual(count($router->routes[0][3]), 3);
$router->routes = array(); $router->routes = array();
$router->connect('/:controller', array('controller' => 'testing2')); $router->connect('/:controller', array('controller' => 'testing2'));
$this->assertTrue(is_array($router->routes[0][3]) && !empty($router->routes[0][3]), '/', "Route map error for \"/:controller\" with default controller"); $this->assertTrue(is_array($router->routes[0][3]) && !empty($router->routes[0][3]), '/');
$this->assertEqual($router->routes[0][3]['controller'], 'testing2', "Route map error for \"/:controller\" with default controller"); $this->assertEqual($router->routes[0][3]['controller'], 'testing2');
$this->assertEqual($router->routes[0][3]['action'], 'index', "Route map error for \"/:controller\" with default controller"); $this->assertEqual($router->routes[0][3]['action'], 'index');
$this->assertEqual(count($router->routes[0][3]), 3, "Route map error for \"/:controller\" with default controller: defaults array length is ".count($router->routes[0][3]).', expected 2'); $this->assertEqual(count($router->routes[0][3]), 3);
$router->routes = array(); $router->routes = array();
$router->connect('/:controller/:action', array('controller' => 'testing3')); $router->connect('/:controller/:action', array('controller' => 'testing3'));
$this->assertEqual($router->routes[0][0], '/:controller/:action', "Route map error for \"/:controller/:action\" with default controller"); $this->assertEqual($router->routes[0][0], '/:controller/:action');
$this->assertEqual($router->routes[0][1], '#^(?:\/([^\/]+))?(?:\/([^\/]+))?[\/]*$#', "Route map error for \"/:controller/:action\" with default controller"); $this->assertEqual($router->routes[0][1], '#^(?:\/([^\/]+))?(?:\/([^\/]+))?[\/]*$#');
$this->assertEqual($router->routes[0][2], array('controller', 'action'), "Route map error for \"/:controller\" with default controller: defaults array length is ".count($router->routes[0][3]).', expected 2'); $this->assertEqual($router->routes[0][2], array('controller', 'action'));
$this->assertEqual($router->routes[0][3], array('controller' => 'testing3', 'action' => 'index', 'plugin' => null), "Route map error for \"/:controller/:action\" with default controller"); $this->assertEqual($router->routes[0][3], array('controller' => 'testing3', 'action' => 'index', 'plugin' => null));
$router->routes = array(); $router->routes = array();
$router->connect('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => $router->__named['ID'])); $router->connect('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => $router->__named['ID']));
$this->assertEqual($router->routes[0][0], '/:controller/:action/:id', "Route map error for \"/:controller/:action/:id\" with default controller and ID not required"); $this->assertEqual($router->routes[0][0], '/:controller/:action/:id');
$this->assertEqual($router->routes[0][1], '#^(?:\/([^\/]+))?(?:\/([^\/]+))?(?:\/([0-9]+))?[\/]*$#', "Route map error for \"/:controller/:action/:id\" with default controller and ID not required"); $this->assertEqual($router->routes[0][1], '#^(?:\/([^\/]+))?(?:\/([^\/]+))?(?:\/([0-9]+))?[\/]*$#');
$this->assertEqual($router->routes[0][2], array('controller', 'action', 'id'), "Route map error for \"/:controller/:action/:id\" with default controller"); $this->assertEqual($router->routes[0][2], array('controller', 'action', 'id'));
$router->routes = array(); $router->routes = array();
$router->connect('/:controller/:action/:id', array('controller' => 'testing4'), array('id' => $router->__named['ID'])); $router->connect('/:controller/:action/:id', array('controller' => 'testing4'), array('id' => $router->__named['ID']));
$this->assertEqual($router->routes[0][1], '#^(?:\/([^\/]+))?(?:\/([^\/]+))?(?:\/([0-9]+))[\/]*$#', "Route map error for \"/:controller/:action/:id\" with default controller and ID required"); $this->assertEqual($router->routes[0][1], '#^(?:\/([^\/]+))?(?:\/([^\/]+))?(?:\/([0-9]+))[\/]*$#');
} }
function testRouterIdentity() { function testRouterIdentity() {
@ -90,7 +90,7 @@ class RouterTest extends UnitTestCase {
$router->routes = $router->__paths = $router->__params = $router->__currentRoute = array(); $router->routes = $router->__paths = $router->__params = $router->__currentRoute = array();
$router->__parseExtensions = false; $router->__parseExtensions = false;
$router2 = new Router(); $router2 = new Router();
$this->assertEqual(get_object_vars($router), get_object_vars($router2), "Router identity crisis"); $this->assertEqual(get_object_vars($router), get_object_vars($router2));
} }
function testUrlGeneration() { function testUrlGeneration() {
@ -102,32 +102,32 @@ class RouterTest extends UnitTestCase {
$router->connect('/', array('controller'=>'pages', 'action'=>'display', 'home')); $router->connect('/', array('controller'=>'pages', 'action'=>'display', 'home'));
$out = $router->url(array('controller'=>'pages', 'action'=>'display', 'home')); $out = $router->url(array('controller'=>'pages', 'action'=>'display', 'home'));
$this->assertEqual($out, '/', "Router URL generation failed: expected '/', got '{$out}'"); $this->assertEqual($out, '/');
$router->connect('/pages/*', array('controller'=>'pages', 'action'=>'display')); $router->connect('/pages/*', array('controller'=>'pages', 'action'=>'display'));
$out = $router->url(array('controller'=>'pages', 'action'=>'display', 'about')); $out = $router->url(array('controller'=>'pages', 'action'=>'display', 'about'));
$expected = '/pages/about'; $expected = '/pages/about';
$this->assertEqual($out, $expected, "Router URL generation failed: expected '{$expected}' got '{$out}'"); $this->assertEqual($out, $expected);
$router->connect('/:plugin/:controller/*', array('plugin'=>'cake_plugin', 'controller'=>'posts', 'action'=>'view', '1')); $router->connect('/:plugin/:controller/*', array('plugin'=>'cake_plugin', 'controller'=>'posts', 'action'=>'view', '1'));
$out = $router->url(array('plugin'=>'cake_plugin', 'controller'=>'posts', '1')); $out = $router->url(array('plugin'=>'cake_plugin', 'controller'=>'posts', '1'));
$expected = '/cake_plugin/posts/'; $expected = '/cake_plugin/posts/';
$this->assertEqual($out, $expected, "Router URL generation failed: expected '{$expected}' got '{$out}'"); $this->assertEqual($out, $expected);
$router->connect('/:controller/:action/:id', array(), array('id' => '1')); $router->connect('/:controller/:action/:id', array(), array('id' => '1'));
$out = $router->url(array('controller'=>'posts', 'action'=>'view', '1')); $out = $router->url(array('controller'=>'posts', 'action'=>'view', '1'));
$expected = '/posts/view/1'; $expected = '/posts/view/1';
$this->assertEqual($out, $expected, "Router URL generation failed: expected '{$expected}' got '{$out}'"); $this->assertEqual($out, $expected);
$router->connect('/:controller/:id', array('action' => 'view'), array('id' => '1')); $router->connect('/:controller/:id', array('action' => 'view'), array('id' => '1'));
$out = $router->url(array('controller'=>'posts', '1')); $out = $router->url(array('controller'=>'posts', '1'));
$expected = '/posts/1'; $expected = '/posts/1';
$this->assertEqual($out, $expected, "Router URL generation failed: expected '{$expected}' got '{$out}'"); $this->assertEqual($out, $expected);
$out = $router->url(array('controller' => 'posts', 'action'=>'index', '0')); $out = $router->url(array('controller' => 'posts', 'action'=>'index', '0'));
$expected = '/posts/index/0'; $expected = '/posts/index/0';
$this->assertEqual($out, $expected, "Router URL generation failed: expected '{$expected}' got '{$out}'"); $this->assertEqual($out, $expected);
} }
@ -135,12 +135,11 @@ class RouterTest extends UnitTestCase {
if (PHP5) { if (PHP5) {
$router = Router::getInstance(); $router = Router::getInstance();
$router->reload(); $router->reload();
$this->assertFalse($router->__parseExtensions, "Router::__parseExtensions not defaulting correctly"); $this->assertFalse($router->__parseExtensions);
$router->parseExtensions(); $router->parseExtensions();
$this->assertTrue($router->__parseExtensions, "Router::parseExtensions() not enabling extension parsing"); $this->assertTrue($router->__parseExtensions);
} }
} }
} }
?>
?>

View file

@ -40,24 +40,23 @@ class SocketTest extends UnitTestCase {
} }
function testSocketConnection() { function testSocketConnection() {
$this->assertTrue($this->socket->connected, 'Socket connection error: socket not connected when it should be'); $this->assertTrue($this->socket->connected);
$this->socket->disconnect(); $this->socket->disconnect();
$this->assertFalse($this->socket->connected, 'Socket connection error: socket connected when it should not be'); $this->assertFalse($this->socket->connected);
$this->socket->connect(); $this->socket->connect();
$this->assertTrue($this->socket->connected, 'Socket connection error: socket not connected when it should be'); $this->assertTrue($this->socket->connected);
} }
function testSocketHost() { function testSocketHost() {
$this->assertEqual($this->socket->address(), '127.0.0.1', 'Socket address does not resolve to localhost IP (127.0.0.1)'); $this->assertEqual($this->socket->address(), '127.0.0.1');
$this->assertEqual($this->socket->addresses(), array('127.0.0.1'), 'Socket address group does not resolve to localhost IP (127.0.0.1)'); $this->assertEqual($this->socket->addresses(), array('127.0.0.1'));
$this->assertEqual($this->socket->host(), 'localhost', 'Socket host is not localhost'); $this->assertEqual($this->socket->host(), 'localhost');
$this->assertEqual($this->socket->lastError(), null, 'Socket connection error, expected null'); $this->assertEqual($this->socket->lastError(), null);
} }
function testSocketWriting() { function testSocketWriting() {
$request = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n"; $request = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n";
$this->assertTrue($this->socket->write($request), 'Couldn\'t write to socket'); $this->assertTrue($this->socket->write($request));
} }
} }
?> ?>

File diff suppressed because it is too large Load diff

View file

@ -50,12 +50,11 @@ class AjaxTest extends UnitTestCase {
function testDraggable() { function testDraggable() {
$result = $this->ajax->drag('id', array('handle' => 'other_id')); $result = $this->ajax->drag('id', array('handle' => 'other_id'));
$expected = '<script type="text/javascript">new Draggable(\'id\', {handle:\'other_id\'});</script>'; $expected = '<script type="text/javascript">new Draggable(\'id\', {handle:\'other_id\'});</script>';
$this->assertEqual($result, $expected, "Error generating script.aculo.us draggable object, expected '{$expected}', got '{$result}'."); $this->assertEqual($result, $expected);
} }
function tearDown() { function tearDown() {
unset($this->ajax); unset($this->ajax);
} }
} }
?> ?>

View file

@ -37,6 +37,7 @@
h3 {font-size: 150%} h3 {font-size: 150%}
a {font-size: 120%} a {font-size: 120%}
li {line-height: 140%} li {line-height: 140%}
.fail { background-color: inherit; color: red; }
</style> </style>
</head> </head>
<body> <body>
@ -46,4 +47,3 @@
</div> </div>
<div id="content"> <div id="content">
<h2>CakePHP Test Suite v 1.2.0.0</h2> <h2>CakePHP Test Suite v 1.2.0.0</h2>