source: trunk/tests/AppTest.php @ 1

Last change on this file since 1 was 1, checked in by scdev, 19 years ago

Initial import.

File size: 5.1 KB
Line 
1<?php
2/**
3 * PHPUnit test case for App
4 *
5 * The method skeletons below need to be filled in with
6 * real data so that the tests will run correctly. Replace
7 * all EXPECTED_VAL and PARAM strings with real data.
8 *
9 * Created with PHPUnit_Skeleton on 2005-08-09
10 */
11require_once 'PHPUnit.php';
12class AppTest extends PHPUnit_TestCase {
13
14    var $App;
15
16    function AppTest($name)
17    {
18        $this->PHPUnit_TestCase($name);
19    }
20
21    function setUp()
22    {
23        require dirname(__FILE__) . '/_config.inc.php';
24        $this->App =& $app;
25    }
26
27    function tearDown()
28    {
29        unset($this->App);
30    }
31
32    function test_getinstance()
33    {
34        $thisapp =& App::getinstance();
35        $this->assertTrue(serialize($thisapp) == serialize($this->App), 'Objects do not match across instantiations.');
36    }
37
38    function test_setParam()
39    {
40        $this->App->setParam(array(
41            'test_config_value' => 1234
42        ));
43        $this->assertTrue(1234 === $this->App->_params['test_config_value']);
44    }
45
46    function test_getParam()
47    {
48        $this->App->_params['test_config_value2'] = 'okay';
49        $result = $this->App->getParam('test_config_value2');
50        $this->assertEquals('okay', $result);
51    }
52
53    function test_start()
54    {
55        unset($_SESSION);
56        $this->App->stop();
57        $this->App->start();
58
59        $this->assertEquals(ini_get('error_reporting'), E_ALL, 'Error reporting not set to E_ALL.');
60        $this->assertTrue($this->App->db->dbh && is_resource($this->App->db->dbh), 'DB handler not a resource');
61        $this->assertTrue(isset($_SESSION), '$_SESSION is not set.');
62        $_SESSION['sess_test_value'] = 'okay';
63        $this->assertEquals($_SESSION['sess_test_value'], 'okay', '$_SESSION not storing values.');
64        $this->assertTrue(session_name() == 'StrangecodeTestSession', 'Session_name not set correctly.');
65    }
66
67    function test_stop()
68    {
69    }
70
71    function test_dbquery()
72    {
73        $qid = DB::query("SELECT 2 + 2");
74        list($result) = mysql_fetch_row($qid);
75        $this->assertEquals('4', $result);
76    }
77
78    function test_raisemsg()
79    {
80        $expected = 'My message';
81        App::raiseMsg($expected, MSG_NOTICE, __FILE__, __LINE__);
82        $msg = current($_SESSION[$this->App->app]['messages']);
83        $this->assertEquals($expected, $msg['message']);
84    }
85
86    function test_printraisedmessages()
87    {
88        ob_start();
89        App::printraisedmessages();
90        $result = ob_get_clean();
91        $this->assertContains('My message', $result, 'Raised message not found in output.');
92    }
93
94    function test_logmsg()
95    {
96        $file = $this->App->getParam('log_directory') . '/' . $this->App->getParam('log_filename');
97        App::logMsg('Test log message', LOG_DEBUG, __FILE__, __LINE__);
98        if ($result = file($file)) {
99            $result = end($result);
100        } else {
101            $result = '';
102        }
103        $this->assertContains('Test log message', $result, 'Test message not recorded in log: ' . $file);
104    }
105
106    function test_ohref()
107    {
108        $_GET['arg1'] = 'A';
109        $result = App::ohref('/some/url.php', array('arg1'), true);
110        $this->assertContains(session_name(), $result, 'SSID not found in URL.');
111        $this->assertContains('arg1=A', $result, 'Argument not passed through.');
112    }
113
114    function test_printhiddensession()
115    {
116        ob_start();
117        App::printhiddensession();
118        $result = ob_get_clean();
119        $this->assertContains(session_name(), $result);
120    }
121
122//     function test_dieurl()
123//     {
124//         App::dieURL('/die/to/this/url.php');
125//     }
126//
127//     function test_dieboomerangurl()
128//     {
129//         $result = $this->App->dieboomerangurl(PARAM);
130//         $expected = EXPECTED_VAL;
131//         $this->assertEquals($expected, $result);
132//     }
133//
134//     function test_setboomerangurl()
135//     {
136//         $result = $this->App->setboomerangurl(PARAM);
137//         $expected = EXPECTED_VAL;
138//         $this->assertEquals($expected, $result);
139//     }
140//
141//     function test_getboomerangurl()
142//     {
143//         $result = $this->App->getboomerangurl(PARAM);
144//         $expected = EXPECTED_VAL;
145//         $this->assertEquals($expected, $result);
146//     }
147//
148//     function test_deleteboomerangurl()
149//     {
150//         $result = $this->App->deleteboomerangurl(PARAM);
151//         $expected = EXPECTED_VAL;
152//         $this->assertEquals($expected, $result);
153//     }
154//
155//     function test_validboomerangurl()
156//     {
157//         $result = $this->App->validboomerangurl(PARAM);
158//         $expected = EXPECTED_VAL;
159//         $this->assertEquals($expected, $result);
160//     }
161//
162//     function test_sslon()
163//     {
164//         $result = $this->App->sslon(PARAM);
165//         $expected = EXPECTED_VAL;
166//         $this->assertEquals($expected, $result);
167//     }
168//
169//     function test_ssloff()
170//     {
171//         $result = $this->App->ssloff(PARAM);
172//         $expected = EXPECTED_VAL;
173//         $this->assertEquals($expected, $result);
174//     }
175
176}
177// Running the test.
178$suite = new PHPUnit_TestSuite('AppTest');
179$result = PHPUnit::run($suite);
180echo $result->toString();
181?>
Note: See TracBrowser for help on using the repository browser.