Adding CakeFixture Test Case

Adding TestSuite group test
Fixing documentation and removing unecessary ife() calls from CakeTestFixture.
Made CodeCoverage test run nicely in group tests

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7538 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-09-01 14:21:57 +00:00
parent 26e2747180
commit 91a6508a26
4 changed files with 322 additions and 9 deletions

View file

@ -0,0 +1,233 @@
<?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
* @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
*/
App::import('Core', 'DboSource');
/**
* CakeFixture Test Fixture
*
* @package cake
* @subpackage cake.cake.tests.cases.libs
*/
class CakeTestFixtureTestFixture extends CakeTestFixture {
/**
* name Property
*
* @var string
*/
var $name = 'FixtureTest';
/**
* table property
*
* @var string
*/
var $table = 'fixture_tests';
/**
* Fields array
*
* @var array
*/
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'text', 'length' => '255'),
'created' => array('type' => 'datetime'),
);
/**
* Records property
*
* @var array
*/
var $records = array(
array('name' => 'Gandalf'),
array('name' => 'Captain Picard'),
array('name' => 'Chewbacca')
);
}
/**
* Import Fixture Test Fixture
*
* @package cake
* @subpackage cake.cake.tests.cases.libs
*/
class CakeTestFixtureImportFixture extends CakeTestFixture {
/**
* Name property
*
* @var string
*/
var $name = 'ImportFixture';
/**
* Import property
*
* @var array
*/
var $import = array('table' => 'fixture_tests', 'connection' => 'test_suite');
}
/**
* Fixture Test Case Model
*
* @package default
* @subpackage cake.cake.tests.cases.libs.
**/
class FixtureImportTestModel extends Model {
var $name = 'FixtureImport';
var $useTable = 'fixture_tests';
var $useDbConfig = 'test_suite';
}
Mock::generate('DboSource', 'FixtureMockDboSource');
/**
* Test case for CakeTestFixture
*
* @package cake
* @subpackage cake.cake.tests.cases.libs
*/
class CakeTestFixtureTest extends CakeTestCase {
function setUp() {
$this->criticDb =& new FixtureMockDboSource();
$this->criticDb->fullDebug = true;
}
/**
* testInit
*
* @access public
* @return void
*/
function testInit() {
$Fixture =& new CakeTestFixtureTestFixture();
unset($Fixture->table);
$Fixture->init();
$this->assertEqual($Fixture->table, 'fixture_tests');
$this->assertEqual($Fixture->primaryKey, 'id');
$Fixture =& new CakeTestFixtureTestFixture();
$Fixture->primaryKey = 'my_random_key';
$Fixture->init();
$this->assertEqual($Fixture->primaryKey, 'my_random_key');
$this->_initDb();
$Source =& new CakeTestFixtureTestFixture();
$Source->create($this->db);
$Source->insert($this->db);
$Fixture =& new CakeTestFixtureImportFixture();
$expected = array('id', 'name', 'created');
$this->assertEqual(array_keys($Fixture->fields), $expected);
$Fixture->fields = $Fixture->records = null;
$Fixture->import = array('table' => 'fixture_tests', 'connection' => 'test_suite', 'records' => true);
$Fixture->init();
$this->assertEqual(count($Fixture->records), count($Source->records));
$Fixture =& new CakeTestFixtureImportFixture();
$Fixture->fields = $Fixture->records = null;
$Fixture->import = array('FixtureImport');
$Fixture->init();
$Source->drop($this->db);
}
/**
* test create method
*
* @return void
**/
function testCreate() {
$Fixture =& new CakeTestFixtureTestFixture();
$this->criticDb->expectAtLeastOnce('execute');
$this->criticDb->expectAtLeastOnce('createSchema');
$return = $Fixture->create($this->criticDb);
$this->assertTrue($this->criticDb->fullDebug);
$this->assertTrue($return);
unset($Fixture->fields);
$return = $Fixture->create($this->criticDb);
$this->assertFalse($return);
}
/**
* test the insert method
*
* @return void
**/
function testInsert() {
$Fixture =& new CakeTestFixtureTestFixture();
$this->criticDb->setReturnValue('insertMulti', true);
$this->criticDb->expectAtLeastOnce('insertMulti');
$return = $Fixture->insert($this->criticDb);
$this->assertTrue($this->criticDb->fullDebug);
$this->assertTrue($return);
}
/**
* Test the drop method
*
* @return void
**/
function testDrop() {
$Fixture =& new CakeTestFixtureTestFixture();
$this->criticDb->setReturnValueAt(0, 'execute', true);
$this->criticDb->expectAtLeastOnce('execute');
$this->criticDb->expectAtLeastOnce('dropSchema');
$return = $Fixture->drop($this->criticDb);
$this->assertTrue($this->criticDb->fullDebug);
$this->assertTrue($return);
$this->criticDb->setReturnValueAt(1, 'execute', false);
$return = $Fixture->drop($this->criticDb);
$this->assertFalse($return);
}
/**
* Test the truncate method.
*
* @return void
**/
function testTruncate() {
$Fixture =& new CakeTestFixtureTestFixture();
$this->criticDb->expectAtLeastOnce('truncate');
$Fixture->truncate($this->criticDb);
$this->assertTrue($this->criticDb->fullDebug);
}
/**
* tearDown
*
* @access public
* @return void
*/
function tearDown() {
unset($this->criticDb);
}
}
?>

