]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Add first unit tests
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 31 Dec 2015 08:16:42 +0000 (09:16 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 31 Dec 2015 08:16:42 +0000 (09:16 +0100)
gui/baculum/tests/test_common.php [new file with mode: 0644]
gui/baculum/tests/units/Class/APITest.php [new file with mode: 0644]
gui/baculum/tests/units/Class/ConfigurationManagerApplicationSettingsTest.php [new file with mode: 0644]
gui/baculum/tests/units/Class/ConfigurationManagerTest.php [new file with mode: 0644]
gui/baculum/tests/units/Class/ConfigurationManagerUsersConfigTest.php [new file with mode: 0644]

diff --git a/gui/baculum/tests/test_common.php b/gui/baculum/tests/test_common.php
new file mode 100644 (file)
index 0000000..1e813f4
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2015 Marcin Haba
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+// Set framework in test run mode
+define('PRADO_TEST_RUN', true);
+
+define('BACULUM_ROOT_DIR', dirname(__FILE__) . '/../');
+define('FRAMEWORK_ROOT_DIR', BACULUM_ROOT_DIR . 'framework');
+define('BACKUP_FILES_PATH', '/tmp/baculum-unittest');
+
+set_include_path(dirname(__FILE__) . PATH_SEPARATOR . FRAMEWORK_ROOT_DIR . PATH_SEPARATOR . get_include_path());
+
+require_once(FRAMEWORK_ROOT_DIR . '/prado.php');
+
+class TApplicationTest extends TApplication {
+
+       public function run() {
+               $this->initApplication();
+       }
+}
+
+function copy_path($source, $destination) {
+       if (is_dir($source)) {
+               if (!is_dir($destination)) {
+                       mkdir($destination);
+               }
+               $path = dir($source);
+               while (($file = $path->read()) != false) {
+                       if ($file == '.' || $file == '..') {
+                               continue;
+                       }
+                       $pathDir = $source . '/' . $file;
+                       copy($pathDir, $destination . '/' . $file);
+               }
+               $path->close();
+       }
+}
+
+function remove_path($path, $only_content = false) {
+       if(is_dir($path)) {
+               $dir = dir($path);
+               while (($file = $dir->read()) != false) {
+                       if ($file == '.' || $file == '..') {
+                               continue;
+                       }
+                       $pathDir = $path . '/' . $file;
+                       unlink($pathDir);
+               }
+               if ($only_content === false) {
+                       rmdir(dirname($pathDir));
+               }
+       }
+}
+
+?>
diff --git a/gui/baculum/tests/units/Class/APITest.php b/gui/baculum/tests/units/Class/APITest.php
new file mode 100644 (file)
index 0000000..d8e54bd
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2015 Marcin Haba
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+require_once('test_common.php');
+
+/**
+ * Test cases to internal API client module.
+ *
+ * @author Marcin Haba
+ */
+class APITest extends PHPUnit_Framework_TestCase {
+
+       public static $application = null;
+
+       public function setUp() {
+               if (self::$application === null) {
+                       self::$application = new TApplicationTest(BACULUM_ROOT_DIR . 'protected');
+                       self::$application->run();
+               }
+               if (file_exists(BACULUM_ROOT_DIR . 'protected/Data')) {
+                       copy_path(BACULUM_ROOT_DIR . 'protected/Data', BACKUP_FILES_PATH);
+                       remove_path(BACULUM_ROOT_DIR . 'protected/Data', true);
+               }
+       }
+
+       public function tearDown() {
+               if (file_exists(BACKUP_FILES_PATH)) {
+                       remove_path(BACKUP_FILES_PATH . 'protected/Data', true);
+                       copy_path(BACKUP_FILES_PATH, BACULUM_ROOT_DIR . 'protected/Data');
+                       remove_path(BACKUP_FILES_PATH);
+               }
+       }
+
+       public function testApiVersion() {
+               $testData = array('result' => '0.1');
+               $apiModule = self::$application->getModule('api');
+               $this->assertEquals($testData['result'], $apiModule::API_VERSION);
+       }
+
+       public function testGetConnection() {
+               // prepare example config
+               $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
+               $testData['db']['type'] = 'pgsql';
+               $testData['db']['name'] = 'my database 123';
+               $testData['db']['login'] = 'admin321';
+               $testData['db']['password'] = 'Str0NgPa$$w0Rd';
+               $testData['db']['ip_addr'] = '127.0.0.1';
+               $testData['db']['port'] = '5433';
+               $testData['db']['path'] = '';
+               $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
+               $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
+               $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/bconsole-{user}.conf';
+               $testData['bconsole']['use_sudo'] = 1;
+               $testData['baculum']['login'] = 'ganiuszka';
+               $testData['baculum']['password'] = 'AnOTHe3Str0n6 Pass W OR d';
+               $testData['baculum']['debug'] = 0;
+               $testData['baculum']['lang'] = 'pl';
+
+               $testResult = array('type' => 'resource');
+
+               // save example config
+               self::$application->getModule('configuration')->setApplicationConfig($testData);
+
+               $result = self::$application->getModule('api')->getConnection();
+               $this->assertEquals($testResult['type'], gettype($result));
+       }
+}
+?>
diff --git a/gui/baculum/tests/units/Class/ConfigurationManagerApplicationSettingsTest.php b/gui/baculum/tests/units/Class/ConfigurationManagerApplicationSettingsTest.php
new file mode 100644 (file)
index 0000000..4cea1d4
--- /dev/null
@@ -0,0 +1,231 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2015 Marcin Haba
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+require_once('test_common.php');
+
+/**
+ * Test cases to read/write/check Baculum configuration file (settings.conf).
+ *
+ * @author Marcin Haba
+ */
+class ConfigurationManagerApplicationSettingsTest extends PHPUnit_Framework_TestCase {
+
+       public static $application = null;
+
+       public function setUp() {
+               if (self::$application === null) {
+                       self::$application = new TApplicationTest(BACULUM_ROOT_DIR . 'protected');
+                       self::$application->run();
+               }
+               if (file_exists(BACULUM_ROOT_DIR . 'protected/Data')) {
+                       copy_path(BACULUM_ROOT_DIR . 'protected/Data', BACKUP_FILES_PATH);
+                       remove_path(BACULUM_ROOT_DIR . 'protected/Data', true);
+               }
+       }
+
+       public function tearDown() {
+               if (file_exists(BACKUP_FILES_PATH)) {
+                       remove_path(BACKUP_FILES_PATH . 'protected/Data', true);
+                       copy_path(BACKUP_FILES_PATH, BACULUM_ROOT_DIR . 'protected/Data');
+                       remove_path(BACKUP_FILES_PATH);
+               }
+       }
+
+       public function testSetApplicationConfigPostgreSQL() {
+               $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
+               $testData['db']['type'] = 'pgsql';
+               $testData['db']['name'] = 'my database 123';
+               $testData['db']['login'] = 'admin321';
+               $testData['db']['password'] = 'Str0NgPa$$w0Rd';
+               $testData['db']['ip_addr'] = '127.0.0.1';
+               $testData['db']['port'] = '5433';
+               $testData['db']['path'] = '';
+               $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
+               $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
+               $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/bconsole-{user}.conf';
+               $testData['bconsole']['use_sudo'] = 1;
+               $testData['baculum']['login'] = 'ganiuszka';
+               $testData['baculum']['password'] = 'AnOTHe3Str0n6 Pass W OR d';
+               $testData['baculum']['debug'] = 0;
+               $testData['baculum']['lang'] = 'pl';
+               $resultContent = '[db]
+type = "pgsql"
+name = "my database 123"
+login = "admin321"
+password = "Str0NgPa$$w0Rd"
+ip_addr = "127.0.0.1"
+port = "5433"
+path = ""
+
+[bconsole]
+bin_path = "/usr/local/bacula/sbin/bconsole"
+cfg_path = "/usr/local/bacula/etc/bconsole.conf"
+cfg_custom_path = "/etc/bacula/bconsole-{user}.conf"
+use_sudo = "1"
+
+[baculum]
+login = "ganiuszka"
+password = "AnOTHe3Str0n6 Pass W OR d"
+debug = "0"
+lang = "pl"
+
+';
+               // check if config does not exist
+               $result = self::$application->getModule('configuration')->isApplicationConfig();
+               $this->assertFalse($result);
+
+               // check saving config
+               self::$application->getModule('configuration')->setApplicationConfig($testData);
+               $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/settings.conf');
+               // compare written config with expected string
+               $this->assertEquals($resultContent, $result);
+
+               // check if config already exists
+               $result = self::$application->getModule('configuration')->isApplicationConfig();
+               $this->assertTrue($result);
+
+               // check reading config
+               $configRead = self::$application->getModule('configuration')->getApplicationConfig();
+               // compare test data array with read application config as array
+               $this->assertEquals($testData, $configRead);
+       }
+
+       public function testSetApplicationConfigMySQL() {
+               $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
+               $testData['db']['type'] = 'mysql';
+               $testData['db']['name'] = 'mydatabase538';
+               $testData['db']['login'] = 'administrator';
+               $testData['db']['password'] = '#Str0NgPa$##$w0Rd^$#!&#*$@';
+               $testData['db']['ip_addr'] = '192.168.0.4';
+               $testData['db']['port'] = '3306';
+               $testData['db']['path'] = '';
+               $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
+               $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
+               $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/bconsole-{user}.conf';
+               $testData['bconsole']['use_sudo'] = 0;
+               $testData['baculum']['login'] = 'ganiuszka';
+               $testData['baculum']['password'] = 'Str0n6 Pass4W2OR d';
+               $testData['baculum']['debug'] = 1;
+               $testData['baculum']['lang'] = 'en';
+               $resultContent = '[db]
+type = "mysql"
+name = "mydatabase538"
+login = "administrator"
+password = "#Str0NgPa$##$w0Rd^$#!&#*$@"
+ip_addr = "192.168.0.4"
+port = "3306"
+path = ""
+
+[bconsole]
+bin_path = "/usr/local/bacula/sbin/bconsole"
+cfg_path = "/usr/local/bacula/etc/bconsole.conf"
+cfg_custom_path = "/etc/bacula/bconsole-{user}.conf"
+use_sudo = "0"
+
+[baculum]
+login = "ganiuszka"
+password = "Str0n6 Pass4W2OR d"
+debug = "1"
+lang = "en"
+
+';
+
+               // check if config does not exist
+               $result = self::$application->getModule('configuration')->isApplicationConfig();
+               $this->assertFalse($result);
+
+               // check saving config
+               self::$application->getModule('configuration')->setApplicationConfig($testData);
+               $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/settings.conf');
+               // compare written config with expected string
+               $this->assertEquals($resultContent, $result);
+
+               // check if config already exists
+               $result = self::$application->getModule('configuration')->isApplicationConfig();
+               $this->assertTrue($result);
+
+               // check reading config
+               $configRead = self::$application->getModule('configuration')->getApplicationConfig();
+               // compare test data array with read application config as array
+               $this->assertEquals($testData, $configRead);
+       }
+
+       public function testSetApplicationConfigSQLite() {
+               $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
+               $testData['db']['type'] = 'sqlite';
+               $testData['db']['name'] = 'bacula';
+               $testData['db']['login'] = 'bacula';
+               $testData['db']['password'] = '';
+               $testData['db']['ip_addr'] = '';
+               $testData['db']['port'] = '';
+               $testData['db']['path'] = '/home/gani/mydatabase.db';
+               $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
+               $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
+               $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/users/bconsole-{user}.conf';
+               $testData['bconsole']['use_sudo'] = 0;
+               $testData['baculum']['login'] = 'kekeke';
+               $testData['baculum']['password'] = 'kekeke';
+               $testData['baculum']['debug'] = 1;
+               $testData['baculum']['lang'] = 'en';
+               $resultContent = '[db]
+type = "sqlite"
+name = "bacula"
+login = "bacula"
+password = ""
+ip_addr = ""
+port = ""
+path = "/home/gani/mydatabase.db"
+
+[bconsole]
+bin_path = "/usr/local/bacula/sbin/bconsole"
+cfg_path = "/usr/local/bacula/etc/bconsole.conf"
+cfg_custom_path = "/etc/bacula/users/bconsole-{user}.conf"
+use_sudo = "0"
+
+[baculum]
+login = "kekeke"
+password = "kekeke"
+debug = "1"
+lang = "en"
+
+';
+               // check if config does not exist
+               $result = self::$application->getModule('configuration')->isApplicationConfig();
+               $this->assertFalse($result);
+
+               // check saving config
+               self::$application->getModule('configuration')->setApplicationConfig($testData);
+               $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/settings.conf');
+               // compare written config with expected string
+               $this->assertEquals($resultContent, $result);
+
+               // check if config already exists
+               $result = self::$application->getModule('configuration')->isApplicationConfig();
+               $this->assertTrue($result);
+
+               // check reading config
+               $configRead = self::$application->getModule('configuration')->getApplicationConfig();
+               // compare test data array with read application config as array
+               $this->assertEquals($testData, $configRead);
+       }
+}
+?>
diff --git a/gui/baculum/tests/units/Class/ConfigurationManagerTest.php b/gui/baculum/tests/units/Class/ConfigurationManagerTest.php
new file mode 100644 (file)
index 0000000..05cece2
--- /dev/null
@@ -0,0 +1,113 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2015 Marcin Haba
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+require_once('test_common.php');
+
+/**
+ * Basic Test cases to configuration manager module.
+ *
+ * @author Marcin Haba
+ */
+class ConfigurationManagerTest extends PHPUnit_Framework_TestCase {
+
+       public static $application = null;
+
+       public function setUp() {
+               if(self::$application === null) {
+                       self::$application = new TApplicationTest(BACULUM_ROOT_DIR . 'protected');
+                       self::$application->run();
+               }
+       }
+
+       public function testGetDbNameByTypeValid() {
+               $testData = array(
+                       'pgsql' => 'PostgreSQL',
+                       'mysql' => 'MySQL',
+                       'sqlite' => 'SQLite'
+               );
+               foreach ($testData as $shortName => $longName) {
+                       $result = self::$application->getModule('configuration')->getDbNameByType($shortName);
+                       $this->assertEquals($longName, $result);
+               }
+       }
+
+       public function testGetDbNameByTypeInvalid() {
+               $testData = array("pgsql\n", ' pgsql', ' pgsql ', 'Mysql', 'MYSQL', 'SQlite', 'MySqL', null, true, 0, -1);
+               for ($i = 0; $i < count($testData); $i++) {
+                       $result = self::$application->getModule('configuration')->getDbNameByType($testData[$i]);
+                       $this->assertNull($result);
+               }
+       }
+
+       public function testIsPostgreSQLTypeValid() {
+               $testData = 'pgsql';
+               $result = self::$application->getModule('configuration')->isPostgreSQLType($testData);
+               $this->assertTrue($result);
+       }
+
+       public function testIsPostgreSQLTypeInvalid() {
+               $testData = array("pgsql\n", ' pgsql', ' pgsql ', 'mysql', 'MYSQL', 'sqlite', 'MySqL', null, true, 0, -1);
+               for ($i = 0; $i < count($testData); $i++) {
+                       $result = self::$application->getModule('configuration')->isPostgreSQLType($testData[$i]);
+                       $this->assertFalse($result);
+               }
+       }
+
+       public function testIsMySQLTypeValid() {
+               $testData = 'mysql';
+               $result = self::$application->getModule('configuration')->isMySQLType($testData);
+               $this->assertTrue($result);
+       }
+
+       public function testIsMySQLTypeInvalid() {
+               $testData = array("mysql\n", ' mysql', ' mysql ', 'm ysql', 'MYSQ', 'sqlite', 'pgsql', 'mysq', null, true, 0, -1);
+               for ($i = 0; $i < count($testData); $i++) {
+                       $result = self::$application->getModule('configuration')->isMySQLType($testData[$i]);
+                       $this->assertFalse($result);
+               }
+       }
+       public function testIsSQLiteTypeValid() {
+               $testData = 'sqlite';
+               $result = self::$application->getModule('configuration')->isSQLiteType($testData);
+               $this->assertTrue($result);
+       }
+
+       public function testIsSQLiteTypeInvalid() {
+               $testData = array("sqlite\n", ' sqlite', ' sqlite ', 's qlite', 'sqlit', 'pgsql', 'mysqs', null, true, 0, -1);
+               for ($i = 0; $i < count($testData); $i++) {
+                       $result = self::$application->getModule('configuration')->isSQLiteType($testData[$i]);
+                       $this->assertFalse($result);
+               }
+       }
+
+       public function testGetDefaultLanguageValid() {
+               $mockData = false;
+               $testData = 'en';
+
+               $mock = $this->getMockBuilder('ConfigurationManager')->setMethods(array('isApplicationConfig'))->getMock();
+               $mock->expects($this->once())->method('isApplicationConfig')->will($this->returnValue($mockData));
+               $result = $mock->getLanguage();
+               $this->assertEquals($testData, $result);
+       }
+}
+
+?>
diff --git a/gui/baculum/tests/units/Class/ConfigurationManagerUsersConfigTest.php b/gui/baculum/tests/units/Class/ConfigurationManagerUsersConfigTest.php
new file mode 100644 (file)
index 0000000..69ac8f8
--- /dev/null
@@ -0,0 +1,160 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2015 Marcin Haba
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+require_once('test_common.php');
+
+/**
+ * Test cases to read/write/check Baculum users file (baculum.users).
+ *
+ * @author Marcin Haba
+ */
+class ConfigurationManagerUsersConfigTest extends PHPUnit_Framework_TestCase {
+
+       public static $application = null;
+
+       public function setUp() {
+               if (self::$application === null) {
+                       self::$application = new TApplicationTest(BACULUM_ROOT_DIR . 'protected');
+                       self::$application->run();
+               }
+               if (file_exists(BACULUM_ROOT_DIR . 'protected/Data')) {
+                       copy_path(BACULUM_ROOT_DIR . 'protected/Data', BACKUP_FILES_PATH);
+                       remove_path(BACULUM_ROOT_DIR . 'protected/Data', true);
+               }
+       }
+
+       public function tearDown() {
+               if (file_exists(BACKUP_FILES_PATH)) {
+                       remove_path(BACKUP_FILES_PATH . 'protected/Data', true);
+                       copy_path(BACKUP_FILES_PATH, BACULUM_ROOT_DIR . 'protected/Data');
+                       remove_path(BACKUP_FILES_PATH);
+               }
+       }
+
+       public function testSetUsersConfig() {
+               $testData = array();
+               $testData[] = array( // create new user admin432
+                       'data' => array(
+                               'user' => 'admin432',
+                               'password' => 'myStrOnGPa$$!',
+                               'firstusage' => true,
+                               'olduser' => null
+                       ),
+                       'result' => 'admin432:bXOrb7VkxRBYY'
+               );
+               $testData[] = array( // add user willyWonka to config
+                       'data' => array(
+                               'user' => 'willyWonka',
+                               'password' => '#=ChOcOlAtEE=#',
+                               'firstusage' => false,
+                               'olduser' => null
+                       ),
+                       'result' => "admin432:bXOrb7VkxRBYY\nwillyWonka:IzGy5zT.vOaeI"
+               );
+               $testData[] = array( // clear users config and create user willyWonka again
+                       'data' => array(
+                               'user' => 'willyWonka',
+                               'password' => '#=ChOcOlAtEE=#',
+                               'firstusage' => true,
+                               'olduser' => null
+                       ),
+                       'result' => "willyWonka:IzGy5zT.vOaeI"
+               );
+               $testData[] = array( // add user donkamillo to config
+                       'data' => array(
+                               'user' => 'donkamillo',
+                               'password' => '!@#$%^&*()_+}{|"\'<>?/.,',
+                               'firstusage' => false,
+                               'olduser' => null
+                       ),
+                       'result' => "willyWonka:IzGy5zT.vOaeI\ndonkamillo:IU029IHEUYWhY"
+               );
+               $testData[] = array( // rename user willyWonka to user johny11
+                       'data' => array(
+                               'user' => 'johny11',
+                               'password' => '#=ChOcOlAtEE=#',
+                               'firstusage' => false,
+                               'olduser' => 'willyWonka'
+                       ),
+                       'result' => "donkamillo:IU029IHEUYWhY\njohny11:IzGy5zT.vOaeI"
+               );
+               $testData[] = array( // change password for user johny11
+                       'data' => array(
+                               'user' => 'johny11',
+                               'password' => 'CoffeeAndTee!@#$%^&*()_+}{|"\'<>?/.:,',
+                               'firstusage' => false,
+                               'olduser' => null
+                       ),
+                       'result' => "donkamillo:IU029IHEUYWhY\njohny11:Q2XfKovUGQe52"
+               );
+               $testData[] = array( // input the same password again for user johny11
+                       'data' => array(
+                               'user' => 'johny11',
+                               'password' => 'CoffeeAndTee!@#$%^&*()_+}{|"\'<>?/.:,',
+                               'firstusage' => false,
+                               'olduser' => null
+                       ),
+                       'result' => "donkamillo:IU029IHEUYWhY\njohny11:Q2XfKovUGQe52"
+               );
+               for ($i = 0; $i < count($testData); $i++) {
+                       $result = self::$application->getModule('configuration')->setUsersConfig(
+                               $testData[$i]['data']['user'],
+                               $testData[$i]['data']['password'],
+                               $testData[$i]['data']['firstusage'],
+                               $testData[$i]['data']['olduser']
+                       );
+                       $this->assertTrue($result);
+                       $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/baculum.users');
+                       $this->assertEquals($testData[$i]['result'], $result);
+               }
+       }
+
+       public function testCheckAndClearUsersConfig() {
+               $testData[] = array( // input the same password again for user johny11
+                       'data' => array(
+                               'user' => 'johny11',
+                               'password' => 'CoffeeAndTee!@#$%^&*()_+}{|"\'<>?/.:,',
+                               'firstusage' => false,
+                               'olduser' => null
+                       ),
+                       'result' => "johny11:Q2XfKovUGQe52"
+               );
+               $result = self::$application->getModule('configuration')->isUsersConfig();
+               $this->assertFalse($result);
+               for ($i = 0; $i < count($testData); $i++) {
+                       $result = self::$application->getModule('configuration')->setUsersConfig(
+                               $testData[$i]['data']['user'],
+                               $testData[$i]['data']['password'],
+                               $testData[$i]['data']['firstusage'],
+                               $testData[$i]['data']['olduser']
+                       );
+                       $this->assertTrue($result);
+                       $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/baculum.users');
+                       $this->assertEquals($testData[$i]['result'], $result);
+               }
+               $result = self::$application->getModule('configuration')->isUsersConfig();
+               $this->assertTrue($result);
+               $result = self::$application->getModule('configuration')->clearUsersConfig();
+               $this->assertTrue($result);
+       }
+}
+?>