66 protected $ini_file =
'/var/www/ilias/data/trunk/client.ini.php';
78 $this->error_reporting_backup = error_reporting();
79 error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING & ~E_STRICT);
81 PHPUnit_Framework_Error_Notice::$enabled =
false;
82 PHPUnit_Framework_Error_Deprecated::$enabled =
false;
84 require_once(
'./libs/composer/vendor/autoload.php');
86 define(
'DEVMODE',
true);
88 require_once(
'./Services/Database/classes/class.ilDBWrapperFactory.php');
95 switch ($this->type) {
97 require_once(
'./Services/Database/test/Implementations/data/MySQL/class.ilDatabaseMySQLTestMockData.php');
98 require_once(
'./Services/Database/test/Implementations/data/MySQL/class.ilDatabaseMySQLTestsDataOutputs.php');
104 require_once(
'./Services/Database/test/Implementations/data/Postgres/class.ilDatabasePostgresTestMockData.php');
105 require_once(
'./Services/Database/test/Implementations/data/Postgres/class.ilDatabasePostgresTestsDataOutputs.php');
110 $this->set_up =
true;
127 require_once(
'./Services/Init/classes/class.ilIniFile.php');
128 require_once(
'./Services/Init/classes/class.ilErrorHandling.php');
130 $ilClientIniFile->read();
131 $this->type = $ilClientIniFile->readVariable(
"db",
"type");
136 $return = $ilDBInterface->
connect($missing_ini);
146 return strtolower(self::TABLE_NAME .
'_' . $this->db->getDBType());
153 $this->outputs = null;
155 $this->set_up =
false;
156 error_reporting($this->error_reporting_backup);
178 if ($this->db->supportsEngineMigration()) {
184 public function testCompareCreateTableQueries() {
190 $this->assertEquals($this->outputs->getCreationQueryBuildByILIAS($this->getTableName()), $this->
normalizeSQL(
$query));
198 $fields = $this->mock->getDBFields();
199 $this->db->createTable($this->
getTableName(), $fields,
true);
201 $this->assertTrue($this->db->tableExists($this->getTableName()));
210 $data = array_change_key_case(
$data, CASE_LOWER);
213 $create_table_mock = $this->
normalizeSQL($this->mock->getTableCreateSQL($this->getTableName(), $this->db->getStorageEngine()));
215 $this->assertEquals($create_table_mock, $create_table);
223 $values = $this->mock->getInputArray(
false,
false);
224 $id = $values[
'id'][1];
228 $this->db->setLimit(1);
229 $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() .
" WHERE id = $id");
230 $data_pdo = $this->db->fetchAssoc($res_pdo);
236 $this->assertEquals($this->mock->getLike(), $this->db->like(
'column',
'text', 22));
238 $this->assertEquals($this->mock->getNow(), $this->db->now());
240 $this->assertEquals($this->mock->getLocate(), $this->db->locate(
'needle',
'mystring', 5));
242 $this->assertEquals($this->mock->getConcat(
false), $this->db->concat(
array(
'one',
'two',
'three' ),
false));
244 $this->assertEquals($this->mock->getConcat(
true), $this->db->concat(
array(
'one',
'two',
'three' ),
true));
253 $with_clob = $this->mock->getInputArray(2222,
true);
254 $without_clob = $this->mock->getInputArray(2222,
true,
false);
255 $id = $with_clob[
'id'][1];
259 $this->db->setLimit(1, 0);
260 $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() .
" WHERE id = $id ");
261 $data_pdo = $this->db->fetchAssoc($res_pdo);
265 $this->db->setLimit(1, 0);
266 $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() .
" WHERE id = $id ");
267 $data_pdo = $this->db->fetchAssoc($res_pdo);
277 $this->db->manipulate($this->mock->getInsertQuery($this->getTableName()));
278 $this->db->setLimit(1, 0);
279 $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() .
" WHERE id = 58");
280 $data_pdo = $this->db->fetchObject($res_pdo);
293 $query =
'SELECT usr_id, login, is_self_registered FROM usr_data WHERE usr_id = 6';
295 $this->db->setLimit(1, 0);
301 $this->db->setLimit(1, 0);
305 $query =
'SELECT usr_id, login, is_self_registered FROM usr_data WHERE ' . $this->db->in(
'usr_id',
array( 6, 13 ),
false,
'integer');
306 $this->db->setLimit(2, 0);
310 $this->assertTrue(in_array($item,
$data));
313 $this->assertEquals(2, $this->db->numRows(
$result));
322 $this->db->addIndex($this->
getTableName(),
array(
'init_mob_id' ), self::INDEX_NAME);
323 $this->assertTrue($this->db->indexExistsByFields($this->getTableName(),
array(
'init_mob_id' )));
326 $this->db->dropIndex($this->
getTableName(), self::INDEX_NAME);
327 $this->assertFalse($this->db->indexExistsByFields($this->getTableName(),
array(
'init_mob_id' )));
331 if ($this->db->supportsFulltext()) {
332 $this->assertTrue($this->db->indexExistsByFields($this->getTableName(),
array(
'address' )));
334 $this->assertFalse($this->db->indexExistsByFields($this->getTableName(),
array(
'address' )));
339 $this->assertTrue($this->db->indexExistsByFields($this->getTableName(),
array(
'elevation' )));
342 $this->assertFalse($this->db->indexExistsByFields($this->getTableName(),
array(
'elevation' )));
350 $this->assertTrue($this->db->tableColumnExists($this->getTableName(),
'init_mob_id'));
352 $this->db->addTableColumn($this->
getTableName(),
"export",
array(
"type" =>
"text",
"length" => 1024 ));
353 $this->assertTrue($this->db->tableColumnExists($this->getTableName(),
'export'));
355 $this->db->dropTableColumn($this->
getTableName(),
"export");
356 $this->assertFalse($this->db->tableColumnExists($this->getTableName(),
'export'));
364 if ($this->db->sequenceExists($this->getTableName())) {
368 $this->assertEquals(10, $this->db->nextId($this->getTableName()));
369 $this->assertEquals(11, $this->db->nextId($this->getTableName()));
376 public function testReverse() {
383 $this->assertEquals($this->outputs->getTableFieldDefinition(), $reverse->getTableFieldDefinition($this->
getTableName(),
'comment_mob_id'));
386 $this->db->addIndex($this->
getTableName(),
array(
'init_mob_id' ), self::INDEX_NAME);
387 $tableIndexDefinition = $reverse->getTableIndexDefinition($this->
getTableName(), $this->db->constraintName($this->getTableName(), self::INDEX_NAME));
389 $this->db->dropIndex($this->
getTableName(), self::INDEX_NAME);
399 public function testManager() {
406 $this->assertEquals($this->outputs->getTableFields(), $manager->listTableFields($this->
getTableName()));
409 $this->assertEquals($this->outputs->getTableConstraints($this->getTableName()), $manager->listTableConstraints($this->getTableName()));
413 $this->db->addIndex($this->
getTableName(),
array(
'init_mob_id' ), self::INDEX_NAME);
414 $this->assertEquals($this->outputs->getNativeTableIndices($this->getTableName(), $this->db->supportsFulltext()), $manager->listTableIndexes($this->getTableName()));
417 $list_tables_output = $this->outputs->getListTables($this->
getTableName());
418 sort($list_tables_output);
419 $list_tables_native = $manager->listTables();
420 sort($list_tables_native);
421 $this->assertEquals($list_tables_output, $list_tables_native);
424 $table_sequences_output = $this->outputs->getTableSequences($this->
getTableName());
425 $this->assertTrue(count(array_diff($table_sequences_output, $manager->listSequences())) < 3);
433 require_once(
'./Services/Database/classes/class.ilDBAnalyzer.php');
441 $this->assertEquals(0, $analyzer->getBestDefinitionAlternative($def));
444 $this->assertEquals(
false, $analyzer->getAutoIncrementField($this->getTableName()));
447 $this->assertEquals($this->outputs->getPrimaryInfo($this->getTableName()), $analyzer->getPrimaryKeyInformation($this->getTableName()));
450 if ($this->db->supportsFulltext()) {
451 $this->assertEquals($this->outputs->getIndexInfo(
true, $this->getTableName()), $analyzer->getIndicesInformation($this->getTableName()));
453 $this->assertEquals($this->outputs->getIndexInfo(
false, $this->getTableName()), $analyzer->getIndicesInformation($this->getTableName()));
457 $this->assertEquals(
array(), $analyzer->getConstraintsInformation($this->getTableName()));
460 $this->assertEquals(59, $analyzer->hasSequence($this->getTableName()));
468 $this->assertTrue($this->db->sequenceExists($this->getTableName()));
469 if ($this->db->sequenceExists($this->getTableName())) {
472 $this->assertFalse($this->db->sequenceExists($this->getTableName()));
485 $this->db->dropTable($this->
getTableName() .
'_a',
false);
487 $this->assertTrue($this->db->tableExists($this->getTableName() .
'_a'));
498 $this->db->renameTableColumn($this->
getTableName(),
'comment_mob_id',
'comment_mob_id_altered');
504 $data = array_change_key_case(
$data, CASE_LOWER);
506 $this->assertEquals($this->
normalizeSQL($this->mock->getTableCreateSQLAfterRename($this->getTableName(), $this->db->getStorageEngine(), $this->db->supportsFulltext())), $this->
normalizeSQL(
$data[self::CREATE_TABLE_ARRAY_KEY]));
525 $this->db->modifyTableColumn($this->
getTableName(),
'comment_mob_id_altered', $changes);
532 $data = array_change_key_case(
$data, CASE_LOWER);
536 $this->assertEquals($this->
normalizeSQL($this->mock->getTableCreateSQLAfterAlter($this->getTableName(), $this->db->getStorageEngine(), $this->db->supportsFulltext())), $this->
normalizeSQL(
$data[self::CREATE_TABLE_ARRAY_KEY]));
549 $this->db->lockTables($locks);
550 $this->db->manipulate(
'DELETE FROM usr_data WHERE usr_id = -1');
551 $this->db->unlockTables();
573 $this->assertTrue(!$this->db->tableExists($this->getTableName()));
585 $this->ildb_backup =
$ilDB;
586 $ilDB = $ilDBInterface;
601 return preg_replace(
'/[ \t]+/',
' ', preg_replace(
'/\s*$^\s*/m',
" ", preg_replace(
"/\n/",
"", preg_replace(
"/`/",
"", $sql))));
initFromIniFile($tmpClientIniFile=null)
testDropSequence()
testConnection
static $output_after_native_update
static $select_usr_data_output
testTransactions()
testConnection
testInsertNative()
testConnection
TestCase for the ilDatabaseCommonTest.
testIndices()
testConnection
connect($return_false_on_error=false)
testModifyTableColumn()
testConnection
Class ilDatabaseCommonTestMockData.
connect(ilDBInterface $ilDBInterface, $missing_ini=false)
testSequences()
testConnection
testRenameTableColumn()
testConnection
testInstance()
Test instance implements ilDBInterface and is ilDBInnoDB.
testTableColums()
testConnection
static $table_constraint_definition_output
Class ilDatabaseCommonTestsDataOutputs.
testCreateDatabase()
testConnection
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
static $insert_sql_output
testChangeTableName()
testConnection
Class ilDatabaseCommonTestMockData.
testLockTables()
testConnection
static $table_index_definition_output
Create styles array
The data for the language used.
testInsertSQL()
testConnection
static $select_usr_data_2_output
static $output_after_native_input
Class ilDatabaseCommonTestsDataOutputs.
const CREATE_TABLE_ARRAY_KEY
Create new PHPExcel object
obj_idprivate
This class gives all kind of DB information using the MDB2 manager and reverse module.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
changeGlobal(ilDBInterface $ilDBInterface)
testDropTable()
testConnection
testDBAnalyser()
testConnection
testUpdateNative()
testConnection