diff --git a/cake/tests/fixtures/article_fixture.php b/cake/tests/fixtures/article_fixture.php index efe5c2261..84a02447e 100644 --- a/cake/tests/fixtures/article_fixture.php +++ b/cake/tests/fixtures/article_fixture.php @@ -1,5 +1,37 @@ + * 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.fixtures + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * Short description for class. + * + * @package cake.tests + * @subpackage cake.tests.fixtures + */ class ArticleFixture extends CakeTestFixture { var $name = 'Article'; var $fields = array( diff --git a/cake/tests/fixtures/articles_tag_fixture.php b/cake/tests/fixtures/articles_tag_fixture.php index d5cafec64..a0a6d2f15 100644 --- a/cake/tests/fixtures/articles_tag_fixture.php +++ b/cake/tests/fixtures/articles_tag_fixture.php @@ -1,5 +1,37 @@ + * 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.fixtures + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * Short description for class. + * + * @package cake.tests + * @subpackage cake.tests.fixtures + */ class ArticlesTagFixture extends CakeTestFixture { var $name = 'ArticlesTag'; var $fields = array( diff --git a/cake/tests/fixtures/attachment_fixture.php b/cake/tests/fixtures/attachment_fixture.php index 11ceb6d2f..37085a2ef 100644 --- a/cake/tests/fixtures/attachment_fixture.php +++ b/cake/tests/fixtures/attachment_fixture.php @@ -1,5 +1,37 @@ + * 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.fixtures + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * Short description for class. + * + * @package cake.tests + * @subpackage cake.tests.fixtures + */ class AttachmentFixture extends CakeTestFixture { var $name = 'Attachment'; var $fields = array( diff --git a/cake/tests/fixtures/category_fixture.php b/cake/tests/fixtures/category_fixture.php index 53d67d120..d2621083e 100644 --- a/cake/tests/fixtures/category_fixture.php +++ b/cake/tests/fixtures/category_fixture.php @@ -1,5 +1,37 @@ + * 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.fixtures + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * Short description for class. + * + * @package cake.tests + * @subpackage cake.tests.fixtures + */ class CategoryFixture extends CakeTestFixture { var $name = 'Category'; var $fields = array( diff --git a/cake/tests/fixtures/comment_fixture.php b/cake/tests/fixtures/comment_fixture.php index 6f047529a..9f2eacece 100644 --- a/cake/tests/fixtures/comment_fixture.php +++ b/cake/tests/fixtures/comment_fixture.php @@ -1,5 +1,37 @@ + * 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.fixtures + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * Short description for class. + * + * @package cake.tests + * @subpackage cake.tests.fixtures + */ class CommentFixture extends CakeTestFixture { var $name = 'Comment'; var $fields = array( diff --git a/cake/tests/fixtures/tag_fixture.php b/cake/tests/fixtures/tag_fixture.php index 5dca2414b..0a477d748 100644 --- a/cake/tests/fixtures/tag_fixture.php +++ b/cake/tests/fixtures/tag_fixture.php @@ -1,5 +1,37 @@ + * 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.fixtures + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * Short description for class. + * + * @package cake.tests + * @subpackage cake.tests.fixtures + */ class TagFixture extends CakeTestFixture { var $name = 'Tag'; var $fields = array( diff --git a/cake/tests/fixtures/user_fixture.php b/cake/tests/fixtures/user_fixture.php index b0849456d..31c80cdf1 100644 --- a/cake/tests/fixtures/user_fixture.php +++ b/cake/tests/fixtures/user_fixture.php @@ -1,5 +1,37 @@ + * 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.fixtures + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * Short description for class. + * + * @package cake.tests + * @subpackage cake.tests.fixtures + */ class UserFixture extends CakeTestFixture { var $name = 'User'; var $fields = array( diff --git a/cake/tests/lib/cake_test_case.php b/cake/tests/lib/cake_test_case.php index 25c40b28d..d78962b01 100644 --- a/cake/tests/lib/cake_test_case.php +++ b/cake/tests/lib/cake_test_case.php @@ -1,32 +1,62 @@ + * 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 + * @subpackage cake.cake.tests.libs + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_model.php'; require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_fixture.php'; - vendor('simpletest'.DS.'unit_tester'); - +/** + * Short description for class. + * + * @package cake + * @subpackage cake.cake.tests.lib + */ class CakeTestCase extends UnitTestCase { - /** - * Announces the start of a test. - * - * @param string $method Test method just started. - * - * @access public - */ +/** + * Announces the start of a test. + * + * @param string $method Test method just started. + * + * @access public + */ function before($method) { parent::before($method); - + if (isset($this->fixtures) && (!is_array($this->fixtures) || empty($this->fixtures))) { unset($this->fixtures); } - + // Set up DB connection if (isset($this->fixtures) && low($method) == 'start') { // Try for test DB restore_error_handler(); @$db =& ConnectionManager::getDataSource('test'); set_error_handler('simpleTestErrorHandler'); - + // Try for default DB if (!$db->isConnected()) { $db =& ConnectionManager::getDataSource('default'); @@ -35,22 +65,22 @@ class CakeTestCase extends UnitTestCase { // Add test prefix $config = $db->config; $config['prefix'] .= 'test_suite_'; - + // Set up db connection ConnectionManager::create('test_suite', $config); - + // Get db connection $this->db =& ConnectionManager::getDataSource('test_suite'); $this->db->fullDebug = false; - + $this->_loadFixtures(); } - + // Create records if (isset($this->_fixtures) && isset($this->db) && !in_array(low($method), array('start', 'end'))) { foreach($this->_fixtures as $fixture) { $inserts = $fixture->insert(); - + if (isset($inserts) && !empty($inserts)) { foreach($inserts as $query) { if (isset($query) && $query !== false) { @@ -61,99 +91,95 @@ class CakeTestCase extends UnitTestCase { } } } - - /** - * Runs as first test to create tables. - * - * @access public - */ +/** + * Runs as first test to create tables. + * + * @access public + */ function start() { if (isset($this->_fixtures) && isset($this->db)) { foreach($this->_fixtures as $fixture) { $query = $fixture->create(); - + if (isset($query) && $query !== false) { $this->db->_execute($query); } } } } - - /** - * Runs as last test to drop tables. - * - * @access public - */ +/** + * Runs as last test to drop tables. + * + * @access public + */ function end() { if (isset($this->_fixtures) && isset($this->db)) { foreach(array_reverse($this->_fixtures) as $fixture) { $query = $fixture->drop(); - + if (isset($query) && $query !== false) { $this->db->_execute($query); } } } } - - /** - * Announces the end of a test. - * - * @param string $method Test method just finished. - * - * @access public - */ + +/** + * Announces the end of a test. + * + * @param string $method Test method just finished. + * + * @access public + */ function after($method) { if (isset($this->_fixtures) && isset($this->db) && !in_array(low($method), array('start', 'end'))) { foreach($this->_fixtures as $fixture) { $query = $fixture->truncate(); - + if (isset($query) && $query !== false) { $this->db->_execute($query); } } } - + parent::after($method); } - - /** - * Gets a list of test names. Normally that will be all internal methods that start with the - * name "test". This method should be overridden if you want a different rule. - * - * @return array List of test names. - * - * @access public - */ +/** + * Gets a list of test names. Normally that will be all internal methods that start with the + * name "test". This method should be overridden if you want a different rule. + * + * @return array List of test names. + * + * @access public + */ function getTests() { $methods = parent::getTests(); - + if (isset($this->fixtures)) { $methods = am(am(array('start'), $methods), array('end')); } - + return $methods; } - - /** - * Load fixtures specified in var $fixtures. - * - * @access private - */ +/** + * Load fixtures specified in var $fixtures. + * + * @access private + */ function _loadFixtures() { if (!isset($this->fixtures) || empty($this->fixtures)) { return; } - + if (!is_array($this->fixtures)) { $this->fixtures = array( $this->fixtures ); } - + $this->_fixtures = array(); - + foreach($this->fixtures as $index => $fixture) { $fixtureFile = null; - + if (strpos($fixture, 'core.') === 0) { $fixture = substr($fixture, strlen('core.')); $fixturePaths = array( @@ -170,27 +196,26 @@ class CakeTestCase extends UnitTestCase { CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'tests' . DS . 'fixtures' ); } - + foreach($fixturePaths as $path) { if (is_readable($path . DS . $fixture . '_fixture.php')) { $fixtureFile = $path . DS . $fixture . '_fixture.php'; break; } } - + if (isset($fixtureFile)) { require_once($fixtureFile); - + $fixtureClass = Inflector::camelize($fixture) . 'Fixture'; - + $this->_fixtures[$this->fixtures[$index]] =& new $fixtureClass($this->db); } } - + if (empty($this->_fixtures)) { unset($this->_fixtures); } } } - ?> \ No newline at end of file diff --git a/cake/tests/lib/cake_test_fixture.php b/cake/tests/lib/cake_test_fixture.php index e79819878..96291419a 100644 --- a/cake/tests/lib/cake_test_fixture.php +++ b/cake/tests/lib/cake_test_fixture.php @@ -1,154 +1,180 @@ + * 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 + * @subpackage cake.cake.tests.libs + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * Short description for class. + * + * @package cake + * @subpackage cake.cake.tests.lib + */ class CakeTestFixture extends Object { var $db = null; - - /** - * Instantiate the fixture. - * - * @param object Cake's DBO driver (e.g: DboMysql). - * - * @access public - */ +/** + * Instantiate the fixture. + * + * @param object Cake's DBO driver (e.g: DboMysql). + * + * @access public + */ function __construct(&$db) { $this->db =& $db; - + if (!isset($this->table)) { $this->table = Inflector::underscore(Inflector::pluralize($this->name)); } - + if (!isset($this->primaryKey) && isset($this->fields['id'])) { $this->primaryKey = 'id'; } - + if (isset($this->primaryKey) && !is_array($this->primaryKey)) { $this->primaryKey = array( $this->primaryKey ); } } - - /** - * Run before all tests execute, should return SQL statement to create table for this fixture. - * - * @return string SQL CREATE TABLE statement, false if not applicable. - * - * @access public - */ +/** + * Run before all tests execute, should return SQL statement to create table for this fixture. + * + * @return string SQL CREATE TABLE statement, false if not applicable. + * + * @access public + */ function create() { if (!isset($this->_create)) { if (!isset($this->fields) || empty($this->fields)) { return null; } - + $create = 'CREATE TABLE ' . $this->db->name($this->db->config['prefix'] . $this->table) . ' (' . "\n"; - + foreach($this->fields as $field => $attributes) { if (!is_array($attributes)) { $attributes = array('type' => $attributes); } else if (isset($attributes['key']) && low($attributes['key']) == 'primary' && !isset($this->primaryKey)) { $this->primaryKey = array ( $field ); } - + $column = array($field, $attributes['type']); unset($attributes['type']); - + if (!empty($attributes)) { $column = array_merge($column, $attributes); } - + $create .= $this->db->generateColumnSchema($column) . ',' . "\n"; } - + if (isset($this->primaryKey)) { foreach($this->primaryKey as $index => $field) { $this->primaryKey[$index] = $this->db->name($field); } } - + if (!isset($this->primaryKey)) { $create = substr($create, 0, -1); } else { $create .= 'PRIMARY KEY(' . implode(', ', $this->primaryKey) . ')' . "\n"; } - + $create .= ')'; - + $this->_create = $create; } - + return $this->_create; } - - /** - * Run after all tests executed, should return SQL statement to drop table for this fixture. - * - * @return string SQL DROP TABLE statement, false if not applicable. - * - * @access public - */ +/** + * Run after all tests executed, should return SQL statement to drop table for this fixture. + * + * @return string SQL DROP TABLE statement, false if not applicable. + * + * @access public + */ function drop() { if (!isset($this->_drop)) { $this->_drop = 'DROP TABLE ' . $this->db->name($this->db->config['prefix'] . $this->table); } - + return $this->_drop; } - - /** - * Run after each tests is executed, should return SQL statement to empty of records the table for this fixture. - * - * @return string SQL TRUNCATE TABLE statement, false if not applicable. - * - * @access public - */ +/** + * Run after each tests is executed, should return SQL statement to empty of records the table for this fixture. + * + * @return string SQL TRUNCATE TABLE statement, false if not applicable. + * + * @access public + */ function truncate() { if (!isset($this->_truncate)) { $this->_truncate = 'TRUNCATE ' . $this->db->name($this->db->config['prefix'] . $this->table); } - + return $this->_truncate; } - - /** - * Run before each tests is executed, should return a set of SQL statements to insert records for the table of this fixture. - * - * @return array SQL INSERT statements, empty array if not applicable. - * - * @access public - */ +/** + * Run before each tests is executed, should return a set of SQL statements to insert records for the table of this fixture. + * + * @return array SQL INSERT statements, empty array if not applicable. + * + * @access public + */ function insert() { if (!isset($this->_insert)) { $inserts = array(); - + if (isset($this->records) && !empty($this->records)) { foreach($this->records as $record) { $fields = array_keys($record); $values = array_values($record); - + $insert = 'INSERT INTO ' . $this->db->name($this->db->config['prefix'] . $this->table) . '('; - + foreach($fields as $field) { - $insert .= $this->db->name($field) . ','; + $insert .= $this->db->name($field) . ','; } $insert = substr($insert, 0, -1); - + $insert .= ') VALUES ('; - + foreach($values as $values) { - $insert .= $this->db->value($values) . ','; + $insert .= $this->db->value($values) . ','; } $insert = substr($insert, 0, -1); - + $insert .= ')'; - + $inserts[] = $insert; } } - + $this->_insert = $inserts; } - + return $this->_insert; } } - ?> \ No newline at end of file diff --git a/cake/tests/lib/cake_test_model.php b/cake/tests/lib/cake_test_model.php index d95b93404..21fa44ce4 100644 --- a/cake/tests/lib/cake_test_model.php +++ b/cake/tests/lib/cake_test_model.php @@ -1,9 +1,39 @@ + * 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 + * @subpackage cake.cake.tests.libs + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ require_once LIBS.'model'.DS.'model.php'; - +/** + * Short description for class. + * + * @package cake + * @subpackage cake.cake.tests.lib + */ class CakeTestModel extends Model { var $useDbConfig = 'test_suite'; } - ?> \ No newline at end of file