66    protected $ini_file = 
'/var/www/ilias/data/trunk/client.ini.php';
 
   79        $this->error_reporting_backup = error_reporting();
 
   81        PHPUnit_Framework_Error_Notice::$enabled = 
false;
 
   82        PHPUnit_Framework_Error_Deprecated::$enabled = 
false;
 
   84        require_once(
'./libs/composer/vendor/autoload.php');
 
   85        if (!defined(
'DEVMODE')) {
 
   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;
 
  129        require_once(
'./Services/Init/classes/class.ilIniFile.php');
 
  130        require_once(
'./Services/Init/classes/class.ilErrorHandling.php');
 
  132        $ilClientIniFile->read();
 
  133        $this->type = $ilClientIniFile->readVariable(
"db", 
"type");
 
  138        $return = $ilDBInterface->
connect($missing_ini);
 
  149        return strtolower(self::TABLE_NAME . 
'_' . $this->db->getDBType());
 
  157        $this->outputs = 
null;
 
  159        $this->set_up = 
false;
 
  160        error_reporting($this->error_reporting_backup);
 
  186    public function testCompareCreateTableQueries()
 
  192        $query = $manager->getTableCreationQuery($this->
getTableName(), $this->mock->getDBFields(), array());
 
  193        $this->assertEquals($this->outputs->getCreationQueryBuildByILIAS($this->getTableName()), $this->normalizeSQL(
$query));
 
  202        $fields = $this->mock->getDBFields();
 
  203        $this->db->createTable($this->
getTableName(), $fields, 
true);
 
  204        $this->db->addPrimaryKey($this->
getTableName(), array( 
'id' ));
 
  205        $this->assertTrue($this->db->tableExists($this->getTableName()));
 
  214        $data = array_change_key_case(
$data, CASE_LOWER);
 
  217        $create_table_mock = $this->
normalizeSQL($this->mock->getTableCreateSQL($this->getTableName(), $this->db->getStorageEngine()));
 
  219        $this->assertEquals($create_table_mock, $create_table);
 
  228        $values = $this->mock->getInputArray(
false, 
false);
 
  233        $this->db->setLimit(1);
 
  234        $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() . 
" WHERE id = $id");
 
  235        $data_pdo = $this->db->fetchAssoc($res_pdo);
 
  242        $this->assertEquals($this->mock->getLike(), $this->db->like(
'column', 
'text', 22));
 
  244        $this->assertEquals($this->mock->getNow(), $this->db->now());
 
  246        $this->assertEquals($this->mock->getLocate(), $this->db->locate(
'needle', 
'mystring', 5));
 
  248        $this->assertEquals($this->mock->getConcat(
false), $this->db->concat(array( 
'one', 
'two', 
'three' ), 
false));
 
  250        $this->assertEquals($this->mock->getConcat(
true), $this->db->concat(array( 
'one', 
'two', 
'three' ), 
true));
 
  260        $with_clob = $this->mock->getInputArray(2222, 
true);
 
  261        $without_clob = $this->mock->getInputArray(2222, 
true, 
false);
 
  262        $id = $with_clob[
'id'][1];
 
  265        $this->db->update($this->
getTableName(), $with_clob, array( 
'id' => array( 
'integer', 
$id ) ));
 
  266        $this->db->setLimit(1, 0);
 
  267        $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() . 
" WHERE id = $id ");
 
  268        $data_pdo = $this->db->fetchAssoc($res_pdo);
 
  271        $this->db->update($this->
getTableName(), $without_clob, array( 
'id' => array( 
'integer', 
$id ) ));
 
  272        $this->db->setLimit(1, 0);
 
  273        $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() . 
" WHERE id = $id ");
 
  274        $data_pdo = $this->db->fetchAssoc($res_pdo);
 
  285        $this->db->manipulate($this->mock->getInsertQuery($this->getTableName()));
 
  286        $this->db->setLimit(1, 0);
 
  287        $res_pdo = $this->db->query(
"SELECT * FROM " . $this->
getTableName() . 
" WHERE id = 58");
 
  288        $data_pdo = $this->db->fetchObject($res_pdo);
 
  302        $query = 
'SELECT usr_id, login, is_self_registered FROM usr_data WHERE usr_id = 6';
 
  304        $this->db->setLimit(1, 0);
 
  310        $this->db->setLimit(1, 0);
 
  314        $query = 
