2005-06-18 23:26:35 +00:00
|
|
|
<?php
|
2005-07-04 02:59:39 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// + $Id:$
|
|
|
|
// +------------------------------------------------------------------+ //
|
|
|
|
// + Cake PHP : Rapid Development Framework <http://www.cakephp.org/> + //
|
|
|
|
// + Copyright: (c) 2005, CakePHP Authors/Developers + //
|
|
|
|
// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
|
|
|
|
// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
|
|
|
|
// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
|
|
|
|
// +------------------------------------------------------------------+ //
|
|
|
|
// + Licensed under The MIT License + //
|
|
|
|
// + Redistributions of files must retain the above copyright notice. + //
|
|
|
|
// + See: http://www.opensource.org/licenses/mit-license.php + //
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @author CakePHP Authors/Developers
|
|
|
|
* @copyright Copyright (c) 2005, CakePHP Authors/Developers
|
|
|
|
* @link https://trac.cakephp.org/wiki/Authors Authors/Developers
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.libs
|
|
|
|
* @since CakePHP v 0.2.9
|
|
|
|
* @version $Revision:$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date:$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic defines
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
uses('dbo_factory');
|
|
|
|
|
|
|
|
class DboTest extends UnitTestCase
|
|
|
|
{
|
2005-07-04 02:59:39 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var unknown_type
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
var $dbo;
|
|
|
|
|
2005-07-04 02:59:39 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return DboTest
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function DboTest()
|
|
|
|
{
|
|
|
|
$this->UnitTestCase('DBO test');
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:59:39 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function setUp()
|
|
|
|
{
|
2005-06-23 14:13:50 +00:00
|
|
|
$this->dbo = DBO::getInstance('test');
|
2005-06-18 23:26:35 +00:00
|
|
|
|
|
|
|
$this->createTemporaryTable();
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:59:39 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function tearDown()
|
|
|
|
{
|
|
|
|
if(!$this->dbo) return false;
|
|
|
|
|
|
|
|
$this->dropTemporaryTable();
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:59:39 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function createTemporaryTable()
|
|
|
|
{
|
|
|
|
if(!$this->dbo) return false;
|
|
|
|
|
|
|
|
if($this->dbo->config['driver'] == 'postgres')
|
|
|
|
$sql = 'CREATE TABLE __test(id serial NOT NULL, body CHARACTER VARYING(255))';
|
|
|
|
else
|
|
|
|
$sql = 'CREATE TABLE __test(id INT UNSIGNED PRIMARY KEY, body VARCHAR(255))';
|
|
|
|
|
|
|
|
return $this->dbo->query($sql);
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:59:39 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function dropTemporaryTable()
|
|
|
|
{
|
|
|
|
if(!$this->dbo) return false;
|
|
|
|
|
|
|
|
return $this->dbo->query("DROP TABLE __test");
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:59:39 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function testHasImplementation()
|
|
|
|
{
|
|
|
|
if(!$this->dbo) return false;
|
|
|
|
|
|
|
|
$functions = array(
|
|
|
|
'connect',
|
|
|
|
'disconnect',
|
|
|
|
'execute',
|
|
|
|
'fetchRow',
|
|
|
|
'tables',
|
|
|
|
'fields',
|
|
|
|
'prepare',
|
|
|
|
'lastError',
|
|
|
|
'lastAffected',
|
|
|
|
'lastNumRows',
|
|
|
|
'lastInsertId'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($functions as $function)
|
|
|
|
{
|
|
|
|
$this->assertTrue(method_exists($this->dbo, $function));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:59:39 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function testConnectivity()
|
|
|
|
{
|
|
|
|
if(!$this->dbo) return false;
|
|
|
|
|
|
|
|
$this->assertTrue($this->dbo->connected);
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:59:39 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function testFields()
|
|
|
|
{
|
|
|
|
if(!$this->dbo) return false;
|
|
|
|
|
|
|
|
$fields = $this->dbo->fields('__test');
|
|
|
|
$this->assertEqual(count($fields), 2, 'equals');
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:59:39 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function testTables()
|
|
|
|
{
|
|
|
|
if(!$this->dbo) return false;
|
|
|
|
|
|
|
|
$this->assertTrue(in_array('__test', $this->dbo->tables()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|