3
3
* $RCSfile: PhpVmTest.class,v $
5
5
* Gallery - a web based photo album viewer and editor
6
* Copyright (C) 2000-2005 Bharat Mediratta
6
* Copyright (C) 2000-2006 Bharat Mediratta
8
8
* This program is free software; you can redistribute it and/or modify
9
9
* it under the terms of the GNU General Public License as published by
20
20
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
23
* @version $Revision: 1.6 $ $Date: 2005/08/23 03:49:33 $
23
* @version $Revision: 1.8 $ $Date: 2006/01/30 23:00:21 $
24
24
* @package GalleryCore
25
25
* @subpackage PHPUnit
26
26
* @author Jay Rossiter <cryptographite@users.sf.net>
29
GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryPhpVm.class');
29
GalleryCoreApi::requireOnce('modules/core/classes/GalleryPhpVm.class');
32
32
* Test the GalleryPhpVm. These are passthrough functions so all we do is perform a smoke test to
88
88
function testHeader() {
92
92
* This test also depends on the G2 Session code as we do an actual HTTP request and
93
93
* verify that we received a cookie header. GallerySession uses the $phpVm->header()
94
94
* function, thus this covers what we'd like to test (and a little more)
96
$session =& $gallery->getSession();
97
96
$urlGenerator =& $gallery->getUrlGenerator();
98
$url = $urlGenerator->getCurrentUrl();
99
/* Strip of the /lib/tools/test/ part to get a valid G2 request uri */
100
$url = preg_replace('|^(.*/)lib/tools/.*$|', '$1', $url);
101
list ($body, $response, $headers) = GalleryCoreApi::fetchWebPage($url);
97
$url = $urlGenerator->generateUrl(array('href' => 'main.php'),
98
array('forceFullUrl' => true));
100
/* For guests, we don't send cookies, thus prepare an existing session */
101
GalleryCoreApi::requireOnce('modules/core/classes/GallerySession.class');
102
$session = new GallerySession();
103
$ret = $session->initEmpty(true);
105
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
107
$this->assert(!empty($session->_sessionId), 'persistent session preparation failed');
108
$url = GalleryUrlGenerator::appendParamsToUrl(
109
$url, array($session->getKey() => $session->getId()));
111
list ($success, $body, $response, $headers) = GalleryCoreApi::fetchWebPage($url);
112
$this->assert($success, 'Could not retrieve G2 page');
102
113
$this->assertEquals($response, 'HTTP/1.1 200 OK', 'Could not retrieve G2 page');
103
114
$this->assertEquals(true, isset($headers['Set-Cookie']), 'Set-Cookie header not set');
104
115
if (isset($headers['Set-Cookie'])) {
105
$this->assert(strpos($headers['Set-Cookie'], SESSION_ID_PARAMETER) !== false,
106
'no G2 SessionId found in the cookie header');
116
$this->assert(strpos($headers['Set-Cookie'],
117
SESSION_ID_PARAMETER . '=' . $session->getId()) !== false,
118
'no G2 SessionId with a correct SID found in the cookie header');
108
$this->assert(false, 'no cookie header found in http response');
120
$this->assert(false, 'no cookie header found in http response for url: ' . $url);
115
127
/* When this unit test is executed, we already sent some data to the user agent */
116
128
$phpVm = $gallery->getPhpVm();
117
$this->assert($phpVm->headers_sent(), 'headers are sent at this point, but the vm function ' .
118
'does not think so');
129
$this->assert($phpVm->headers_sent(), 'headers are sent at this point, but the vm ' .
130
'function does not think so');
120
132
/* The other case, $phpVm->headers_sent() == false, is covered by testHeader() */
125
137
$this->assertEquals(get_magic_quotes_gpc(), $this->_phpVm->get_magic_quotes_gpc(),
126
138
'The Vm function does not return the correct value');
141
function testTime() {
143
* There's an incredibly slim chance that this will fail. If it does, we should improve
146
$this->assertEquals(time(), $this->_phpVm->time());
149
function testRand() {
150
$this->assert(is_int(rand()), 'is int');
151
$this->assert(rand() > 0, 'is positive');
152
for ($i = 0; $i < 50; $i++) {
153
$rand = rand(1000, 1010);
154
$this->assert($rand >= 1000 && $rand <= 1010, 'with minimum and maximum');