View file

@ -35,7 +35,26 @@ require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_reporter.php';
* @package cake.tests
* @subpackage cake.tests.cases.libs
*/
class CodeCoverageManagerTest extends UnitTestCase {
class CodeCoverageManagerTest extends CakeTestCase {
/**
* startTest Method
* Store reference of $_GET to restore later.
*
* @return void
**/
function startCase() {
$this->_get = $_GET;
}
/**
* End Case - restore GET vars.
*
* @return void
**/
function endCase() {
$_GET = $this->_get;
}
/**
* Skip if XDebug not installed
*

View file

@ -0,0 +1,63 @@
<?php
/* SVN FILE: $Id$ */
/**
* Test Suite Test Group
*
* 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
*/
/** Test Suite Test Group
*
* This test group will run the test cases for the test suite classes.
*
* @package cake.tests
* @subpackage cake.tests.groups
*/
/**
* TestSuiteGroupTest class
*
* @package cake
* @subpackage cake.tests.groups
*/
class TestSuiteGroupTest extends GroupTest {
/**
* label property
*
* @var string 'Socket and HttpSocket tests'
* @access public
*/
var $label = 'Test Suite Tests';
/**
* TestSuiteGroupTest method
*
* @access public
* @return void
*/
function TestSuiteGroupTest() {
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'code_coverage_manager');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'cake_test_case');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'cake_test_fixture');
}
}
?>

View file

@ -49,11 +49,9 @@ class CakeTestFixture extends Object {
/**
* Instantiate the fixture.
*
* @param object Cake's DBO driver (e.g: DboMysql).
*
* @access public
*/
function __construct(&$db) {
function __construct() {
App::import('Model', 'Schema');
$this->Schema = new CakeSchema(array('name' => 'TestSuite', 'connection' => 'test_suite'));
@ -69,10 +67,10 @@ class CakeTestFixture extends Object {
function init() {
if (isset($this->import) && (is_string($this->import) || is_array($this->import))) {
$import = array();
if (is_string($this->import) || is_array($this->import) && isset($this->import['model'])) {
$import = array_merge(array('records' => false), ife(is_array($this->import), $this->import, array()));
$import['model'] = ife(is_array($this->import), $this->import['model'], $this->import);
$import = array_merge(array('records' => false), is_array($this->import) ? $this->import : array());
$import['model'] = is_array($this->import) ? $this->import['model'] : $this->import;
} elseif (isset($this->import['table'])) {
$import = array_merge(array('connection' => 'default', 'records' => false), $this->import);
}
@ -98,7 +96,7 @@ class CakeTestFixture extends Object {
$this->fields = $model->schema(true);
}
if ($import['records'] !== false && isset($model) && isset($db)) {
if (isset($import['records']) && $import['records'] !== false && isset($model) && isset($db)) {
$this->records = array();
$query = array(
@ -191,7 +189,7 @@ class CakeTestFixture extends Object {
* truncate.
*
* @param object $db A reference to a db instance
* @return void
* @return boolean
* @access public
*/
function truncate(&$db) {