3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2015 Marcin Haba
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.
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.
17 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
23 require_once('test_common.php');
26 * Basic Test cases to configuration manager module.
30 class ConfigurationManagerTest extends PHPUnit_Framework_TestCase {
32 public static $application = null;
34 public function setUp() {
35 if(self::$application === null) {
36 self::$application = new TApplicationTest(BACULUM_ROOT_DIR . 'protected');
37 self::$application->run();
41 public function testGetDbNameByTypeValid() {
43 'pgsql' => 'PostgreSQL',
47 foreach ($testData as $shortName => $longName) {
48 $result = self::$application->getModule('configuration')->getDbNameByType($shortName);
49 $this->assertEquals($longName, $result);
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);
61 public function testIsPostgreSQLTypeValid() {
63 $result = self::$application->getModule('configuration')->isPostgreSQLType($testData);
64 $this->assertTrue($result);
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);
75 public function testIsMySQLTypeValid() {
77 $result = self::$application->getModule('configuration')->isMySQLType($testData);
78 $this->assertTrue($result);
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);
88 public function testIsSQLiteTypeValid() {
90 $result = self::$application->getModule('configuration')->isSQLiteType($testData);
91 $this->assertTrue($result);
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);
102 public function testGetDefaultLanguageValid() {
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);