Implemented a fall-back if the first compressor class doesn't work
[core.git] / tests / RegistryTest.php
1 <?php
2 print (basename(__FILE__).": Init...\n");
3
4 // Change directory
5 @chdir("..");
6
7 // Load config file
8 require(dirname(dirname(__FILE__)) . '/inc/config.php');
9
10 // Load all include files
11 require($cfg->getConfigEntry('base_path') . 'inc/includes.php');
12
13 // Load all game classes
14 require($cfg->getConfigEntry('base_path') . 'inc/classes.php');
15
16 // Set default application
17 FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'ship-simu');
18
19 // Set testing mode (no starter.php will be loaded!)
20 define('TEST_MODE', true);
21
22 // Load the PHPUnit framework
23 require('PHPUnit/Framework.php');
24
25 print (basename(__FILE__).": Init completed.\n\n");
26
27 /**
28  * A test case for the registry
29  *
30  * @author              Roland Haeder <webmaster@ship-simu.org>
31  * @version             0.0.0
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
36  *
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.
41  *
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.
46  *
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/>.
49  */
50 class RegistryTest extends PHPUnit_Framework_TestCase {
51         /**
52          * Tests if we can store an instance to the registry
53          *
54          * @return void
55          */
56         public function testInstanceRegistryAdd () {
57                 // Get a registry instance
58                 $registryInstance = Registry::getRegistry();
59
60                 // Create a User instance
61                 $userInstance = Member::createMemberByEmail("webmaster@ship-simu.org");
62
63                 // Now store the instance in the registry
64                 $registryInstance->addInstance('user', $userInstance);
65
66                 // Test if the registry key is there
67                 if (!$registryInstance->instanceExists('user')) {
68                         $this->fail("Registry test failed: Cannot locate our user instance in registry!");
69                 }
70         }
71
72         /**
73          * Tests if we can store an instance to the registry
74          *
75          * @return void
76          */
77         public function testInstanceRegistryCompare () {
78                 // Get a registry instance
79                 $registryInstance = Registry::getRegistry();
80
81                 // And get it back
82                 $userInstance = $registryInstance->getInstance('user');
83
84                 // Compare both unique keys
85                 $testPassed = ($userInstance instanceof ManageableAccount);
86
87                 // Test passed?
88                 if (!$testPassed) {
89                         $this->fail("Registry test failed: Method getInstance() returned a non-object.");
90                 }
91         }
92 }
93
94 ?>