ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
58 PHPUnit_Framework_Error_Notice::$enabled = false;
59 PHPUnit_Framework_Error_Deprecated::$enabled = false;
60
61 require_once('./libs/composer/vendor/autoload.php');
62 if (!defined('DEVMODE')) {
63 define('DEVMODE', true);
64 }
65 require_once('./Services/Database/classes/class.ilDBWrapperFactory.php');
66 $this->db = $this->getDBInstance();
67 $this->connect($this->db);
68 }
69
70
75 protected function getDBInstance()
76 {
77 return ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_PDO_MYSQL_INNODB);
78 }
79
80
84 protected function getIniFile()
85 {
86 return $this->ini_file;
87 }
88
89
94 protected function connect(ilDBInterface $ilDBInterface)
95 {
96 require_once('./Services/Init/classes/class.ilIniFile.php');
97 require_once('./Services/Init/classes/class.ilErrorHandling.php');
98 $ilClientIniFile = new ilIniFile($this->getIniFile());
99 $ilClientIniFile->read();
100 $this->type = $ilClientIniFile->readVariable("db", "type");
101 $ilDBInterface->initFromIniFile($ilClientIniFile);
102 $return = $ilDBInterface->connect();
103
104 return $return;
105 }
106
107
108 protected function tearDown()
109 {
110 error_reporting($this->error_reporting_backup);
111 }
112
113
117 public function testPrimaryKeys()
118 {
122 $manager = $this->db->loadModule(ilDBConstants::MODULE_MANAGER);
123 $all_tables_primary_mock = array();
124 $all_tables_primary_actual = array();
125 foreach ($this->db->listTables() as $table) {
126 $constraints = $manager->listTableConstraints($table);
127 $all_tables_primary_actual[$table] = $constraints[0];
128 $all_tables_primary_mock[$table] = 'primary';
129 }
130
131 $this->assertEquals($all_tables_primary_mock, $all_tables_primary_actual);
132 }
133
134
138 public function testIndicesOrPrimaries()
139 {
143 $manager = $this->db->loadModule(ilDBConstants::MODULE_MANAGER);
144 $all_tables_primary_mock = array();
145 $all_tables_primary_actual = array();
146 foreach ($this->db->listTables() as $table) {
147 $indices = $manager->listTableIndexes($table);
148 $constraints = $manager->listTableConstraints($table);
149 $count = count($indices) + count($constraints);
150 $all_tables_primary_actual[$table] = $count;
151 $all_tables_primary_mock[$table] = $count ? $count : 1;
152 }
153
154 $this->assertEquals($all_tables_primary_mock, $all_tables_primary_actual);
155 }
156}
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)
if(empty($password)) $table
Definition: pwgen.php:24