'SELECT usr_id, login, is_self_registered FROM usr_data WHERE ' . $this->db->in(
'usr_id', array( 6, 13 ), 
false, 
'integer');
 
  315        $this->db->setLimit(2, 0);
 
  319            $this->assertTrue(in_array($item, 
$data));
 
  322        $this->assertEquals(2, $this->db->numRows(
$result));
 
  332        $this->db->addIndex($this->
getTableName(), array( 
'init_mob_id' ), self::INDEX_NAME);
 
  333        $this->assertTrue($this->db->indexExistsByFields($this->getTableName(), array( 
'init_mob_id' )));
 
  336        $this->db->dropIndex($this->
getTableName(), self::INDEX_NAME);
 
  337        $this->assertFalse($this->db->indexExistsByFields($this->getTableName(), array( 
'init_mob_id' )));
 
  340        $this->db->addIndex($this->
getTableName(), array( 
'address' ), 
'i2', 
true);
 
  341        if ($this->db->supportsFulltext()) {
 
  342            $this->assertTrue($this->db->indexExistsByFields($this->getTableName(), array( 
'address' )));
 
  344            $this->assertFalse($this->db->indexExistsByFields($this->getTableName(), array( 
'address' )));
 
  348        $this->db->addIndex($this->
getTableName(), array( 
'elevation' ), 
'i3');
 
  349        $this->assertTrue($this->db->indexExistsByFields($this->getTableName(), array( 
'elevation' )));
 
  351        $this->db->dropIndexByFields($this->
getTableName(), array( 
'elevation' ));
 
  352        $this->assertFalse($this->db->indexExistsByFields($this->getTableName(), array( 
'elevation' )));
 
  361        $this->assertTrue($this->db->tableColumnExists($this->getTableName(), 
'init_mob_id'));
 
  363        $this->db->addTableColumn($this->
getTableName(), 
"export", array( 
"type" => 
"text", 
"length" => 1024 ));
 
  364        $this->assertTrue($this->db->tableColumnExists($this->getTableName(), 
'export'));
 
  366        $this->db->dropTableColumn($this->
getTableName(), 
"export");
 
  367        $this->assertFalse($this->db->tableColumnExists($this->getTableName(), 
'export'));
 
  376        if ($this->db->sequenceExists($this->getTableName())) {
 
  380        $this->assertEquals(10, $this->db->nextId($this->getTableName()));
 
  381        $this->assertEquals(11, $this->db->nextId($this->getTableName()));
 
  388    public function testReverse()
 
  396        $this->assertEquals($this->outputs->getTableFieldDefinition(), $reverse->getTableFieldDefinition($this->getTableName(), 
'comment_mob_id'));
 
  399        $this->db->addIndex($this->
getTableName(), array( 
'init_mob_id' ), self::INDEX_NAME);
 
  400        $tableIndexDefinition = $reverse->getTableIndexDefinition($this->
getTableName(), $this->db->constraintName($this->getTableName(), self::INDEX_NAME));
 
  402        $this->db->dropIndex($this->
getTableName(), self::INDEX_NAME);
 
  412    public function testManager()
 
  420        $this->assertEquals($this->outputs->getTableFields(), $manager->listTableFields($this->getTableName()));
 
  423        $this->assertEquals($this->outputs->getTableConstraints($this->getTableName()), $manager->listTableConstraints($this->getTableName()));
 
  426        $this->db->dropIndexByFields($this->
getTableName(), array( 
'init_mob_id' ));
 
  427        $this->db->addIndex($this->
getTableName(), array( 
'init_mob_id' ), self::INDEX_NAME);
 
  428        $this->assertEquals($this->outputs->getNativeTableIndices($this->getTableName(), $this->db->supportsFulltext()), $manager->listTableIndexes($this->getTableName()));
 
  431        $list_tables_output = $this->outputs->getListTables($this->
getTableName());
 
  432        sort($list_tables_output);
 
  433        $list_tables_native = $manager->listTables();
 
  434        sort($list_tables_native);
 
  435        $this->assertEquals($list_tables_output, $list_tables_native);
 
  438        $table_sequences_output = $this->outputs->getTableSequences($this->
getTableName());
 
  439        $this->assertTrue(count(array_diff($table_sequences_output, $manager->listSequences())) < 3);
 
  448        require_once(
'./Services/Database/classes/class.ilDBAnalyzer.php');
 
  456        $this->assertEquals(0, $analyzer->getBestDefinitionAlternative(
$def)); 
 
  459        $this->assertEquals(
false, $analyzer->getAutoIncrementField($this->getTableName()));
 
  462        $this->assertEquals($this->outputs->getPrimaryInfo($this->getTableName()), $analyzer->getPrimaryKeyInformation($this->getTableName()));
 
  465        if ($this->db->supportsFulltext()) {
 
  466            $this->assertEquals($this->outputs->getIndexInfo(
true, $this->getTableName()), $analyzer->getIndicesInformation($this->getTableName()));
 
  468            $this->assertEquals($this->outputs->getIndexInfo(
false, $this->getTableName()), $analyzer->getIndicesInformation($this->getTableName()));
 
  472        $this->assertEquals(array(), $analyzer->getConstraintsInformation($this->getTableName())); 
 
  475        $this->assertEquals(59, $analyzer->hasSequence($this->getTableName()));
 
  484        $this->assertTrue($this->db->sequenceExists($this->getTableName()));
 
  485        if ($this->db->sequenceExists($this->getTableName())) {
 
  488        $this->assertFalse($this->db->sequenceExists($this->getTableName()));
 
  502        $this->db->dropTable($this->
getTableName() . 
'_a', 
false);
 
  504        $this->assertTrue($this->db->tableExists($this->getTableName() . 
'_a'));
 
  516        $this->db->renameTableColumn($this->
getTableName(), 
'comment_mob_id', 
'comment_mob_id_altered');
 
  522        $data = array_change_key_case(
$data, CASE_LOWER);
 
  524        $this->assertEquals($this->
normalizeSQL($this->mock->getTableCreateSQLAfterRename($this->getTableName(), $this->db->getStorageEngine(), $this->db->supportsFulltext())), $this->normalizeSQL(
$data[self::CREATE_TABLE_ARRAY_KEY]));
 
  544        $this->db->modifyTableColumn($this->
getTableName(), 
'comment_mob_id_altered', $changes);
 
  551        $data = array_change_key_case(
$data, CASE_LOWER);
 
  555        $this->assertEquals($this->
normalizeSQL($this->mock->getTableCreateSQLAfterAlter($this->getTableName(), $this->db->getStorageEngine(), $this->db->supportsFulltext())), $this->normalizeSQL(
$data[self::CREATE_TABLE_ARRAY_KEY]));
 
  569        $this->db->lockTables($locks);
 
  570        $this->db->manipulate(
'DELETE FROM usr_data WHERE usr_id = -1');
 
  571        $this->db->unlockTables();
 
  595        $this->assertTrue(!$this->db->tableExists($this->getTableName()));
 
  608        $this->ildb_backup = 
$ilDB;
 
  609        $ilDB = $ilDBInterface;
 
  626        return preg_replace(
'/[ \t]+/', 
' ', preg_replace(
'/\s*$^\s*/m', 
" ", preg_replace(
"/\n/", 
"", preg_replace(
"/`/", 
"", $sql))));
 
An exception for terminatinating execution or to throw for unit testing.
This class gives all kind of DB information using the database manager and reverse module.
static $table_constraint_definition_output
static $select_usr_data_output
static $table_index_definition_output
static $output_after_native_input
static $insert_sql_output
static $output_after_native_update
static $select_usr_data_2_output
TestCase for the ilDatabaseCommonTest.
testDBAnalyser()
@depends testConnection
testInstance()
Test instance implements ilDBInterface and is ilDBInnoDB.
testModifyTableColumn()
@depends testConnection
testTableColums()
@depends testConnection
testTransactions()
@depends testConnection
testDropTable()
@depends testConnection
testInsertSQL()
@depends testConnection
connect(ilDBInterface $ilDBInterface, $missing_ini=false)
const CREATE_TABLE_ARRAY_KEY
testLockTables()
@depends testConnection
testIndices()
@depends testConnection
testCreateDatabase()
@depends testConnection
testUpdateNative()
@depends testConnection
testRenameTableColumn()
@depends testConnection
testDropSequence()
@depends testConnection
testInsertNative()
@depends testConnection
changeGlobal(ilDBInterface $ilDBInterface)
testChangeTableName()
@depends testConnection
testSequences()
@depends testConnection
Class ilDatabaseCommonTestMockData.
Class ilDatabaseCommonTestsDataOutputs.
Class ilDatabaseCommonTestMockData.
Class ilDatabaseCommonTestsDataOutputs.
if(!array_key_exists('StateId', $_REQUEST)) $id
initFromIniFile($tmpClientIniFile=null)
connect($return_false_on_error=false)
foreach($_POST as $key=> $value) $res