mirror of
https://github.com/e107inc/e107.git
synced 2025-08-08 07:36:32 +02:00
105 lines
2.2 KiB
PHP
105 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* e107 website system
|
|
*
|
|
* Copyright (C) 2008-2020 e107 Inc (e107.org)
|
|
* Released under the terms and conditions of the
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
|
*
|
|
*/
|
|
|
|
|
|
class e_db_mysqlTest extends e_db_abstractTest
|
|
{
|
|
protected function makeDb()
|
|
{
|
|
return $this->make('e_db_mysql');
|
|
}
|
|
|
|
protected function _before()
|
|
{
|
|
require_once(e_HANDLER."mysql_class.php");
|
|
try
|
|
{
|
|
$this->db = $this->makeDb();
|
|
}
|
|
catch (Exception $e)
|
|
{
|
|
$this->fail("Couldn't load e_db_mysql object");
|
|
}
|
|
|
|
|
|
// Simulate PHP 5.6
|
|
defined('MYSQL_ASSOC') or define('MYSQL_ASSOC', 1);
|
|
defined('MYSQL_NUM') or define('MYSQL_NUM', 2);
|
|
defined('MYSQL_BOTH') or define('MYSQL_BOTH', 3);
|
|
$this->db->__construct();
|
|
$this->loadConfig();
|
|
|
|
$this->db->db_Connect(
|
|
$this->dbConfig['mySQLserver'],
|
|
$this->dbConfig['mySQLuser'],
|
|
$this->dbConfig['mySQLpassword'],
|
|
$this->dbConfig['mySQLdefaultdb']
|
|
);
|
|
}
|
|
|
|
public function _after()
|
|
{
|
|
$db_impl = $this->getDbImplementation();
|
|
if (@empty($db_impl->server_info)) return;
|
|
|
|
parent::_after();
|
|
}
|
|
|
|
public function testGetPDO()
|
|
{
|
|
$result = $this->db->getPDO();
|
|
$this->assertFalse($result);
|
|
}
|
|
|
|
public function testGetServerInfo()
|
|
{
|
|
$result = $this->db->getServerInfo();
|
|
$this->assertRegExp('/[0-9]+\./', $result);
|
|
}
|
|
|
|
public function testGetLastErrorNumber()
|
|
{
|
|
$this->db->select('doesnt_exists');
|
|
$result = $this->db->getLastErrorNumber();
|
|
$this->assertEquals("1146", $result);
|
|
}
|
|
|
|
public function testEscape()
|
|
{
|
|
$result = $this->db->escape(123);
|
|
$this->assertEquals(123,$result);
|
|
|
|
$result = $this->db->escape("Can't", true);
|
|
$this->assertEquals("Can\'t", $result);
|
|
}
|
|
|
|
public function testDb_Close()
|
|
{
|
|
$db_impl = $this->getDbImplementation();
|
|
if (!empty($db_impl->server_info))
|
|
{
|
|
$this->db->db_Close();
|
|
self::assertTrue(empty($db_impl->server_info));
|
|
}
|
|
else
|
|
{
|
|
self::assertTrue(true); // Connection is already closed, so the test passes
|
|
}
|
|
}
|
|
|
|
private function getDbImplementation()
|
|
{
|
|
$reflection_object = new ReflectionObject($this->db);
|
|
$db_property = $reflection_object->getProperty('mySQLaccess');
|
|
$db_property->setAccessible(true);
|
|
return $db_property->getValue($this->db);
|
|
}
|
|
}
|