Updated a little unmaintained test cases (they need to be run sooner or later).
[core.git] / tests / RequestTest.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', 'shipsimu');
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 faked HTTP requests. This is faked because we *set*
29  * $_REQUEST here. This should be made better in PHP6... :(
30  *
31  * @author              Roland Haeder <webmaster@shipsimu.org>
32  * @version             0.0.0
33  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
34  * @license             GNU GPL 3.0 or any newer version
35  * @link                http://www.shipsimu.org
36  * @see                 http://www.phpunit.de
37  *
38  * This program is free software: you can redistribute it and/or modify
39  * it under the terms of the GNU General Public License as published by
40  * the Free Software Foundation, either version 3 of the License, or
41  * (at your option) any later version.
42  *
43  * This program is distributed in the hope that it will be useful,
44  * but WITHOUT ANY WARRANTY; without even the implied warranty of
45  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46  * GNU General Public License for more details.
47  *
48  * You should have received a copy of the GNU General Public License
49  * along with this program. If not, see <http://www.gnu.org/licenses/>.
50  */
51 class RequestTest extends PHPUnit_Framework_TestCase {
52         /**
53          * A non-exist request element is being asked for. null is the expected
54          * result from the class
55          *
56          * @return      void
57          */
58         public function testMissingRequestElement () {
59                 // Get a request instance
60                 $requestInstance = HtmlRequest::createHtmlRequest();
61
62                 // Get the element
63                 $nonExist = $requestInstance->getRequestElement('never_there');
64
65                 // Is this null?
66                 if (!is_null($nonExist)) {
67                         // Is not null!
68                         $this->fail(sprintf("[%s:] Unexpected type %s received from request handler.",
69                                 $requestInstance->__toString(),
70                                 gettype($nonExists)
71                         ));
72                 }
73         }
74
75         /**
76          * Now fake a request array and try the test on it again
77          *
78          * @return      void
79          */
80         public function testFakeRequestElement () {
81                 // Fake the request here
82                 $_REQUEST = array('test_key' => 'test_value');
83
84                 // Again get an instance
85                 $requestInstance = HtmlRequest::createHtmlRequest();
86
87                 // Get the element
88                 $testValue = $requestInstance->getRequestElement('test_key');
89
90                 // Is it the same?
91                 if ($testValue !== 'test_value') {
92                         // Something went wrong
93                         $this->fail(sprintf('[%s] Unexpected value %s (%s) from test key received.',
94                                 $requestInstance->__toString(),
95                                 $testValue,
96                                 gettype($testValue)
97                         ));
98                 }
99         }
100 }
101
102 ?>