ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
36
40 protected $db;
47 protected $ini_file = '/var/www/ilias/data/trunk/client.ini.php';
52
53
54 protected function setUp()
55 {
56 $this->error_reporting_backup = error_reporting();
57 error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING & ~E_STRICT); // Due to PEAR Lib MDB2
58
59 PHPUnit_Framework_Error_Notice::$enabled = false;
60 PHPUnit_Framework_Error_Deprecated::$enabled = false;
61
62 require_once('./libs/composer/vendor/autoload.php');
63 if (!defined('DEVMODE')) {
64 define('DEVMODE', true);
65 }
66 require_once('./Services/Database/classes/class.ilDBWrapperFactory.php');
67 $this->db = $this->getDBInstance();
68 $this->connect($this->db);
69 }
70
71
76 protected function getDBInstance()
77 {
78 return ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_PDO_MYSQL_INNODB);
79 }
80
81
85 protected function getIniFile()
86 {
87 return $this->ini_file;
88 }
89
90
95 protected function connect(ilDBInterface $ilDBInterface)
96 {
97 require_once('./Services/Init/classes/class.ilIniFile.php');
98 require_once('./Services/Init/classes/class.ilErrorHandling.php');
99 $ilClientIniFile = new ilIniFile($this->getIniFile());
100 $ilClientIniFile->read();
101 $this->type = $ilClientIniFile->readVariable("db", "type");
102 $ilDBInterface->initFromIniFile($ilClientIniFile);
103 $return = $ilDBInterface->connect();
104
105 return $return;
106 }
107
108
109 protected function tearDown()
110 {
111 error_reporting($this->error_reporting_backup);
112 }
113
114
118 public function testPrimaryKeys()
119 {
123 $manager = $this->db->loadModule(ilDBConstants::MODULE_MANAGER);
124 $all_tables_primary_mock = array();
125 $all_tables_primary_actual = array();
126 foreach ($this->db->listTables() as $table) {
127 $constraints = $manager->listTableConstraints($table);
128 $all_tables_primary_actual[$table] = $constraints[0];
129 $all_tables_primary_mock[$table] = 'primary';
130 }
131
132 $this->assertEquals($all_tables_primary_mock, $all_tables_primary_actual);
133 }
134
135
139 public function testIndicesOrPrimaries()
140 {
144 $manager = $this->db->loadModule(ilDBConstants::MODULE_MANAGER);
145 $all_tables_primary_mock = array();
146 $all_tables_primary_actual = array();
147 foreach ($this->db->listTables() as $table) {
148 $indices = $manager->listTableIndexes($table);
149 $constraints = $manager->listTableConstraints($table);
150 $count = count($indices) + count($constraints);
151 $all_tables_primary_actual[$table] = $count;
152 $all_tables_primary_mock[$table] = $count ? $count : 1;
153 }
154
155 $this->assertEquals($all_tables_primary_mock, $all_tables_primary_actual);
156 }
157}
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
if(empty($password)) $table
Definition: pwgen.php:24