]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/tests/units/Class/ConfigurationManagerTest.php
baculum: Add first unit tests
[bacula/bacula] / gui / baculum / tests / units / Class / ConfigurationManagerTest.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2015 Marcin Haba
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The original author of Bacula is Kern Sibbald, with contributions
10  * from many others, a complete list can be found in the file AUTHORS.
11  *
12  * You may use this file and others of this release according to the
13  * license defined in the LICENSE file, which includes the Affero General
14  * Public License, v3.0 ("AGPLv3") and some additional permissions and
15  * terms pursuant to its AGPLv3 Section 7.
16  *
17  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22
23 require_once('test_common.php');
24
25 /**
26  * Basic Test cases to configuration manager module.
27  *
28  * @author Marcin Haba
29  */
30 class ConfigurationManagerTest extends PHPUnit_Framework_TestCase {
31
32         public static $application = null;
33
34         public function setUp() {
35                 if(self::$application === null) {
36                         self::$application = new TApplicationTest(BACULUM_ROOT_DIR . 'protected');
37                         self::$application->run();
38                 }
39         }
40
41         public function testGetDbNameByTypeValid() {
42                 $testData = array(
43                         'pgsql' => 'PostgreSQL',
44                         'mysql' => 'MySQL',
45                         'sqlite' => 'SQLite'
46                 );
47                 foreach ($testData as $shortName => $longName) {
48                         $result = self::$application->getModule('configuration')->getDbNameByType($shortName);
49                         $this->assertEquals($longName, $result);
50                 }
51         }
52
53         public function testGetDbNameByTypeInvalid() {
54                 $testData = array("pgsql\n", ' pgsql', ' pgsql ', 'Mysql', 'MYSQL', 'SQlite', 'MySqL', null, true, 0, -1);
55                 for ($i = 0; $i < count($testData); $i++) {
56                         $result = self::$application->getModule('configuration')->getDbNameByType($testData[$i]);
57                         $this->assertNull($result);
58                 }
59         }
60
61         public function testIsPostgreSQLTypeValid() {
62                 $testData = 'pgsql';
63                 $result = self::$application->getModule('configuration')->isPostgreSQLType($testData);
64                 $this->assertTrue($result);
65         }
66
67         public function testIsPostgreSQLTypeInvalid() {
68                 $testData = array("pgsql\n", ' pgsql', ' pgsql ', 'mysql', 'MYSQL', 'sqlite', 'MySqL', null, true, 0, -1);
69                 for ($i = 0; $i < count($testData); $i++) {
70                         $result = self::$application->getModule('configuration')->isPostgreSQLType($testData[$i]);
71                         $this->assertFalse($result);
72                 }
73         }
74
75         public function testIsMySQLTypeValid() {
76                 $testData = 'mysql';
77                 $result = self::$application->getModule('configuration')->isMySQLType($testData);
78                 $this->assertTrue($result);
79         }
80
81         public function testIsMySQLTypeInvalid() {
82                 $testData = array("mysql\n", ' mysql', ' mysql ', 'm ysql', 'MYSQ', 'sqlite', 'pgsql', 'mysq', null, true, 0, -1);
83                 for ($i = 0; $i < count($testData); $i++) {
84                         $result = self::$application->getModule('configuration')->isMySQLType($testData[$i]);
85                         $this->assertFalse($result);
86                 }
87         }
88         public function testIsSQLiteTypeValid() {
89                 $testData = 'sqlite';
90                 $result = self::$application->getModule('configuration')->isSQLiteType($testData);
91                 $this->assertTrue($result);
92         }
93
94         public function testIsSQLiteTypeInvalid() {
95                 $testData = array("sqlite\n", ' sqlite', ' sqlite ', 's qlite', 'sqlit', 'pgsql', 'mysqs', null, true, 0, -1);
96                 for ($i = 0; $i < count($testData); $i++) {
97                         $result = self::$application->getModule('configuration')->isSQLiteType($testData[$i]);
98                         $this->assertFalse($result);
99                 }
100         }
101
102         public function testGetDefaultLanguageValid() {
103                 $mockData = false;
104                 $testData = 'en';
105
106                 $mock = $this->getMockBuilder('ConfigurationManager')->setMethods(array('isApplicationConfig'))->getMock();
107                 $mock->expects($this->once())->method('isApplicationConfig')->will($this->returnValue($mockData));
108                 $result = $mock->getLanguage();
109                 $this->assertEquals($testData, $result);
110         }
111 }
112
113 ?>