66 protected $ini_file =
'/var/www/ilias/data/trunk/client.ini.php';
79 $this->error_reporting_backup = error_reporting();
80 error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING & ~E_STRICT);
82 PHPUnit_Framework_Error_Notice::$enabled =
false;
83 PHPUnit_Framework_Error_Deprecated::$enabled =
false;
85 require_once(
'./libs/composer/vendor/autoload.php');
87 define(
'DEVMODE',
true);
89 require_once(
'./Services/Database/classes/class.ilDBWrapperFactory.php');
96 switch ($this->type) {
98 require_once(
'./Services/Database/test/Implementations/data/MySQL/class.ilDatabaseMySQLTestMockData.php');
99 require_once(
'./Services/Database/test/Implementations/data/MySQL/class.ilDatabaseMySQLTestsDataOutputs.php');
105 require_once(
'./Services/Database/test/Implementations/data/Postgres/class.ilDatabasePostgresTestMockData.php');
106 require_once(
'./Services/Database/test/Implementations/data/Postgres/class.ilDatabasePostgresTestsDataOutputs.php');
111 $this->set_up =
true;
130 require_once(
'./Services/Init/classes/class.ilIniFile.php');
131 require_once(
'./Services/Init/classes/class.ilErrorHandling.php');
133 $ilClientIniFile->read();
134 $this->type = $ilClientIniFile->readVariable(
"db",
"type");
139 $return = $ilDBInterface->
connect($missing_ini);
150 return strtolower(self::TABLE_NAME .
'_' . $this->db->getDBType());
158 $this->outputs = null;
160 $this->set_up =
false;
161 error_reporting($this->error_reporting_backup);
185 if ($this->db->supportsEngineMigration()) {
191 public function testCompareCreateTableQueries()
198 $this->assertEquals($this->outputs->getCreationQueryBuildByILIAS($this->getTableName()), $this->
normalizeSQL(
$query));
207 $fields = $this->mock->getDBFields();
208 $this->db->createTable($this->
getTableName(), $fields,
true);
210 $this->assertTrue($this->db->tableExists($this->getTableName()));
219 $data = array_change_key_case(
$data, CASE_LOWER);
222 $create_table_mock = $this->
normalizeSQL($this->mock->getTableCreateSQL($this->getTableName(), $this->db->getStorageEngine()));
224 $this->assertEquals($create_table_mock, $create_table);
233 $values = $this->mock->getInputArray(
false,
false);
234 $id = $values[
'id'][1];
238 $this->db->setLimit(1);
239 $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() .
" WHERE id = $id");
240 $data_pdo = $this->db->fetchAssoc($res_pdo);
247 $this->assertEquals($this->mock->getLike(), $this->db->like(
'column',
'text', 22));
249 $this->assertEquals($this->mock->getNow(), $this->db->now());
251 $this->assertEquals($this->mock->getLocate(), $this->db->locate(
'needle',
'mystring', 5));
253 $this->assertEquals($this->mock->getConcat(
false), $this->db->concat(
array(
'one',
'two',
'three' ),
false));
255 $this->assertEquals($this->mock->getConcat(
true), $this->db->concat(
array(
'one',
'two',
'three' ),
true));
265 $with_clob = $this->mock->getInputArray(2222,
true);
266 $without_clob = $this->mock->getInputArray(2222,
true,
false);
267 $id = $with_clob[
'id'][1];
271 $this->db->setLimit(1, 0);
272 $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() .
" WHERE id = $id ");
273 $data_pdo = $this->db->fetchAssoc($res_pdo);
277 $this->db->setLimit(1, 0);
278 $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() .
" WHERE id = $id ");
279 $data_pdo = $this->db->fetchAssoc($res_pdo);
290 $this->db->manipulate($this->mock->getInsertQuery($this->getTableName()));
291 $this->db->setLimit(1, 0);
292 $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() .
" WHERE id = 58");
293 $data_pdo = $this->db->fetchObject($res_pdo);
307 $query =
'SELECT usr_id, login, is_self_registered FROM usr_data WHERE usr_id = 6';
309 $this->db->setLimit(1, 0);
315 $this->db->setLimit(1, 0);
319 $query =
'SELECT usr_id, login, is_self_registered FROM usr_data WHERE ' . $this->db->in(
'usr_id',
array( 6, 13 ),
false,
'integer');
320 $this->db->setLimit(2, 0);
324 $this->assertTrue(in_array($item,
$data));
327 $this->assertEquals(2, $this->db->numRows(
$result));
337 $this->db->addIndex($this->
getTableName(),
array(
'init_mob_id' ), self::INDEX_NAME);
338 $this->assertTrue($this->db->indexExistsByFields($this->getTableName(),
array(
'init_mob_id' )));
341 $this->db->dropIndex($this->
getTableName(), self::INDEX_NAME);
342 $this->assertFalse($this->db->indexExistsByFields($this->getTableName(),
array(
'init_mob_id' )));
346 if ($this->db->supportsFulltext()) {
347 $this->assertTrue($this->db->indexExistsByFields($this->getTableName(),
array(
'address' )));
349 $this->assertFalse($this->db->indexExistsByFields($this->getTableName(),
array(
'address' )));
354 $this->assertTrue($this->db->indexExistsByFields($this->getTableName(),
array(
'elevation' )));
357 $this->assertFalse($this->db->indexExistsByFields($this->getTableName(),
array(
'elevation' )));
366 $this->assertTrue($this->db->tableColumnExists($this->getTableName(),
'init_mob_id'));
368 $this->db->addTableColumn($this->
getTableName(),
"export",
array(
"type" =>
"text",
"length" => 1024 ));
369 $this->assertTrue($this->db->tableColumnExists($this->getTableName(),
'export'));
371 $this->db->dropTableColumn($this->
getTableName(),
"export");
372 $this->assertFalse($this->db->tableColumnExists($this->getTableName(),
'export'));
381 if ($this->db->sequenceExists($this->getTableName())) {
385 $this->assertEquals(10, $this->db->nextId($this->getTableName()));
386 $this->assertEquals(11, $this->db->nextId($this->getTableName()));
393 public function testReverse()
401 $this->assertEquals($this->outputs->getTableFieldDefinition(), $reverse->getTableFieldDefinition($this->
getTableName(),
'comment_mob_id'));
404 $this->db->addIndex($this->
getTableName(),
array(
'init_mob_id' ), self::INDEX_NAME);
405 $tableIndexDefinition = $reverse->getTableIndexDefinition($this->
getTableName(), $this->db->constraintName($this->getTableName(), self::INDEX_NAME));
407 $this->db->dropIndex($this->
getTableName(), self::INDEX_NAME);
417 public function testManager()
425 $this->assertEquals($this->outputs->getTableFields(), $manager->listTableFields($this->
getTableName()));
428 $this->assertEquals($this->outputs->getTableConstraints($this->getTableName()), $manager->listTableConstraints($this->getTableName()));
432 $this->db->addIndex($this->
getTableName(),
array(
'init_mob_id' ), self::INDEX_NAME);
433 $this->assertEquals($this->outputs->getNativeTableIndices($this->getTableName(), $this->db->supportsFulltext()), $manager->listTableIndexes($this->getTableName()));
436 $list_tables_output = $this->outputs->getListTables($this->
getTableName());
437 sort($list_tables_output);
438 $list_tables_native = $manager->listTables();
439 sort($list_tables_native);
440 $this->assertEquals($list_tables_output, $list_tables_native);
443 $table_sequences_output = $this->outputs->getTableSequences($this->
getTableName());
444 $this->assertTrue(count(array_diff($table_sequences_output, $manager->listSequences())) < 3);
453 require_once(
'./Services/Database/classes/class.ilDBAnalyzer.php');
461 $this->assertEquals(0, $analyzer->getBestDefinitionAlternative(
$def));
464 $this->assertEquals(
false, $analyzer->getAutoIncrementField($this->getTableName()));
467 $this->assertEquals($this->outputs->getPrimaryInfo($this->getTableName()), $analyzer->getPrimaryKeyInformation($this->getTableName()));
470 if ($this->db->supportsFulltext()) {
471 $this->assertEquals($this->outputs->getIndexInfo(
true, $this->getTableName()), $analyzer->getIndicesInformation($this->getTableName()));
473 $this->assertEquals($this->outputs->getIndexInfo(
false, $this->getTableName()), $analyzer->getIndicesInformation($this->getTableName()));
477 $this->assertEquals(
array(), $analyzer->getConstraintsInformation($this->getTableName()));
480 $this->assertEquals(59, $analyzer->hasSequence($this->getTableName()));
489 $this->assertTrue($this->db->sequenceExists($this->getTableName()));
490 if ($this->db->sequenceExists($this->getTableName())) {
493 $this->assertFalse($this->db->sequenceExists($this->getTableName()));
507 $this->db->dropTable($this->
getTableName() .
'_a',
false);
509 $this->assertTrue($this->db->tableExists($this->getTableName() .
'_a'));
521 $this->db->renameTableColumn($this->
getTableName(),
'comment_mob_id',
'comment_mob_id_altered');
527 $data = array_change_key_case(
$data, CASE_LOWER);
529 $this->assertEquals($this->
normalizeSQL($this->mock->getTableCreateSQLAfterRename($this->getTableName(), $this->db->getStorageEngine(), $this->db->supportsFulltext())), $this->
normalizeSQL(
$data[self::CREATE_TABLE_ARRAY_KEY]));
549 $this->db->modifyTableColumn($this->
getTableName(),
'comment_mob_id_altered', $changes);
556 $data = array_change_key_case(
$data, CASE_LOWER);
560 $this->assertEquals($this->
normalizeSQL($this->mock->getTableCreateSQLAfterAlter($this->getTableName(), $this->db->getStorageEngine(), $this->db->supportsFulltext())), $this->
normalizeSQL(
$data[self::CREATE_TABLE_ARRAY_KEY]));
574 $this->db->lockTables($locks);
575 $this->db->manipulate(
'DELETE FROM usr_data WHERE usr_id = -1');
576 $this->db->unlockTables();
600 $this->assertTrue(!$this->db->tableExists($this->getTableName()));
613 $this->ildb_backup =
$ilDB;
614 $ilDB = $ilDBInterface;
631 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)
if(!array_key_exists('StateId', $_REQUEST)) $id
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
foreach($_POST as $key=> $value) $res
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