3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2016 Kern Sibbald
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 * Test cases to internal API client module.
30 class APITest 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();
39 if (file_exists(BACULUM_ROOT_DIR . 'protected/Data')) {
40 copy_path(BACULUM_ROOT_DIR . 'protected/Data', BACKUP_FILES_PATH);
41 remove_path(BACULUM_ROOT_DIR . 'protected/Data', true);
45 public function tearDown() {
46 if (file_exists(BACKUP_FILES_PATH)) {
47 remove_path(BACKUP_FILES_PATH . 'protected/Data', true);
48 copy_path(BACKUP_FILES_PATH, BACULUM_ROOT_DIR . 'protected/Data');
49 remove_path(BACKUP_FILES_PATH);
53 public function testApiVersion() {
54 $testData = array('result' => '0.1');
55 $apiModule = self::$application->getModule('api');
56 $this->assertEquals($testData['result'], $apiModule::API_VERSION);
59 public function testGetConnection() {
60 // prepare example config
61 $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
62 $testData['db']['type'] = 'pgsql';
63 $testData['db']['name'] = 'my database 123';
64 $testData['db']['login'] = 'admin321';
65 $testData['db']['password'] = 'Str0NgPa$$w0Rd';
66 $testData['db']['ip_addr'] = '127.0.0.1';
67 $testData['db']['port'] = '5433';
68 $testData['db']['path'] = '';
69 $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
70 $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
71 $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/bconsole-{user}.conf';
72 $testData['bconsole']['use_sudo'] = 1;
73 $testData['baculum']['login'] = 'ganiuszka';
74 $testData['baculum']['password'] = 'AnOTHe3Str0n6 Pass W OR d';
75 $testData['baculum']['debug'] = 0;
76 $testData['baculum']['lang'] = 'pl';
78 $testResult = array('type' => 'resource');
80 // save example config
81 self::$application->getModule('configuration')->setApplicationConfig($testData);
83 $result = self::$application->getModule('api')->getConnection();
84 $this->assertEquals($testResult['type'], gettype($result));