2014-02-14 22:08:19 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
|
|
|
* Free Query Builder / Database Abstraction Layer
|
|
|
|
*
|
|
|
|
* @package Query
|
|
|
|
* @author Timothy J. Warren
|
2014-02-18 15:18:01 -05:00
|
|
|
* @copyright Copyright (c) 2012 - 2014
|
2014-02-14 22:08:19 -05:00
|
|
|
* @link https://github.com/aviat4ion/Query
|
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2014-06-09 17:02:14 -04:00
|
|
|
/**
|
|
|
|
* Quercus detection for workarounds
|
|
|
|
*/
|
|
|
|
if ( ! defined('IS_QUERCUS'))
|
|
|
|
{
|
|
|
|
if ( ! isset($_SERVER_SOFTWARE))
|
|
|
|
{
|
|
|
|
define('IS_QUERCUS', FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$test = strpos($_SERVER["SERVER_SOFTWARE"],'Quercus') !== FALSE;
|
|
|
|
define('IS_QUERCUS', $test);
|
|
|
|
unset($test);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
/**
|
|
|
|
* Base class for TestCases
|
|
|
|
*/
|
|
|
|
class Query_TestCase extends PHPUnit_Framework_TestCase {
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
/**
|
|
|
|
* Wrapper for Simpletest's assertEqual
|
2014-02-21 15:02:41 -05:00
|
|
|
*
|
2014-02-14 22:08:19 -05:00
|
|
|
* @param mixed $expected
|
|
|
|
* @param mixed $actual
|
|
|
|
* @param string $message
|
|
|
|
*/
|
|
|
|
public function assertEqual($expected, $actual, $message='')
|
|
|
|
{
|
|
|
|
$this->assertEquals($expected, $actual, $message);
|
|
|
|
}
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
/**
|
|
|
|
* Wrapper for SimpleTest's assertIsA
|
|
|
|
*
|
|
|
|
* @param object $object
|
|
|
|
* @param string $type
|
|
|
|
* @param string $message
|
|
|
|
*/
|
|
|
|
public function assertIsA($object, $type, $message='')
|
|
|
|
{
|
|
|
|
$this->assertTrue(is_a($object, $type), $message);
|
|
|
|
}
|
2014-02-21 15:02:41 -05:00
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
/**
|
|
|
|
* Implementation of SimpleTest's assertReference
|
2014-02-21 15:02:41 -05:00
|
|
|
*
|
2014-02-14 22:08:19 -05:00
|
|
|
* @param mixed $first
|
|
|
|
* @param mixed $second
|
|
|
|
* @param string $message
|
|
|
|
*/
|
|
|
|
public function assertReference($first, $second, $message='')
|
|
|
|
{
|
2014-02-21 15:02:41 -05:00
|
|
|
if (is_object($first))
|
2014-02-14 22:08:19 -05:00
|
|
|
{
|
|
|
|
$res = ($first === $second);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$temp = $first;
|
|
|
|
$first = uniqid("test");
|
|
|
|
$is_ref = ($first === $second);
|
|
|
|
$first = $temp;
|
2014-02-21 15:02:41 -05:00
|
|
|
$res = $is_ref;
|
2014-02-14 22:08:19 -05:00
|
|
|
}
|
|
|
|
$this->assertTrue($res, $message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit test bootstrap - Using phpunit
|
|
|
|
*/
|
|
|
|
define('QTEST_DIR', realpath(dirname(__FILE__)));
|
2014-02-14 22:27:01 -05:00
|
|
|
define('QBASE_DIR', realpath(QTEST_DIR.'/../') . '/');
|
2014-02-14 22:08:19 -05:00
|
|
|
define('QDS', DIRECTORY_SEPARATOR);
|
|
|
|
|
|
|
|
// Include db classes
|
|
|
|
require_once(QBASE_DIR . 'autoload.php');
|
|
|
|
|
|
|
|
// Require base testing classes
|
|
|
|
require_once(QTEST_DIR . '/core/core.php');
|
|
|
|
require_once(QTEST_DIR . '/core/db_test.php');
|
|
|
|
require_once(QTEST_DIR . '/core/db_qp_test.php');
|
|
|
|
require_once(QTEST_DIR . '/core/db_qb_test.php');
|
|
|
|
|
2014-02-21 15:02:41 -05:00
|
|
|
// Preset SQLite connection, so there aren't locking issues
|
|
|
|
if (extension_loaded('pdo_sqlite'))
|
|
|
|
{
|
|
|
|
$path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db';
|
2014-04-08 17:13:41 -04:00
|
|
|
@unlink($path);
|
2014-02-25 11:33:18 -05:00
|
|
|
$params = array(
|
2014-02-21 15:02:41 -05:00
|
|
|
'type' => 'sqlite',
|
2014-04-08 17:13:41 -04:00
|
|
|
'file' => ':memory:',
|
2014-02-21 15:02:41 -05:00
|
|
|
'host' => 'localhost',
|
|
|
|
'prefix' => 'create_',
|
|
|
|
'alias' => 'test_sqlite',
|
|
|
|
'options' => array(
|
|
|
|
PDO::ATTR_PERSISTENT => TRUE
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
Query($params);
|
|
|
|
}
|
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
// End of bootstrap.php
|