ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilDatabaseBaseTest.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24// require_once(__DIR__."/mocks.php");
25
35
39 protected $db;
46 protected $ini_file = '/var/www/ilias/data/trunk/client.ini.php';
51
52
53 protected function setUp() {
54 $this->error_reporting_backup = error_reporting();
55 error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING & ~E_STRICT); // Due to PEAR Lib MDB2
56
57 PHPUnit_Framework_Error_Notice::$enabled = false;
58 PHPUnit_Framework_Error_Deprecated::$enabled = false;
59
60 require_once('./libs/composer/vendor/autoload.php');
61 if (!defined('DEVMODE')) {
62 define('DEVMODE', true);
63 }
64 require_once('./Services/Database/classes/class.ilDBWrapperFactory.php');
65 $this->db = $this->getDBInstance();
66 $this->connect($this->db);
67 }
68
69
74 protected function getDBInstance() {
75 return ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_PDO_MYSQL_INNODB);
76 }
77
78
82 protected function getIniFile() {
83 return $this->ini_file;
84 }
85
86
91 protected function connect(ilDBInterface $ilDBInterface) {
92 require_once('./Services/Init/classes/class.ilIniFile.php');
93 require_once('./Services/Init/classes/class.ilErrorHandling.php');
94 $ilClientIniFile = new ilIniFile($this->getIniFile());
95 $ilClientIniFile->read();
96 $this->type = $ilClientIniFile->readVariable("db", "type");
97 $ilDBInterface->initFromIniFile($ilClientIniFile);
98 $return = $ilDBInterface->connect();
99
100 return $return;
101 }
102
103
104 protected function tearDown() {
105 error_reporting($this->error_reporting_backup);
106 }
107
108
112 public function testPrimaryKeys() {
116 $manager = $this->db->loadModule(ilDBConstants::MODULE_MANAGER);
117 $all_tables_primary_mock = array();
118 $all_tables_primary_actual = array();
119 foreach ($this->db->listTables() as $table) {
120 $constraints = $manager->listTableConstraints($table);
121 $all_tables_primary_actual[$table] = $constraints[0];
122 $all_tables_primary_mock[$table] = 'primary';
123 }
124
125 $this->assertEquals($all_tables_primary_mock, $all_tables_primary_actual);
126 }
127
128
132 public function testIndicesOrPrimaries() {
136 $manager = $this->db->loadModule(ilDBConstants::MODULE_MANAGER);
137 $all_tables_primary_mock = array();
138 $all_tables_primary_actual = array();
139 foreach ($this->db->listTables() as $table) {
140 $indices = $manager->listTableIndexes($table);
141 $constraints = $manager->listTableConstraints($table);
142 $count = count($indices) + count($constraints);
143 $all_tables_primary_actual[$table] = $count;
144 $all_tables_primary_mock[$table] = $count ? $count : 1;
145 }
146
147 $this->assertEquals($all_tables_primary_mock, $all_tables_primary_actual);
148 }
149}
An exception for terminatinating execution or to throw for unit testing.
TestCase for the ilDatabaseCommonTest.
connect(ilDBInterface $ilDBInterface)
INIFile Parser.
Interface ilDBInterface.
initFromIniFile($tmpClientIniFile=null)
connect($return_false_on_error=false)
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27