2 print (basename(__FILE__).": Init...\n");
8 require(dirname(dirname(__FILE__)) . '/inc/config.php');
10 // Load all include files
11 require($cfg->getConfigEntry('base_path') . 'inc/includes.php');
13 // Load all game classes
14 require($cfg->getConfigEntry('base_path') . 'inc/classes.php');
16 // Set default application
17 FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'ship-simu');
19 // Set testing mode (no starter.php will be loaded!)
20 define('TEST_MODE', true);
22 // Load the PHPUnit framework
23 require('PHPUnit/Framework.php');
25 print (basename(__FILE__).": Init completed.\n\n");
28 * A test case for the configuration sub system
30 * @author Roland Haeder <webmaster@ship-simu.org>
32 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
33 * @license GNU GPL 3.0 or any newer version
34 * @link http://www.ship-simu.org
35 * @see http://www.phpunit.de
37 * This program is free software: you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation, either version 3 of the License, or
40 * (at your option) any later version.
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
47 * You should have received a copy of the GNU General Public License
48 * along with this program. If not, see <http://www.gnu.org/licenses/>.
50 class ConfigTest extends PHPUnit_Framework_TestCase {
52 * Tests the exception ConfigEntryNotFoundException if it is being thrown.
53 * Else the test shall fail
57 public function testConfigEntryNotFoundException () {
61 // Now find a configuration variable that does not exist
62 $dummy = FrameworkConfiguration::getInstance()->getConfigEntry('does_not_exist');
63 } catch (ConfigEntryNotFoundException $expected) {
64 // This exception was expected, so it is fine
66 } catch (FrameworkException $unexptected) {
67 // This exception was not expected!
68 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
72 // This test went wrong
73 $this->fail("Test of thrown exception ConfigEntryNotFoundException failed!");
78 * Tests if the exception ConfigEntryIsEmptyException is being thrown by
79 * "emulating" an empty configuration variable.
83 public function testConfigEntryIsEmptyExceptionRead () {
87 // Try to read an empty configuration variable
88 $dummy = FrameworkConfiguration::getInstance()->getConfigEntry('');
89 } catch (ConfigEntryIsEmptyException $expected) {
90 // This exception was expected, so it is fine
92 } catch (FrameworkException $unexptected) {
93 // This exception was not expected!
94 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
98 // This test went wrong
99 $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
104 * Tests if the exception ConfigEntryIsEmptyException is being thrown by
105 * "emulating" an empty configuration variable.
109 public function testConfigEntryIsEmptyExceptionWrite () {
113 // Try to read an empty configuration variable
114 FrameworkConfiguration::getInstance()->setConfigEntry('', 'will_never_be_set');
115 } catch (ConfigEntryIsEmptyException $expected) {
116 // This exception was expected, so it is fine
118 } catch (FrameworkException $unexptected) {
119 // This exception was not expected!
120 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
124 // This test went wrong
125 $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
130 * Tests if a set value can be returned from the configuration sub-system
134 public function testWritegetConfigEntryEntry () {
136 $value = "This is a test value";
138 // Try to read an empty configuration variable
139 FrameworkConfiguration::getInstance()->setConfigEntry('test_key', "{$value}");
141 // Read the config entry we have just written
142 $readValue = FrameworkConfiguration::getInstance()->getConfigEntry('test_key');
144 // Now test the values
145 $this->assertEquals($value, $readValue);
146 } catch (FrameworkException $unexptected) {
147 // This exception was not expected!
148 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));