3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2007 Bharat Mediratta
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
22
* URL generator tests.
23
* @package GalleryCore
25
* @author Bharat Mediratta <bharat@menalto.com>
26
* @version $Revision: 15792 $
28
class UrlGeneratorTest extends GalleryTestCase {
32
function UrlGeneratorTest($methodName) {
33
$this->GalleryTestCase($methodName);
38
$_SERVER['REQUEST_URI'] = '/gallery2/phpunit_test.php?foo=bar';
39
$_SERVER['HTTP_HOST'] = 'example.com';
40
$_SERVER['SERVER_PORT'] = 80;
42
/* PHP/CGI sets PATH_INFO, but we don't want that for our tests */
43
unset($_SERVER['PATH_INFO']);
45
/* For the cookie.path */
46
$ret = $this->_markPluginParametersForCleanup('module', 'core');
48
print $ret->getAsHtml();
52
$this->_urlGenerator = new GalleryUrlGenerator();
53
$ret = $this->_urlGenerator->init('phpunit_test.php');
55
print $ret->getAsHtml();
59
$this->_origEmbed = null;
60
if (GalleryDataCache::containsKey('G2_EMBED')) {
61
$this->_origEmbed = GalleryDataCache::get('G2_EMBED');
67
$session =& $gallery->getSession();
69
if ($this->_origEmbed) {
70
GalleryDataCache::put('G2_EMBED', $this->_origEmbed, true);
72
GalleryDataCache::remove('G2_EMBED');
73
$this->assert(!GalleryDataCache::containsKey('G2_EMBED'), 'Could not remove a GDC var');
75
$session->remove('core.authToken');
81
* Initiates a new url generator
83
function _initNewUrlGenerator($baseUri=null, $g2Uri=null, $embedSessionString=null) {
84
$this->_urlGenerator = new GalleryUrlGenerator();
85
$baseUri = !isset($baseUri) ? 'phpunit_test.php' : $baseUri;
86
return $this->_urlGenerator->init($baseUri, $g2Uri, $embedSessionString);
90
* Set the cookie path to a new value / or make sure it isn't set. Then init the session
91
* again, since the session and the Url Generator are both involved in this matter.
93
function _prepareGenerateUrl($cookiePath, $baseUri, $g2Uri, $embedSessionString=null) {
97
* Configure the cookie path:
98
* - if empty (=not set): g2 should append the session id to embedded downloaditem requests
99
* - else, no session id has to be appended
101
$ret = GalleryCoreApi::setPluginParameter('module', 'core', 'cookie.path', $cookiePath);
103
return array($ret, null, null);
105
/* Check if the correct value was stored */
106
list ($ret, $realValue) = GalleryCoreApi::getPluginParameter('module', 'core',
109
return array($ret, null, null);
111
$this->assertEquals($cookiePath, $realValue, 'Could not reset cookie path');
113
/* Let the url generator know of the new cookie.path value */
114
$this->_urlGenerator = new GalleryUrlGenerator();
115
$ret = $this->_urlGenerator->init($baseUri, $g2Uri, $embedSessionString);
117
return array($ret, null, null);
119
$gallery->setUrlGenerator($this->_urlGenerator);
120
/* Let the session know of the new cookie.path value */
121
$session = new GallerySession();
122
$ret = $session->init();
124
return array($ret, null, null);
126
$session->put('foo', 1);
127
$ret = $session->start();
129
return array($ret, null, null);
132
$gallery->_session = $session;
135
$params['b'] = 'bBbB';
136
$params['c'] = serialize(array(1, 2, 3));
137
$params['d'] = array('<', 2);
139
$values[] = GalleryUtilities::prefixFormVariable('a') . '=' . urlencode('123');
140
$values[] = GalleryUtilities::prefixFormVariable('b') . '=' . urlencode('bBbB');
141
$values[] = GalleryUtilities::prefixFormVariable('c') . '=' .
142
urlencode(serialize(array(1, 2, 3)));
143
$values[] = GalleryUtilities::prefixFormVariable(urlencode('d[0]')) . '=' . urlencode('<');
144
$values[] = GalleryUtilities::prefixFormVariable(urlencode('d[1]')) . '=' . urlencode('2');
146
return array(null, $params, $values);
149
function testGenerateUrl() {
152
/* Make sure the cookie path is not set etc. */
153
list ($ret, $params, $values) = $this->_prepareGenerateUrl('', 'phpunit_test.php', null);
155
$this->failWithStatus($ret);
157
$session =& $gallery->getSession();
159
$actual = $this->_urlGenerator->generateUrl($params);
161
/* If we're not using cookies, expect there to be an additional value */
162
$session =& $gallery->getSession();
163
if (!$session->isUsingCookies()) {
164
$values[] = GalleryUtilities::prefixFormVariable($session->getKey()) .
165
'=' . urlencode($session->getId());
167
$expected = 'phpunit_test.php?' . join('&', $values);
169
$this->assertEquals($expected, $actual);
172
function testGenerateUrlEmbeddedFullBaseUri() {
173
/* Simulate embbeded with full url as embedUri */
174
$_SERVER['REQUEST_URI'] = '/cms/otherpage?foo=bar';
175
GalleryDataCache::put( 'G2_EMBED', 1, true);
176
list ($ret, $params, $values) =
177
$this->_prepareGenerateUrl('',
178
'http://example.com/cms/phpunit_test.php?module=gallery2',
181
$this->failWithStatus($ret);
184
$this->assertEquals('/cms/phpunit_test.php?module=gallery2&' .
185
implode('&', $values), $this->_urlGenerator->generateUrl($params),
189
function testGenerateUrlEmbeddedPathBaseUri() {
190
/* Simulate embedded, only path + uri */
191
$_SERVER['REQUEST_URI'] = '/cms/phpunit_test.php?module=gallery2&foo=bar';
192
GalleryDataCache::put('G2_EMBED', 1, true);
194
list ($ret, $params, $values) =
195
$this->_prepareGenerateUrl('', '/cms/phpunit_test.php?module=gallery2', '/gallery2/');
197
$this->failWithStatus($ret);
200
$this->assertEquals('phpunit_test.php?module=gallery2&' .
201
implode('&', $values), $this->_urlGenerator->generateUrl($params),
205
function testGenerateUrlCookielessEmbedded() {
208
/* Simulate cookieless embedded */
209
$_SERVER['REQUEST_URI'] = '/cms/phpunit_test.php?module=gallery2&foo=bar';
210
GalleryDataCache::put( 'G2_EMBED', 1, true);
211
list ($ret, $params, $values) =
212
$this->_prepareGenerateUrl('', '/cms/phpunit_test.php?module=gallery2',
213
'/gallery2/', 'CMSSID=123456');
215
$this->failWithStatus($ret);
217
$session =& $gallery->getSession();
219
$this->assertEquals('phpunit_test.php?module=gallery2&' .
220
implode('&', $values) . '&CMSSID=123456',
221
$this->_urlGenerator->generateUrl($params,
222
array('forceSessionId' => true)),
223
'cookieless embedded');
225
$this->assertEquals('/gallery2/main.php?g2_view=' .
226
urlencode('core.DownloadItem') . '&g2_itemId=12345&' .
227
GalleryUtilities::prefixFormVariable($session->getKey()) . '=' .
228
urlencode($session->getId()),
229
$this->_urlGenerator->generateUrl(array('view' => 'core.DownloadItem',
231
array('forceSessionId' => true)),
232
'core.DownloadItem always direct-g2 url, even when embedded');
234
$this->assertEquals('/gallery2/main.php?g2_view=' .
235
urlencode('test.View') . '&g2_param=12345',
236
$this->_urlGenerator->generateUrl(
237
array('view' => 'test.View', 'param' => 12345),
238
array('forceDirect' => true,
239
'forceSessionId' => false)),
240
'force direct-g2 url, even when embedded');
243
function testGenerateUrlForView() {
244
$this->assertEquals('phpunit_test.php?g2_view=' . urlencode('test.View') .
245
'&g2_param=12345',
246
$this->_urlGenerator->generateUrl(
247
array('view' => 'test.View', 'param' => 12345)));
250
function testGenerateUrlForController() {
251
$this->assertEquals($this->_signUrl('phpunit_test.php?g2_controller=' .
252
urlencode('test.Controller') . '&g2_param=12345'),
253
$this->_urlGenerator->generateUrl(
254
array('controller' => 'test.Controller', 'param' => 12345)));
257
function testGenerateUrlEmbeddedDownloadItemCookiePathNotSet() {
261
* DownloadItem requests in embedded G2 should have the GALLERYSID in the URL if the cookie
262
* path is not defined, independent of cookieless browsing
264
GalleryDataCache::put('G2_EMBED', 1, true);
265
$_SERVER['REQUEST_URI'] = '/cms/otherpage/?foo=bar';
267
$this->_prepareGenerateUrl('', '/cms/phpunit_test.php?module=gallery2', '/gallery2/');
269
$this->failWithStatus($ret);
271
$session =& $gallery->getSession();
273
/* Do the actual test */
274
$this->assertEquals('/gallery2/main.php?g2_view=' .
275
urlencode('core.DownloadItem') . '&g2_itemId=12345&' .
276
GalleryUtilities::prefixFormVariable($session->getKey()) . '=' .
277
urlencode($session->getId()),
278
$this->_urlGenerator->generateUrl(array('view' => 'core.DownloadItem',
280
'embedded G2 DownloadItem URL without fixed cookie path test failed');
283
* All embedded G2 requests that do not go to the G2 base directly shouldn't have the
284
* GALLERYSID in the URLs
286
$this->assertEquals('/cms/phpunit_test.php?module=gallery2&g2_itemId=12345',
287
$this->_urlGenerator->generateUrl(array('view' => 'core.ShowItem', 'itemId' => 12345)),
288
'embedded G2 ShowItem URL without fixed cookie path test failed');
291
function testGenerateUrlInitWithForceEmptyFilePart() {
294
/* Set g2Uri file to empty string with special override character '|' */
295
GalleryDataCache::put('G2_EMBED', 1, true);
296
$_SERVER['REQUEST_URI'] = '/cms/otherpage/?foo=bar';
297
list ($ret) = $this->_prepareGenerateUrl('', '/cms/phpunit_test.php?module=gallery2',
300
$this->failWithStatus($ret);
302
$session =& $gallery->getSession();
304
/* Do the actual test */
305
$this->assertEquals('/gallery2/?g2_view=' .
306
urlencode('core.DownloadItem') . '&g2_itemId=12345&' .
307
GalleryUtilities::prefixFormVariable($session->getKey()) . '=' .
308
urlencode($session->getId()),
309
$this->_urlGenerator->generateUrl(array('view' => 'core.DownloadItem',
311
'embedded G2 DownloadItem URL without fixed cookie path test failed');
314
function testGenerateUrlEmbeddedWithCookiePathSet() {
317
/* Now test the same with fixed cookie path */
318
GalleryDataCache::put('G2_EMBED', 1, true);
319
$_SERVER['REQUEST_URI'] = '/cms/otherpage?foo=bar';
320
list ($ret) = $this->_prepareGenerateUrl('/', '/cms/phpunit_test.php?module=gallery2',
321
'/gallery2/main.php');
323
$this->failWithStatus($ret);
326
/* Do the actual test */
327
$this->assertEquals('/gallery2/main.php?g2_view=' .
328
urlencode('core.DownloadItem') . '&g2_itemId=12345',
329
$this->_urlGenerator->generateUrl(array('view' => 'core.DownloadItem',
331
'embedded G2 DownloadItem URL with fixed cookie path test failed');
333
/* All other embedded G2 requests should still not have an appended SID */
334
$this->assertEquals('/cms/phpunit_test.php?module=gallery2&g2_itemId=12345',
335
$this->_urlGenerator->generateUrl(array('view' => 'core.ShowItem',
337
'embedded G2 ShowItem URL without fixed cookie path test failed');
340
function testGenerateUrlWithoutSession() {
342
$backup = $gallery->_session;
343
$gallery->_session = null;
345
$urlGenerator = new GalleryUrlGenerator();
346
$ret = $urlGenerator->init('phpunit_test.php');
348
return $this->failWithStatus($ret);
351
$this->assertEquals('phpunit_test.php?g2_view=foo',
352
$urlGenerator->generateUrl(array('view' => 'foo')));
353
$gallery->_session = $backup;
356
function testGenerateHref() {
358
$session =& $gallery->getSession();
360
/* href URLs default to no sessionid */
361
$this->assertEquals('test/test.css',
362
$this->_urlGenerator->generateUrl(array('href' => 'test/test.css')),
366
$this->assertEquals('http://sf.net/',
367
$this->_urlGenerator->generateUrl(array('href' => 'http://sf.net/')),
370
/* Absolute URL path */
371
$this->assertEquals('/cms/test/test.css',
372
$this->_urlGenerator->generateUrl(array('href' => '/cms/test/test.css')),
375
/* Simulate embedded */
376
$_SERVER['REQUEST_URI'] = '/phpunit_test.php?module=gallery2&foo=bar';
377
$urlGenerator = new GalleryUrlGenerator();
378
$ret = $urlGenerator->init('/phpunit_test.php?module=gallery2', '/gallery2/');
380
return $this->failWithStatus($ret);
383
$this->assertEquals('gallery2/test/test.css',
384
$urlGenerator->generateUrl(array('href' => 'test/test.css')),
385
'relative embedded');
387
/* Embedded, trailing slash omitted */
388
$_SERVER['REQUEST_URI'] = '/cms/phpunit_test.php?module=gallery2&foo=bar';
389
$urlGenerator = new GalleryUrlGenerator();
390
$ret = $urlGenerator->init('/cms/phpunit_test.php?module=gallery2', '/gallery2');
392
return $this->failWithStatus($ret);
395
$this->assertEquals('/test/test.css',
396
$urlGenerator->generateUrl(array('href' => 'test/test.css')),
397
'relative embedded, no trailing slash');
400
function testGenerateUrlNoHtmlEntities() {
401
$values[] = GalleryUtilities::prefixFormVariable('a') . '=' . urlencode('123');
402
$values[] = GalleryUtilities::prefixFormVariable('b') . '=' . urlencode('ab&c');
405
'phpunit_test.php?' . implode('&', $values),
406
$this->_urlGenerator->generateUrl(array('a' => 123, 'b' => 'ab&c'),
407
array('htmlEntities' => false)), 'url');
410
'test/blah.php?' . implode('&', $values),
411
$this->_urlGenerator->generateUrl(array('href' => 'test/blah.php',
412
'a' => 123, 'b' => 'ab&c'),
413
array('htmlEntities' => false)), 'href');
416
function testGenerateUrlNoUrlEncode() {
417
$values[] = GalleryUtilities::prefixFormVariable('a') . '=' . 'The Quick!Brown#Fox';
418
$values[] = GalleryUtilities::prefixFormVariable('b') . '=' . 'Jumps Over%The/Lazy_Dog';
421
'phpunit_test.php?' . implode('&', $values),
422
$this->_urlGenerator->generateUrl(array('a' => 'The Quick!Brown#Fox',
423
'b' => 'Jumps Over%The/Lazy_Dog'),
424
array('urlEncode' => false)), 'url');
427
'test/blah.php?' . implode('&', $values),
428
$this->_urlGenerator->generateUrl(array('href' => 'test/blah.php',
429
'a' => 'The Quick!Brown#Fox',
430
'b' => 'Jumps Over%The/Lazy_Dog'),
431
array('urlEncode' => false)), 'href');
434
function testGenerateReturnUrl() {
435
$_SERVER['REQUEST_URI'] = '/gallery2/phpunit_test.php?' .
436
GalleryUtilities::prefixFormVariable('view') . '=foo&' .
437
GalleryUtilities::prefixFormVariable('a') . '=123';
438
$_GET[GalleryUtilities::prefixFormVariable('view')] = 'foo';
439
$_GET[GalleryUtilities::prefixFormVariable('a')] = '123';
442
$params['view'] = 'bar';
443
$params['return'] = 1;
444
$actual = $this->_urlGenerator->generateUrl($params, array('forceSessionId' => false));
447
* The return URL needs to be server relative because we don't know at this point in
448
* wich context it'll be used later on.
451
GalleryUrlGenerator::appendParamsToUrl('/gallery2/phpunit_test.php',
452
array('view' => 'foo', 'a' => '123'));
454
* Note: encoded 'return' url should separate request variables with '%26'
455
* and not '%26amp%3D' because sending this back to G2 would yield &amp;
457
$params['return'] = str_replace('&', '&', $params['return']);
458
foreach ($params as $key => $value) {
459
$values[] = GalleryUtilities::prefixFormVariable(urlencode($key))
460
. '=' . urlencode($value);
462
$expected = 'phpunit_test.php?' . implode('&', $values);
463
$this->assertEquals($expected, $actual);
466
function testGenerateUrlWithEmbeddedSessionId() {
470
$params['b'] = 'bBbB';
471
$params['c'] = serialize(array(1, 2, 3));
472
$actual = $this->_urlGenerator->generateUrl($params, array('forceSessionId' => true));
474
foreach ($params as $key => $value) {
475
$values[] = GalleryUtilities::prefixFormVariable($key) . '=' . urlencode($value);
478
/* No matter what, expect the session id */
479
$session =& $gallery->getSession();
480
$values[] = GalleryUtilities::prefixFormVariable($session->getKey()) .
481
'=' . urlencode($session->getId());
482
$expected = 'phpunit_test.php?' . join('&', $values);
483
$this->assertEquals($expected, $actual);
486
function testGenerateUrlWithoutEmbeddedSessionId() {
488
$params['b'] = 'bBbB';
489
$params['c'] = serialize(array(1, 2, 3));
490
$actual = $this->_urlGenerator->generateUrl($params, array('forceSessionId' => false));
492
foreach ($params as $key => $value) {
493
$values[] = GalleryUtilities::prefixFormVariable($key) . '=' . urlencode($value);
496
/* No matter what, expect no session id */
497
$expected = 'phpunit_test.php?' . join('&', $values);
498
$this->assertEquals($expected, $actual);
501
function testGenerateUrlInMultisite() {
503
/* Simulate multisite (url for codebase) */
504
$gallery->setConfig('galleryBaseUrl', 'test://codebase/somepath/');
506
/* Views should go to the multisite */
507
$this->assertEquals('phpunit_test.php?g2_view=' . urlencode('test.View') .
508
'&g2_param=12345',
509
$this->_urlGenerator->generateUrl(
510
array('view' => 'test.View', 'param' => 12345)));
512
$this->assertEquals('phpunit_test.php?g2_view=' . urlencode('core.DownloadItem') .
514
$this->_urlGenerator->generateUrl(
515
array('view' => 'core.DownloadItem', 'itemId' => 99)));
517
/* Controllers too */
518
$this->assertEquals($this->_signUrl('phpunit_test.php?g2_controller=' .
519
urlencode('test.Controller') . '&g2_param=12345'),
520
$this->_urlGenerator->generateUrl(
521
array('controller' => 'test.Controller', 'param' => 12345)));
523
/* Hrefs should go to the multisite codebase, unless forceDirect given */
524
$this->assertEquals('test://codebase/somepath/theme/test_3745/images/foo.jpg',
525
$this->_urlGenerator->generateUrl(
526
array('href' => 'theme/test_3745/images/foo.jpg')));
527
$this->assertEquals('site/image.jpg',
528
$this->_urlGenerator->generateUrl(
529
array('href' => 'site/image.jpg'), array('forceDirect' => true)));
531
/* URL with baseUrl shouldn't be changed */
532
$this->assertEquals('fix_base_url/foo.php?g2_foo=bar',
533
$this->_urlGenerator->generateUrl(
534
array('foo' => 'bar'), array('baseUrl' => 'fix_base_url/foo.php')));
537
function testGenerateUrlEmbeddedMultisite() {
539
/* Simulate multisite (url for codebase) */
540
$gallery->setConfig('galleryBaseUrl', 'test://codebase/somepath/');
541
/* Simulate embedded */
542
GalleryDataCache::put('G2_EMBED', 1, true);
543
$_SERVER['REQUEST_URI'] = '/cms/otherpage?foo=bar';
544
list ($ret) = $this->_prepareGenerateUrl('/', '/cms/phpunit_test.php?module=gallery2',
545
'/gallery2/main.php');
547
$this->failWithStatus($ret);
550
/* Views should go to the embedded multisite */
551
$this->assertEquals('/cms/phpunit_test.php?module=gallery2&g2_view=' .
552
urlencode('test.View') . '&g2_param=12345',
553
$this->_urlGenerator->generateUrl(
554
array('view' => 'test.View', 'param' => 12345)));
556
/* Download view should go to direct multisite */
557
$this->assertEquals('/gallery2/main.php?g2_view=' . urlencode('core.DownloadItem') .
559
$this->_urlGenerator->generateUrl(
560
array('view' => 'core.DownloadItem', 'itemId' => 99)));
562
/* Controllers should go to the embedded multisite */
563
$this->assertEquals($this->_signUrl('/cms/phpunit_test.php?module=gallery2&' .
564
'g2_controller=' . urlencode('test.Controller') .
565
'&g2_param=12345'),
566
$this->_urlGenerator->generateUrl(
567
array('controller' => 'test.Controller', 'param' => 12345)));
569
/* Hrefs should go to the multisite codebase */
570
$this->assertEquals('test://codebase/somepath/theme/test_3745/images/foo.jpg',
571
$this->_urlGenerator->generateUrl(
572
array('href' => 'theme/test_3745/images/foo.jpg')));
574
/* URL with baseUrl shouldn't be changed */
575
$this->assertEquals('fix_base_url/foo.php?g2_foo=bar',
576
$this->_urlGenerator->generateUrl(
577
array('foo' => 'bar'), array('baseUrl' => 'fix_base_url/foo.php')));
580
function testGetCurrentRequestUri() {
581
$expected = '/gallery2/phpunit_test.php?foo=bar';
582
$this->assertEquals($expected, $this->_urlGenerator->getCurrentRequestUri());
584
/* IIS.. REQUEST_URI is just empty; but has SCRIPT_NAME.. */
585
$_SERVER['REQUEST_URI'] = '';
586
$_SERVER['SCRIPT_NAME'] = '/gallery2/phpunit_test.php';
587
$_SERVER['QUERY_STRING'] = 'foo=bar';
588
$this->assertEquals($expected, $this->_urlGenerator->getCurrentRequestUri(), 'iis');
590
/* Sometimes IIS has PATH_INFO value the same as SCRIPT_NAME.. */
591
$_SERVER['PATH_INFO'] = $_SERVER['SCRIPT_NAME'];
592
$this->assertEquals($expected, $this->_urlGenerator->getCurrentRequestUri(),
597
* Apache is not very clear about whether REQUEST_URI is specified to be an URI without the
598
* schema and host part or not. There's at least 1 Apache 2 setup where REQUEST_URI was a
600
* Since the requestUri in Gallery is expected to be an URI w/o the host part, we must
601
* normalize whatever Apache returns.
603
function testGetCurrentRequestUriForAbsoluteUrl() {
604
$expected = '/gallery2/phpunit_test.php?foo=bar';
605
$_SERVER['REQUEST_URI'] = 'http://example.com' . $expected;
606
$this->assertEquals($expected, $this->_urlGenerator->getCurrentRequestUri());
608
/* And a case with a fragment part. */
609
$expected = '/gallery2/phpunit_test.php?foo=bar#anchor';
610
$_SERVER['REQUEST_URI'] = 'http://example.com' . $expected;
611
$this->assertEquals($expected, $this->_urlGenerator->getCurrentRequestUri());
614
function testGetCurrentUrl() {
615
$expected = 'http://example.com/gallery2/phpunit_test.php?foo=bar';
616
$this->assertEquals($expected, $this->_urlGenerator->getCurrentUrl());
618
/* IIS.. no REQUEST_URI; has SCRIPT_NAME.. */
619
unset($_SERVER['REQUEST_URI']);
620
$_SERVER['SCRIPT_NAME'] = '/gallery2/phpunit_test.php';
621
$_SERVER['QUERY_STRING'] = 'foo=bar';
622
unset($this->_urlGenerator->_currentUrl);
623
$this->assertEquals($expected, $this->_urlGenerator->getCurrentUrl(), 'iis');
625
/* Sometimes IIS has PATH_INFO value the same as SCRIPT_NAME.. */
626
$_SERVER['PATH_INFO'] = $_SERVER['SCRIPT_NAME'];
627
unset($this->_urlGenerator->_currentUrl);
628
$this->assertEquals($expected, $this->_urlGenerator->getCurrentUrl(), 'iis path_info');
631
function testGetCurrentUrlDir() {
632
$this->assertEquals('http://example.com/gallery2/',
633
$this->_urlGenerator->getCurrentUrlDir(), 'basic');
635
/* Simulate embedded.. */
636
$_SERVER['REQUEST_URI'] = '/phpunit_test.php?module=gallery2&foo=bar';
637
$urlGenerator = new GalleryUrlGenerator();
638
$ret = $urlGenerator->init('/phpunit_test.php?module=gallery2','/gallery2/');
640
return $this->failWithStatus($ret);
642
$this->assertEquals('http://example.com/', $urlGenerator->getCurrentUrlDir(), 'embedded');
643
$this->assertEquals('http://example.com/gallery2/', $urlGenerator->getCurrentUrlDir(true),
644
'embedded forceDirect');
646
$_SERVER['REQUEST_URI'] = '/cms/phpunit_test.php?module=gallery2&foo=bar';
647
$urlGenerator = new GalleryUrlGenerator();
648
$ret = $urlGenerator->init('/cms/phpunit_test.php?module=gallery2', '/gallery2/');
650
return $this->failWithStatus($ret);
652
$this->assertEquals('http://example.com/cms/', $urlGenerator->getCurrentUrlDir(),
653
'embedded, different path');
654
$this->assertEquals('http://example.com/gallery2/', $urlGenerator->getCurrentUrlDir(true),
655
'embedded, different path, forceDirect');
658
function testGetCurrentUrlDirBaseFileNotFound() {
659
$_SERVER['REQUEST_URI'] = '/somedir/?filter=foo';
660
$urlGenerator = new GalleryUrlGenerator();
661
$ret = $urlGenerator->init('index.php');
663
return $this->failWithStatus($ret);
665
$this->assertEquals('http://example.com/somedir/', $urlGenerator->getCurrentUrlDir());
668
function testGetHostName() {
669
$_SERVER['HTTP_HOST'] = 'http_host';
670
if ($ret = $this->_initNewUrlGenerator()) {
671
return $this->failWithStatus($ret);
673
$this->assertEquals('http_host', $this->_urlGenerator->getHostName());
675
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'http_x_forwarded_host';
676
if ($ret = $this->_initNewUrlGenerator()) {
677
return $this->failWithStatus($ret);
679
$this->assertEquals('http_x_forwarded_host', $this->_urlGenerator->getHostName());
682
function testGetHostNameOverride() {
683
$_SERVER['HTTP_HOST'] = 'http_host';
684
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'http_host';
686
if ($ret = $this->_initNewUrlGenerator('override/')) {
687
return $this->failWithStatus($ret);
689
$this->assertEquals('override', $this->_urlGenerator->getHostName());
690
$this->assertEquals('override', $this->_urlGenerator->getHostName(false));
691
$this->assertEquals('override', $this->_urlGenerator->getHostName(true));
694
function testGetHostNameEmbeddedOverride() {
695
$_SERVER['HTTP_HOST'] = 'http_host';
696
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'http_host';
698
if ($ret = $this->_initNewUrlGenerator('embedded_override/', 'http://direct_override/')) {
699
return $this->failWithStatus($ret);
701
$this->assertEquals('embedded_override', $this->_urlGenerator->getHostName());
702
$this->assertEquals('embedded_override', $this->_urlGenerator->getHostName(false));
703
$this->assertEquals('direct_override', $this->_urlGenerator->getHostName(true));
709
function testMakeUrl1() {
710
$this->assertEquals('http://example.com/test/path.php',
711
$this->_urlGenerator->makeUrl('/test/path.php'), 'with slash');
713
$this->assertEquals('http://example.com/test/test.jpg',
714
$this->_urlGenerator->makeUrl('test/test.jpg'), 'no slash');
716
$this->assertEquals('http://example.com/',
717
$this->_urlGenerator->makeUrl(''), 'empty');
721
* Test non-standard ports go in both HTTP_HOST and SERVER_PORT (also tests ::init)
723
function testMakeUrl2() {
724
$_SERVER['HTTP_HOST'] = 'example.com:8080';
725
$_SERVER['SERVER_PORT'] = 8080;
726
if ($ret = $this->_initNewUrlGenerator()) {
727
return $this->failWithStatus($ret);
729
$this->assertEquals('http://example.com:8080/test.php?fun=yes',
730
$this->_urlGenerator->makeUrl('/test.php?fun=yes'));
734
* Test browsing to https://example.com
736
function testMakeUrl3() {
737
$_SERVER['HTTP_HOST'] = 'example.com';
738
$_SERVER['SERVER_PORT'] = 443;
739
$_SERVER['HTTPS'] = 'on';
740
if ($ret = $this->_initNewUrlGenerator()) {
741
return $this->failWithStatus($ret);
743
$this->assertEquals('https://example.com/test/go.php?a=one&b=two',
744
$this->_urlGenerator->makeUrl('test/go.php?a=one&b=two'));
748
* Test non-standard port only in SERVER_PORT. This is the case where the
749
* browser went to http://example.com and got internally redirected to
750
* something like http://internal.server:82/. We want to serve up a new
751
* url that the browser can handle.
753
function testMakeUrl4() {
754
$_SERVER['HTTP_HOST'] = 'example.com';
755
$_SERVER['SERVER_PORT'] = 82;
756
if ($ret = $this->_initNewUrlGenerator()) {
757
return $this->failWithStatus($ret);
759
$this->assertEquals('http://example.com/test.php?fun=yes',
760
$this->_urlGenerator->makeUrl('/test.php?fun=yes'));
763
/* Test host and protocol override */
764
function testMakeUrl5() {
765
$this->_urlGenerator->_currentBaseHost[0] = 'http://photos.example.com';
766
$this->assertEquals('http://photos.example.com/test.php?fun=yes',
767
$this->_urlGenerator->makeUrl('/test.php?fun=yes'), 'override');
768
$this->_urlGenerator->_currentBaseHost[0] = 'foo';
769
$this->_urlGenerator->_currentBaseHost[1] = 'http://photos.example.com';
770
$this->assertEquals('http://photos.example.com/test.php?fun=yes',
771
$this->_urlGenerator->makeUrl('/test.php?fun=yes', true),
772
'override with forceG2Base');
773
$this->_urlGenerator->_currentBaseHost[0] = 'https://photos.example.com';
774
$this->assertEquals('https://photos.example.com/test.php?fun=yes',
775
$this->_urlGenerator->makeUrl('/test.php?fun=yes'),
776
'host and protocol override');
777
$this->assertEquals('http://photos.example.com/test.php?fun=yes',
778
$this->_urlGenerator->makeUrl('/test.php?fun=yes', true),
779
'host and protocol override with forceG2Base');
782
function testMakeAbsoluteUrlForRelativeUrl() {
783
$this->_urlGenerator->_currentUrlBaseDir[1] = 'http://photos.example.com/app/';
784
$this->assertEquals('http://example.com/gallery2/test/test.jpg',
785
$this->_urlGenerator->makeAbsoluteUrl('test/test.jpg'), 'relative URL');
786
$this->assertEquals('http://photos.example.com/app/test/test.jpg',
787
$this->_urlGenerator->makeAbsoluteUrl('test/test.jpg', true),
791
function testMakeAbsoluteUrlForServerRelativeUrl() {
792
$this->_urlGenerator->_currentBaseHost[1] = 'http://photos.example.com';
793
$this->assertEquals('http://example.com/test/test.jpg',
794
$this->_urlGenerator->makeAbsoluteUrl('/test/test.jpg'),
796
$this->assertEquals('http://photos.example.com/test/test.jpg',
797
$this->_urlGenerator->makeAbsoluteUrl('/test/test.jpg', true),
799
$this->assertEquals('http://example.com/test/test.jpg',
800
$this->_urlGenerator->makeAbsoluteUrl(' /test/test.jpg'),
801
'relative URL with leading whitespace characters');
804
function testMakeAbsoluteUrlForAbsoluteUrl() {
805
$this->assertEquals('http://example.com/test.jpg',
806
$this->_urlGenerator->makeAbsoluteUrl('http://example.com/test.jpg'),
808
$this->assertEquals('http://other.example.com/test.jpg',
809
$this->_urlGenerator->makeAbsoluteUrl('http://other.example.com/test.jpg'),
810
'absolute URL of non-Gallery host');
811
$this->assertEquals('webdav16+10://other.protocol.com/test.jpg',
812
$this->_urlGenerator->makeAbsoluteUrl('webdav16+10://other.protocol.com/test.jpg'),
813
'absolute URL with a different schema');
814
$this->assertEquals('http://example.com/test.jpg',
815
$this->_urlGenerator->makeAbsoluteUrl('http://example.com/test.jpg', true),
816
'absolute URL, force direct');
820
* Test non-standard ports go in both HTTP_HOST and SERVER_PORT
822
function testInit() {
823
$_SERVER['HTTP_HOST'] = 'example.com:8080';
824
$_SERVER['SERVER_PORT'] = 8080;
825
if ($ret = $this->_initNewUrlGenerator()) {
826
return $this->failWithStatus($ret);
828
$this->assertEquals('http', $this->_urlGenerator->_protocol[0], 'protocol');
829
$this->assertEquals('http', $this->_urlGenerator->_protocol[1], 'forceDirect protocol');
830
$this->assertEquals('example.com:8080', $this->_urlGenerator->_host[0], 'host');
831
$this->assertEquals('example.com:8080', $this->_urlGenerator->_host[1], 'forceDirect host');
832
$this->assertEquals('http://example.com:8080', $this->_urlGenerator->_currentBaseHost[0],
834
$this->assertEquals('http://example.com:8080', $this->_urlGenerator->_currentBaseHost[1],
835
'forceDirect currentBaseHost');
838
function testInitDefault() {
839
unset($_SERVER['HTTPS']);
840
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'http_x_forwarded_host';
841
$uG = new GalleryUrlGenerator();
842
if ($ret = $uG->init()) {
843
return $this->failWithStatus($ret);
846
foreach (array(0, 1) as $i) {
847
$this->assertEquals(GALLERY_MAIN_PHP, $uG->_file[$i], "file[$i]");
848
$this->assert(empty($uG->_path[$i]), "path[$i]");
849
$this->assertEquals('http', $uG->_protocol[$i], "protocol[$i]");
850
$this->assertEquals('http_x_forwarded_host', $uG->_host[$i], "host[$i]");
851
$this->assertEquals('http://http_x_forwarded_host', $uG->_currentBaseHost[$i],
852
"currentBaseHost[$i]");
854
$this->assertEquals(null, $uG->_embedSessionString, 'embedSessionString');
857
function testInitOverride() {
858
unset($_SERVER['HTTPS']);
859
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'http_x_forwarded_host';
860
$uG = new GalleryUrlGenerator();
861
if ($ret = $uG->init('https://override:8080/new_path/index.php?foo=bar')) {
862
return $this->failWithStatus($ret);
865
foreach (array(0, 1) as $i) {
866
$this->assertEquals('index.php?foo=bar', $uG->_file[$i], "file[$i]");
867
$this->assertEquals('/new_path/', $uG->_path[$i], "path[$i]");
868
$this->assertEquals('https', $uG->_protocol[$i], "protocol[$i]");
869
$this->assertEquals('override:8080', $uG->_host[$i], "host[$i]");
870
$this->assertEquals('https://override:8080', $uG->_currentBaseHost[$i],
871
"currentBaseHost[$i]");
875
function testInitEmbedded() {
876
$_SERVER['HTTPS'] = 'on';
877
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'http_x_forwarded_host';
878
$uG = new GalleryUrlGenerator();
879
if ($ret = $uG->init('/cms/index.php?foo=bar', 'http://direct/gallery2/', 'session=123')) {
880
return $this->failWithStatus($ret);
883
$this->assertEquals('index.php?foo=bar', $uG->_file[0], 'file[0]');
884
$this->assertEquals(GALLERY_MAIN_PHP, $uG->_file[1], 'file[1]');
885
$this->assertEquals('/cms/', $uG->_path[0], 'path[0]');
886
$this->assertEquals('/gallery2/', $uG->_path[1], 'path[1]');
887
$this->assertEquals('https', $uG->_protocol[0], 'protocol[0]');
888
$this->assertEquals('http', $uG->_protocol[1], 'protocol[1]');
889
$this->assertEquals('http_x_forwarded_host', $uG->_host[0], 'host[0]');
890
$this->assertEquals('direct', $uG->_host[1], 'host[1]');
891
$this->assertEquals('https://http_x_forwarded_host', $uG->_currentBaseHost[0],
892
'currentBaseHost[0]');
893
$this->assertEquals('http://direct', $uG->_currentBaseHost[1],
894
'currentBaseHost[1]');
897
function testBaseFileWithQMark() {
899
$urlGenerator = new GalleryUrlGenerator();
900
$ret = $urlGenerator->init('phpunit_test.php?test=on');
902
return $this->failWithStatus($ret);
904
$_SERVER['REQUEST_URI'] = '/gallery2/phpunit_test.php?test=on&foo=bar';
907
$params['b'] = 'bBbB';
908
$params['c'] = serialize(array(1, 2, 3));
909
$actual = $urlGenerator->generateUrl($params);
911
foreach ($params as $key => $value) {
912
$values[] = GalleryUtilities::prefixFormVariable($key) . '=' . urlencode($value);
915
/* If we're not using cookies, expect there to be an additional value */
916
$session =& $gallery->getSession();
917
if (!$session->isUsingCookies()) {
918
$values[] = GalleryUtilities::prefixFormVariable($session->getKey()) .
919
'=' . urlencode($session->getId());
921
$expected = 'phpunit_test.php?test=on&' .
922
implode('&', $values);
924
$this->assertEquals($expected, $actual);
927
function testGetNavigationReturnUrl() {
928
$_GET['g2_foo'] = 'bar';
929
$_GET['g2_return'] = 'http://blabla';
930
$_GET['g2_returnName'] = 'name';
931
$_GET['g2_navId'] = 'navId';
932
$_GET['g2_fromNavId'] = 'fromNavId';
934
* We're forwarding the HTTP authorization header via mod_rewrite to the URL params and
935
* need to remove it manually for return URLs again. But we keep it in other places (e.g.
936
* cacheable URLs) since it might influence Gallery's behavior.
938
$_GET['g2_authorization'] = 'authorization';
939
$expected = '/gallery2/phpunit_test.php?g2_foo=bar';
941
/* Normal behaviour (php+apache) */
942
$this->assertEquals($expected, $this->_urlGenerator->getNavigationReturnUrl());
944
/* IIS: no REQUEST_URI or PATH_INFO, just SCRIPT_NAME */
945
unset($_SERVER['REQUEST_URI']);
946
$_SERVER['SCRIPT_NAME'] = '/gallery2/phpunit_test.php';
947
unset($this->_urlGenerator->_currentUrl);
948
$this->assertEquals($expected, $this->_urlGenerator->getNavigationReturnUrl(), 'iis');
950
/* Sometimes IIS has PATH_INFO value the same as SCRIPT_NAME.. */
951
$_SERVER['PATH_INFO'] = $_SERVER['SCRIPT_NAME'];
952
unset($this->_urlGenerator->_currentUrl);
953
$this->assertEquals($expected, $this->_urlGenerator->getNavigationReturnUrl(),
957
function testGetNavigationReturnUrlNoCookies() {
960
/* Session without cookies */
961
$session =& $gallery->getSession();
962
$savedIsUsingCookies = $session->_isUsingCookies;
963
$session->_isUsingCookies = false;
966
GalleryUtilities::prefixFormVariable($session->getKey()) . '=' . $session->getId();
968
/* No other params in URL */
969
$_SERVER['REQUEST_URI'] = '/gallery2/phpunit_test.php';
971
$expected = '/gallery2/phpunit_test.php?' . $sessionParam;
972
$this->assertEquals($expected, $this->_urlGenerator->getNavigationReturnUrl(),
975
/* With other params in URL */
976
$_SERVER['REQUEST_URI'] = '/gallery2/phpunit_test.php?foo=bar';
977
$_GET['g2_foo'] = 'bar';
978
unset($this->_urlGenerator->_currentUrl);
979
$expected = '/gallery2/phpunit_test.php?g2_foo=bar&' . $sessionParam;
980
$this->assertEquals($expected, $this->_urlGenerator->getNavigationReturnUrl(),
981
'with other params');
983
/* With session already in URL */
984
$_GET[GalleryUtilities::prefixFormVariable($session->getKey())] = $session->getId();
985
unset($this->_urlGenerator->_currentUrl);
986
$expected = '/gallery2/phpunit_test.php?g2_foo=bar&' . $sessionParam;
987
$this->assertEquals($expected, $this->_urlGenerator->getNavigationReturnUrl(),
988
'with session already in URL');
990
$session->_isUsingCookies = $savedIsUsingCookies;
993
function testGetNavigationReturnUrlArrayParam() {
994
$_GET['g2_foo'] = array('test' => 'bar');
995
$_GET['g2_form'] = array('one' => array('two' => array('three' => 'four')));
996
$expected = '/gallery2/phpunit_test.php?g2_foo' . urlencode('[test]') . '=bar&'
997
. urlencode('g2_form[one][two][three]') . '=four';
998
$this->assertEquals($expected, $this->_urlGenerator->getNavigationReturnUrl());
1002
* With the g2_return parameter users can add any "back to " link or direct redirect to any
1003
* URL. We try to detect those phishing attacks by comparing the returnUrl with our current
1004
* $this->getCurrentUrlDir(). If returnUrl doesn't start with getCurrentUrlDir(), it's not a
1005
* redirect into the same G2 installation.
1006
* initNavigation is called after GalleryInitFirstPass and init storage, thus we can use
1007
* getCurrentUrlDir(), else it might have been a problem (RewriteUrlGenerator)
1009
function testDetectPhishingAttack() {
1010
/* Not the same domain name or not the same path are not allowed */
1012
'http://EVIL.com/gallery2/main.php?g2_view=core.UserAdmin&g2_subView=core.UserLogin',
1013
'https://EVIL.com/gallery2/main.php',
1014
$this->_urlGenerator->makeUrl('/EVIL/main.php?g2_subView=core.UserLogin'),
1015
'../EVIL/main.php?g2_view=core.UserAdmin',
1016
'/EVIL/../gallery2/main.php?g2_view=core.UserAdmin',
1017
'/gallery2/../EVIL/main.php?g2_view=core.UserAdmin',
1018
"..\\\\EVIL\\\\main.php",
1019
"/gallery/foo\\\\../main.php",
1020
' /EVIL/gallery2/main.php',
1021
' /../gallery2/EVIL/main.php',
1022
' ../gallery2/EVIL/main.php');
1023
foreach ($badUrls as $url) {
1024
$_GET['g2_return'] = $url;
1025
$ret = $this->_urlGenerator->initNavigation();
1026
$this->assert($ret->getErrorCode() & ERROR_PERMISSION_DENIED,
1027
"Phishing attack '$url' not detected for url");
1030
* Check host and path for absolute urls, absolute path for server relative URLs
1031
* and allow relative URLs that don't try to break out of the good path
1034
$this->_urlGenerator->generateUrl(
1035
array('view' => 'core.UserAdmin', 'subView' => 'core.UserLogin')),
1036
'/gallery2/main.php?g2_view=core.UserAdmin',
1038
'www.DONTCARE.com/gallery2/main.php',
1039
'\\gallery2\\main.php');
1040
foreach ($goodUrls as $url) {
1041
$_GET['g2_return'] = $url;
1042
$ret = $this->_urlGenerator->initNavigation();
1044
$this->assert(false, "Normal returnUrl '$url' not accepted");
1045
$this->failWithStatus($ret);
1050
function testDetectHeaderInjectionAttack() {
1052
'http://EVIL.com/gallery2/main.php?test%0d%0afoo',
1053
'main.php?foo%250Abar',
1054
'main.php?g2_subView=core.UserLogin&%0A',
1055
'main.php?foo' . chr(13). 'bar');
1056
foreach ($badUrls as $url) {
1057
$_GET['g2_return'] = $url;
1058
$ret = $this->_urlGenerator->initNavigation();
1059
$this->assert($ret->getErrorCode() & ERROR_PERMISSION_DENIED,
1060
"Header injection '$url' not detected for url");
1065
* Make sure getNavigationLinks() returns unchanged URLs
1066
* (part of our phishing attack protection)
1068
function testGetNavigationLinks() {
1069
list ($ret, $core) = GalleryCoreApi::loadPlugin('module', 'core');
1071
return $this->failWithStatus($ret);
1075
* In initNavigation we accept returnUrl = 'www.EVIL.com' because we have to interpret it
1076
* as relative URL, e.g. for http://example.com/www.EVIL.com/ (album called www.EVIL.com)
1077
* Here we must ensure that we don't add http:// in front the returned URL, since that
1078
* would change the relative to an absolute URL.
1080
$_GET['g2_return'] = 'www.DONTCARE.com';
1081
$_GET['g2_returnName'] = 'I want a pony';
1082
$ret = $this->_urlGenerator->initNavigation();
1084
$this->failWithStatus($ret);
1086
list ($ret, $links) = $this->_urlGenerator->getNavigationLinks();
1088
$this->failWithStatus($ret);
1090
$params = array('fromNavId' => $this->_urlGenerator->_navId);
1091
$expectedUrl = GalleryUrlGenerator::appendParamsToUrl('www.DONTCARE.com', $params);
1092
$this->assertEquals(array(array('url' => $expectedUrl, 'name' => $core->translate(
1093
array('text' => 'Back to %s', 'arg1' => 'I want a pony')))),
1094
$links, 'Navigation link was altered');
1097
/* Regression test to check that we handle embedUri = /foo/bar/ correctly (no file part) */
1098
function testInitNavigationHandlesEmbedUriWithoutFilePart() {
1099
$urlGenerator = new GalleryUrlGenerator();
1100
$ret = $urlGenerator->init('/foo/bar/');
1102
$this->failWithStatus($ret);
1105
GalleryUtilities::putRequestVariable('return', 'foo');
1106
/* Assert that there's no PHP warning during the execution of this function */
1107
$ret = $urlGenerator->initNavigation();
1112
$this->assertEquals(null, $ret);
1115
function testRelativeUrlOverrides() {
1117
$session =& $gallery->getSession();
1119
$gallery->setPlatform(new UrlGeneratorTestPlatform());
1120
$qs = $session->isUsingCookies() ? '' : '?' .
1121
GalleryUtilities::prefixFormVariable($session->getKey()) . '=' .
1122
urlencode($session->getId());
1124
/* Try with a file that has no local override */
1125
$actual = $this->_urlGenerator->generateUrl(array('href' => 'test/test1.css'));
1126
$this->assertEquals('test/test1.css' . $qs, $actual);
1128
/* Try with a file that has a local override */
1129
$actual = $this->_urlGenerator->generateUrl(array('href' => 'test/test2.css'));
1130
$this->assertEquals('test/local/test2.css' . $qs, $actual);
1132
/* We don't allow overrides with top level files (nor do we generate an error) */
1133
$actual = $this->_urlGenerator->generateUrl(array('href' => 'favicon.ico'));
1134
$this->assertEquals('favicon.ico' . $qs, $actual);
1137
function testCurrentUrlToken() {
1138
$_SERVER['REQUEST_URI'] = '/gallery2/phpunit_test.php?a=b';
1140
$url = $this->_urlGenerator->generateUrl(array('view' => 'foo', 'test' => '%CURRENT_URL%'));
1141
$this->assertEquals('phpunit_test.php?g2_view=foo&' .
1142
'g2_test=http%3A%2F%2Fexample.com%2Fgallery2%2Fphpunit_test.php%3Fa%3Db', $url);
1145
function testGetCookiePath() {
1146
/* First check if the configured value is taken if available */
1147
$ret = GalleryCoreApi::setPluginParameter('module', 'core', 'cookie.path', '/bad/');
1149
return $this->failWithStatus($ret);
1151
/* Check if the correct value was stored */
1152
list ($ret, $realValue) = GalleryCoreApi::getPluginParameter('module', 'core',
1155
return $this->failWithStatus($ret);
1157
$this->assertEquals('/bad/', $realValue, 'could not set plugin parameter cookie.path');
1158
/* Now do the actual check */
1159
$_SERVER['REQUEST_URI'] = '/cms/phpunit_test.php?a=b';
1160
$urlGenerator = new GalleryUrlGenerator();
1161
$ret = $urlGenerator->init('/cms/phpunit_test.php', '/gallery2/');
1163
return $this->failWithStatus($ret);
1165
list ($ret, $path) = $urlGenerator->getCookiePath();
1167
return $this->failWithStatus($ret);
1169
$this->assertEquals('/bad/', $path, 'test 0');
1170
list ($ret, $path) = $urlGenerator->getCookiePath(true);
1172
return $this->failWithStatus($ret);
1174
$this->assertEquals('/bad/', $path, 'test 0.1');
1177
* Now reset the cookie path configuration parameter such that the computed value is
1180
$ret = GalleryCoreApi::setPluginParameter('module', 'core', 'cookie.path', '');
1182
return $this->failWithStatus($ret);
1184
/* Check if the correct value was stored */
1185
list ($ret, $realValue) = GalleryCoreApi::getPluginParameter('module', 'core',
1188
return $this->failWithStatus($ret);
1190
$this->assertEquals('', $realValue, 'could not reset plugin parameter cookie.path');
1192
/* Check the computed cookie path */
1194
$tests[] = array('baseUri' => '/gallery2/phpunit_test.php?foo=bar', 'er' => '/gallery2/',
1195
'g2Uri' => '/gallery2/phpunit_test.php', 'force' => false);
1196
$tests[] = array('baseUri' => '/phpunit_test.php?foo=bar','g2Uri' => '/gallery2/foo.php',
1197
'er' => '/', 'force' => false);
1198
/* g2Uri is only relevant if forceG2Path is true */
1199
$tests[] = array('g2Uri' => '/gallery2/index.php?module=gallery2&foo=bar', 'er' => '/cms/',
1200
'baseUri' => '/cms/index.php?module=gallery2', 'force' => false);
1201
$tests[] = array('baseUri' => '/index.php?module=gallery2&foo=bar', 'er' => '/',
1202
'g2Uri' => '/gallery2/index.php?module=gallery2', 'force' => false);
1203
$tests[] = array('baseUri' => '/cms/index.php?module=gallery2&foo=bar', 'force' => false,
1204
'g2Uri' => '/modules/gallery2/index.php?module=gallery2', 'er' => '/cms/');
1205
$tests[] = array('baseUri' => '/apps/cms/index.php?module=gallery2&foo=bar',
1206
'g2Uri' => '/apps/galery2/index.php?module=gallery2', 'force' => false,
1207
'er' => '/apps/cms/');
1208
$tests[] = array('baseUri' => '/cms/index.php?module=gallery2&foo=bar',
1209
'g2Uri' => '/gallery2/index.php?module=gallery2', 'force' => true,
1210
'er' => '/gallery2/');
1211
$tests[] = array('baseUri' => '/cms/index.php?module=gallery2&foo=bar', 'force' => true,
1212
'g2Uri' => '/cms/modules/gallery2/index.php?module=gallery2',
1213
'er' => '/cms/modules/gallery2/');
1214
$tests[] = array('baseUri' => 'phpunit_test.php', 'g2Uri' => null, 'force' => true,
1215
'er' => '/foobar/');
1216
$tests[] = array('baseUri' => 'phpunit_test.php', 'g2Uri' => null, 'force' => false,
1217
'er' => '/foobar/');
1220
foreach ($tests as $testCase) {
1221
$_SERVER['REQUEST_URI'] = !isset($testCase['g2Uri']) ? '/foobar/' : '';
1222
$_SERVER['REQUEST_URI'] .= $testCase['baseUri'];
1223
$urlGenerator = new GalleryUrlGenerator();
1224
$ret = $urlGenerator->init($testCase['baseUri'], $testCase['g2Uri']);
1226
return $this->failWithStatus($ret);
1228
list ($ret, $path) = $urlGenerator->getCookiePath($testCase['force']);
1230
return $this->failWithStatus($ret);
1232
$this->assertEquals($testCase['er'], $path, "test $i");
1237
function testEmbedForceSessionId() {
1240
if (GalleryDataCache::containsKey($key)) {
1241
$savedEmbed = GalleryDataCache::get($key);
1244
/* Permute all involved variables, exhaustive test */
1245
foreach (array(true, false) as $downloadItemRequest) {
1246
$params = array('view' => 'core.ShowItem');
1247
if ($downloadItemRequest) {
1248
$params = array('view' => 'core.DownloadItem');
1250
foreach (array(true, false) as $isEmbedded) {
1251
GalleryDataCache::put($key, $isEmbedded, true);
1252
$this->assertEquals($isEmbedded, GalleryDataCache::get($key),
1253
'Could not set isEmbedded');
1254
foreach (array(true, false) as $cookiePathConfigured) {
1255
$this->_urlGenerator->_isCookiePathConfigured = $cookiePathConfigured;
1256
/* Execute the test */
1257
$result = $this->_urlGenerator->embedForceSessionId($params);
1258
/* Some debug information */
1259
$debugInfo = 'isEmbedded: ' . intval($isEmbedded) . ', cookiePathConfigured: ' .
1260
intval($cookiePathConfigured) . ', downloadItemRequest: ' .
1261
intval($downloadItemRequest);
1262
/* Check the result */
1263
if ($isEmbedded && !$cookiePathConfigured && $downloadItemRequest) {
1264
$this->assertEquals(true, $result, 'wrong result for test case: ' .
1267
$this->assertEquals(false, $result, 'wrong result for test case: ' .
1276
GalleryDataCache::put($key, $savedEmbed, true);
1278
GalleryDataCache::remove($key);
1279
$this->assert(!GalleryDataCache::containsKey($key), 'Could not remove a GDC var');
1283
function testGenerateFullUrlOn() {
1284
$this->assertEquals('http://example.com/gallery2/phpunit_test.php?g2_a=b',
1285
$this->_urlGenerator->generateUrl(array('a' => 'b'), array('forceFullUrl' => true)));
1288
function testGenerateFullUrlOnForRelative() {
1289
$this->assertEquals('http://example.com/gallery2/favicon.ico',
1290
$this->_urlGenerator->generateUrl(array('href' => 'favicon.ico'),
1291
array('forceFullUrl' => true)));
1294
function testGenerateFullUrlOff() {
1295
$this->assertEquals('phpunit_test.php?g2_a=b',
1296
$this->_urlGenerator->generateUrl(array('a' => 'b'), array('forceFullUrl' => false)));
1299
function testGenerateServerRelativeUrlOn() {
1300
$this->assertEquals('/gallery2/phpunit_test.php?g2_a=b',
1301
$this->_urlGenerator->generateUrl(
1302
array('a' => 'b'), array('forceServerRelativeUrl' => true)));
1305
function testGenerateServerRelativeUrlOnForRelative() {
1306
$this->assertEquals('/gallery2/favicon.ico',
1307
$this->_urlGenerator->generateUrl(
1308
array('href' => 'favicon.ico'),
1309
array('forceServerRelativeUrl' => true)));
1312
function testGenerateServerRelativeUrlOff() {
1313
$this->assertEquals('phpunit_test.php?g2_a=b',
1314
$this->_urlGenerator->generateUrl(
1315
array('a' => 'b'), array('forceServerRelativeUrl' => false)));
1318
/* ForceFullUrl has precedence over ForceServerRelativeUrl */
1319
function testGenerateServerRelativeUrlOnFullUrlOn() {
1320
$this->assertEquals('http://example.com/gallery2/phpunit_test.php?g2_a=b',
1321
$this->_urlGenerator->generateUrl(
1322
array('a' => 'b'), array('forceServerRelativeUrl' => true,
1323
'forceFullUrl' => true)));
1326
function testMakeRelativeUrl() {
1327
$this->assertEquals('phpunit_test.php?g2_a=b', $this->_urlGenerator->makeRelativeUrl(
1328
'http://example.com/gallery2/phpunit_test.php?g2_a=b'));
1331
function testMakeRelativeUrlForceServerRelative() {
1332
$this->assertEquals('/gallery2/phpunit_test.php?g2_a=b',
1333
$this->_urlGenerator->makeRelativeUrl(
1334
'http://example.com/gallery2/phpunit_test.php?g2_a=b', true));
1337
function testMakeRelativeUrlDontForceServerRelative() {
1338
$this->assertEquals('phpunit_test.php?g2_a=b',
1339
$this->_urlGenerator->makeRelativeUrl(
1340
'http://example.com/gallery2/phpunit_test.php?g2_a=b', false));
1343
function testMakeServerRelativeUrl() {
1344
$this->_urlGenerator->_file[0] = '';
1345
$this->assertEquals('/gallery2/v/AlbumName', $this->_urlGenerator->makeRelativeUrl(
1346
'http://example.com/gallery2/v/AlbumName'));
1349
/* Multisite / embedded G2 case, some URLs go to another (sub)domain */
1350
function testMakeRelativeUrlDifferentSubdomains() {
1351
$this->_urlGenerator->_host[0] = 'www.example.com';
1352
$this->assertEquals('http://photos.example.com/gallery2/phpunit_test.php',
1353
$this->_urlGenerator->makeRelativeUrl(
1354
'http://photos.example.com/gallery2/phpunit_test.php'));
1357
function testMakeRelativeUrlBaseFileNotInRequestUri() {
1358
$_SERVER['REQUEST_URI'] = '/gallery2/v/AlbumName';
1359
$this->_urlGenerator->_file[0] = 'main.php';
1360
$this->assertEquals('/gallery2/v/AnotherAlbum', $this->_urlGenerator->makeRelativeUrl(
1361
'http://example.com/gallery2/v/AnotherAlbum'));
1364
/* Don't be fooled by baseFile in the return URL */
1365
function testMakeRelativeUrlBaseFileInReturnUrl() {
1366
$_SERVER['REQUEST_URI'] = '/gallery2/v/AlbumName?g2_return=main.php';
1367
$this->_urlGenerator->_file[0] = 'main.php';
1368
$this->assertEquals('/gallery2/v/AnotherAlbum?g2_return=main.php',
1369
$this->_urlGenerator->makeRelativeUrl(
1370
'http://example.com/gallery2/v/AnotherAlbum?g2_return=main.php'));
1374
function testMakeRelativeUrlBaseFileNotInReturnUrl() {
1375
$_SERVER['REQUEST_URI'] = '/gallery2/phpunit_test.php';
1376
$this->_urlGenerator->_file[0] = 'phpunit_test.php';
1377
$this->assertEquals('phpunit_test.php?foo=bar',
1378
$this->_urlGenerator->makeRelativeUrl(
1379
'http://example.com/gallery2/phpunit_test.php?foo=bar'));
1383
function testMakeRelativeUrlOtherProtocol() {
1384
$this->_urlGenerator->_currentBaseHost[0] = 'https://example.com';
1385
$this->assertEquals('http://example.com/gallery2/phpunit_test.php',
1386
$this->_urlGenerator->makeRelativeUrl(
1387
'http://example.com/gallery2/phpunit_test.php'));
1390
/* A multisite / embedded G2 scenario */
1391
function testMakeRelativeUrlDifferentServerPath() {
1392
$this->_urlGenerator->_path[0] = '/portal/';
1393
$this->assertEquals('/gallery2/phpunit_test.php',
1394
$this->_urlGenerator->makeRelativeUrl('/gallery2/phpunit_test.php'));
1398
* _ parseUri should accept various formats and - similar to parse_url() -
1399
* split the URI into its subparts
1401
function testParseUri() {
1403
$tests[] = array('uri' => 'main.php', 'protocol' => null,
1404
'host' => null, 'path' => null, 'file' => 'main.php');
1405
$tests[] = array('uri' => '/main.php', 'protocol' => null,
1406
'host' => null, 'path' => '/', 'file' => 'main.php');
1407
$tests[] = array('uri' => 'index.php?module=gallery2', 'protocol' => null,
1408
'host' => null, 'path' => null, 'file' => 'index.php?module=gallery2');
1409
$tests[] = array('uri' => 'main.php/', 'protocol' => null,
1410
'host' => 'main.php', 'path' => '/', 'file' => '');
1411
$tests[] = array('uri' => '/index.php/', 'protocol' => null,
1412
'host' => null, 'path' => '/index.php/', 'file' => '');
1413
$tests[] = array('uri' => '/gallery2/foo', 'protocol' => null,
1414
'host' => null, 'path' => '/gallery2/', 'file' => 'foo');
1415
$tests[] = array('uri' => '/', 'protocol' => null,
1416
'host' => null, 'path' => '/', 'file' => '');
1417
$tests[] = array('uri' => 'www.example.com/', 'protocol' => null,
1418
'host' => 'www.example.com', 'path' => '/', 'file' => '');
1419
$tests[] = array('uri' => 'www.example.com', 'protocol' => null,
1420
'host' => null, 'path' => null, 'file' => 'www.example.com');
1421
$tests[] = array('uri' => 'https://www.example.com', 'protocol' => 'https',
1422
'host' => 'www.example.com', 'path' => null, 'file' => null);
1423
$tests[] = array('uri' => 'www.example.com', 'protocol' => null,
1424
'host' => null, 'path' => null, 'file' => 'www.example.com');
1425
$tests[] = array('uri' => 'www.example.com/mod/gallery2/', 'protocol' => null,
1426
'host' => 'www.example.com', 'path' => '/mod/gallery2/', 'file' => '');
1427
$tests[] = array('uri' => 'http://localhost/index.php?mod=gallery2', 'protocol' => 'http',
1428
'host' => 'localhost', 'path' => '/', 'file' => 'index.php?mod=gallery2');
1429
$tests[] = array('uri' => 'https://127.0.0.1/test/index.php', 'protocol' => 'https',
1430
'host' => '127.0.0.1', 'path' => '/test/', 'file' => 'index.php');
1431
$tests[] = array('uri' => '127.0.0.1/test/index.php/', 'protocol' => null,
1432
'host' => '127.0.0.1', 'path' => '/test/index.php/', 'file' => '');
1434
foreach ($tests as $test) {
1435
$expected = array($test['protocol'], $test['host'], $test['path'], $test['file']);
1436
$this->assertEquals($expected, $this->_urlGenerator->_parseUri($test['uri']),
1437
"URI = '" . $test['uri'] . "'");
1441
function testInitSetsIsCookiePathConfiguredIfEmbedded() {
1442
foreach (array(true, false) as $embedded) {
1443
GalleryDataCache::put( 'G2_EMBED', $embedded, true);
1444
foreach (array(true, false) as $isSet) {
1445
$value = $isSet ? '/' : '';
1446
$ret = GalleryCoreApi::setPluginParameter('module', 'core', 'cookie.path', $value);
1448
return $this->failWithStatus($ret);
1450
/* Check if the correct value was stored */
1451
list ($ret, $realValue) = GalleryCoreApi::getPluginParameter('module', 'core',
1454
return $this->failWithStatus($ret);
1456
$this->assertEquals($value, $realValue,
1457
'could not set plugin parameter cookie.path');
1459
/* Execute the test */
1460
$urlGenerator = new GalleryUrlGenerator();
1461
$ret = $urlGenerator->init();
1463
return $this->failWithStatus($ret);
1465
/* Check what we want to verfiy */
1466
$msg = $embedded ? 'embedded, ' : 'standalone, ';
1467
$msg .= $isSet ? 'cookie path set' : 'cookie path not set';
1469
$this->assertEquals($isSet, $urlGenerator->_isCookiePathConfigured, $msg);
1471
$this->assert(!isset($urlGenerator->_isCookiePathConfigured), $msg);
1477
function testGetCacheableUrl1() {
1478
$_SERVER['REQUEST_URI'] = '/gallery2/phpunit_test.php?foo=bar&g2_navId=blah&bar=baz';
1479
$this->assertEquals('http://example.com/gallery2/phpunit_test.php?foo=bar&bar=baz',
1480
$this->_urlGenerator->getCacheableUrl());
1483
function testGetCacheableUrl2() {
1484
$_SERVER['REQUEST_URI'] =
1485
'/gallery2/phpunit_test.php?foo=bar&g2_navId=blah&bar=baz&g2_return=blaa';
1486
$this->assertEquals('http://example.com/gallery2/phpunit_test.php?foo=bar&bar=baz',
1487
$this->_urlGenerator->getCacheableUrl());
1490
function testGetCacheableUrl3() {
1491
$_SERVER['REQUEST_URI'] = '/gallery2/phpunit_test.php?g2_navId=blah';
1492
$this->assertEquals('http://example.com/gallery2/phpunit_test.php',
1493
$this->_urlGenerator->getCacheableUrl());
1496
function testGetCacheableUrl4() {
1497
$_SERVER['REQUEST_URI'] = '/gallery2/phpunit_test.php';
1498
$this->assertEquals('http://example.com/gallery2/phpunit_test.php',
1499
$this->_urlGenerator->getCacheableUrl());
1502
function testGenerateUrlWithNavIdAndSessionString() {
1504
list ($ret) = $this->_prepareGenerateUrl('', 'phpunit_test.php', null);
1506
$this->failWithStatus($ret);
1508
$session =& $gallery->getSession();
1509
$this->assertEquals(true, $session->isPersistent(), 'persistent session');
1510
$this->assert(!empty($session->_sessionId), 'session id');
1512
$actual = $this->_urlGenerator->generateUrl(array('view' => 'foo.Bar', 'navId' => '1234'),
1513
array('forceSessionId' => true));
1514
$expected = 'phpunit_test.php?g2_view=foo.Bar&g2_navId=1234&g2_' .
1515
$session->getKey() . '=' . $session->getId();
1517
$this->assertEquals($expected, $actual, 'url');
1520
function testGenerateUrlWithoutPersistentSession() {
1522
GalleryUtilities::removeRequestVariable(SESSION_ID_PARAMETER);
1523
unset($_COOKIE[SESSION_ID_PARAMETER]);
1524
unset($_SERVER['HTTP_COOKIE']);
1526
$session = new GallerySession();
1527
$ret = $session->init();
1529
return $this->failWithStatus($ret);
1531
$backup = $gallery->_session;
1532
$gallery->_session =& $session;
1533
$this->assertEquals(false, $session->isPersistent(), 'not persistent');
1534
$this->assert(empty($session->_sessionId), 'session id');
1535
$this->assertEquals(SESSION_TEMP_ID, $session->getId(), 'temp id');
1537
$actual = $this->_urlGenerator->generateUrl(array('view' => 'foo.Bar', 'navId' => '1234'),
1538
array('forceSessionId' => true));
1539
/* No navId since there's no persistent session to store the nav history */
1540
$expected = 'phpunit_test.php?g2_view=foo.Bar&g2_' . $session->getKey() .
1541
'=' . $session->getId();
1543
$this->assertEquals($expected, $actual, 'url');
1545
/* And now force to not use the temp id */
1546
$gallery->_session->doNotUseTempId();
1547
$actual = $this->_urlGenerator->generateUrl(array('view' => 'foo.Bar', 'navId' => '1234'),
1548
array('forceSessionId' => true));
1549
$expected = 'phpunit_test.php?g2_view=foo.Bar';
1550
$this->assertEquals($expected, $actual, 'url without temp session id');
1552
$gallery->_session = $backup;
1555
function testOmitDefaults() {
1557
$view = GALLERY_DEFAULT_VIEW;
1558
list ($ret, $rootId) = GalleryCoreApi::getDefaultAlbumId();
1560
return $this->failWithStatus($ret);
1563
/* Omit view parameter for default view */
1564
$url = $this->_urlGenerator->generateUrl(
1565
array('view' => $view, 'itemId' => 123),
1566
array('forceSessionId' => false));
1567
$this->assertEquals('phpunit_test.php?g2_itemId=123', $url);
1569
/* Omit itemId parameter for default album with default view */
1570
$url = $this->_urlGenerator->generateUrl(
1571
array('view' => $view, 'itemId' => $rootId),
1572
array('forceSessionId' => false));
1573
$this->assertEquals('phpunit_test.php', $url);
1575
$gallery->setConfig('defaultAlbumId', 123);
1576
unset($this->_urlGenerator->_rootItemId);
1578
$url = $this->_urlGenerator->generateUrl(
1579
array('view' => $view, 'itemId' => 123),
1580
array('forceSessionId' => false));
1581
$this->assertEquals('phpunit_test.php', $url, 'alternate default album');
1584
function testGenerateUrlWithProtocol() {
1585
$this->assertEquals('webdav://example.com/gallery2/phpunit_test.php?g2_a=b',
1586
$this->_urlGenerator->generateUrl(array('a' => 'b'), array('protocol' => 'webdav')));
1589
function testGenerateUrlAddsAuthTokenForControllerUrls() {
1591
$session =& $gallery->getSession();
1593
$session->put('core.authToken', 'AUTH-TOKEN');
1594
$url = $this->_urlGenerator->generateUrl(
1595
array('controller' => 'core.UserLogin', 'foo' => 123));
1597
$this->_signUrl('phpunit_test.php?g2_controller=core.UserLogin&g2_foo=123');
1598
$this->assertEquals($expectedUrl, $url);
1601
function testGenerateUrlUseAuthTokenTrueHasAuthToken() {
1603
$session =& $gallery->getSession();
1605
$session->put('core.authToken', 'AUTH-TOKEN');
1606
$url = $this->_urlGenerator->generateUrl(
1607
array('view' => 'core.UserLogin', 'foo' => 123), array('useAuthToken' => 1));
1608
$expectedUrl = $this->_signUrl('phpunit_test.php?g2_view=core.UserLogin&g2_foo=123');
1609
$this->assertEquals($expectedUrl, $url);
1612
function testGenerateUrlUseAuthTokenTrueControllerUrlHasAuthToken() {
1614
$session =& $gallery->getSession();
1616
$session->put('core.authToken', 'AUTH-TOKEN');
1617
$url = $this->_urlGenerator->generateUrl(
1618
array('controller' => 'core.UserLogin', 'foo' => 123),
1619
array('useAuthToken' => true));
1621
$this->_signUrl('phpunit_test.php?g2_controller=core.UserLogin&g2_foo=123');
1622
$this->assertEquals($expectedUrl, $url);
1625
function testGenerateUrlUseAuthTokenFalseHasNoAuthToken() {
1627
$session =& $gallery->getSession();
1629
$session->put('core.authToken', 'AUTH-TOKEN');
1630
$url = $this->_urlGenerator->generateUrl(
1631
array('controller' => 'core.UserLogin', 'foo' => 123),
1632
array('useAuthToken' => false));
1633
$expectedUrl = 'phpunit_test.php?g2_controller=core.UserLogin&g2_foo=123';
1634
$this->assertEquals($expectedUrl, $url);
1637
function testAppendParamsToUrl() {
1638
$this->assertEquals(
1639
'test.php?g2_a=foo1%25bar&g2_b=foo2%25bar',
1640
GalleryUrlGenerator::appendParamsToUrl(
1642
array('a' => 'foo1%bar',
1643
'b' => 'foo2%bar')));
1646
function testAppendNestedParamsToUrl() {
1647
$this->assertEquals(
1648
'test.php?g2_a%5Bb%5D=foo1%25bar&g2_a%5Bc%5D=foo2%25bar',
1649
GalleryUrlGenerator::appendParamsToUrl(
1651
array('a' => array('b' => 'foo1%bar',
1656
function testAppendParamsToUrlWithQueryString() {
1657
$this->assertEquals(
1658
'test.php?foo=bar&g2_a=foo1%25bar&g2_b=foo2%25bar',
1659
GalleryUrlGenerator::appendParamsToUrl(
1661
array('a' => 'foo1%bar',
1662
'b' => 'foo2%bar')));
1665
function testAppendParamsToUrlNoPrefix() {
1666
$this->assertEquals(
1667
'test.php?a=foo1%25bar&b=foo2%25bar',
1668
GalleryUrlGenerator::appendParamsToUrl(
1670
array('a' => 'foo1%bar',
1675
function testAppendParamsToUrlNoHtmlEntities() {
1676
$this->assertEquals(
1677
'test.php?g2_a=foo1%25bar&g2_b=foo2%25bar',
1678
GalleryUrlGenerator::appendParamsToUrl(
1680
array('a' => 'foo1%bar',
1685
function testAppendParamsToUrlUrlEncodesParamKeyCorrectly() {
1686
$this->assertEquals(
1687
'test.php?g2_a%25=foo1%25bar&' . urlencode('g2_b%[c%d][e%f]') . '=foo2%25bar',
1688
GalleryUrlGenerator::appendParamsToUrl(
1690
array('a%' => 'foo1%bar',
1691
'b%' => array('c%d' => array('e%f' => 'foo2%bar')))));
1694
function testAppendParamsToUrlNoUrlEncode() {
1695
$this->assertEquals(
1696
'test.php?g2_a%=foo1%bar&g2_b%[c%d][e%f]=foo2%bar',
1697
GalleryUrlGenerator::appendParamsToUrl(
1699
array('a%' => 'foo1%bar',
1700
'b%' => array('c%d' => array('e%f' => 'foo2%bar'))),
1701
true, true, false));
1704
function testAppendParamsToUrlPreservesParamOrder() {
1705
$this->assertEquals(
1706
'test.php?a=1&b[sub1]=2&b[sub2]=3&c=4',
1707
GalleryUrlGenerator::appendParamsToUrl(
1710
'b' => array('sub1' => '2',
1713
false, false, false)); /* Makes it easier to read */
1716
function testAppendParamsToUrlEmptyParams() {
1717
$this->assertEquals(
1719
GalleryUrlGenerator::appendParamsToUrl('test.php', array()));
1723
* Verify that we don't do any special handling for paramater keys with brackets. There seems to
1724
* be no escape sequence for them anyway.
1726
function testAppendParamsToUrlDoesNotHandleBracketsInKeyString() {
1727
$this->assertEquals(
1728
'test.php?foo[bar=1&a[b]=2',
1729
GalleryUrlGenerator::appendParamsToUrl(
1731
array('foo[bar' => '1', 'a[b]' => '2'),
1732
false, false, false)); /* Makes it easier to read */
1736
class UrlGeneratorTestPlatform extends GalleryPlatform {
1738
function file_exists($filename) {
1739
$basedir = realpath(dirname(__FILE__) . '/../../classes');
1741
case "$basedir/../../../test/local/test1.css":
1744
case "$basedir/../../../test/local/test2.css":
1748
print "Unexpected file_exists($filename) call";