Skip to content

Commit

Permalink
MINOR Fixed HTTPTest->testSetGetVar() (merged from r98409)
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@98410 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu authored and Sam Minnee committed Feb 2, 2011
1 parent 5b81610 commit add3165
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions tests/HTTPTest.php
Expand Up @@ -26,44 +26,45 @@ public function testGetLinksIn() {
* Tests {@link HTTP::setGetVar()} * Tests {@link HTTP::setGetVar()}
*/ */
public function testSetGetVar() { public function testSetGetVar() {
// Hackery to work around volatile URL formats in test invocation // Hackery to work around volatile URL formats in test invocation,
// and the inability of Director::absoluteBaseURL() to produce consistent URLs.
$expectedPath = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']); $expectedPath = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
$this->assertContains(
$expectedPath, // TODO This should test the absolute URL, but we can't get it reliably
HTTP::setGetVar('foo', 'bar'), // with port and auth URI parts.
'Omitting a URL falls back to current URL' $expectedBasePath = Director::baseURL();
);
$this->assertContains( foreach(array($expectedPath, 'foo=bar') as $e) {
'foo=bar', $this->assertContains(
HTTP::setGetVar('foo', 'bar'), $e,
'Omitting a URL falls back to current URL' HTTP::setGetVar('foo', 'bar'),
); 'Omitting a URL falls back to current URL'

);
$this->assertEquals( }
Director::absoluteBaseURL() . 'relative/url?foo=bar',
HTTP::setGetVar('foo', 'bar', 'relative/url'),
'Relative URL without slash prefix returns URL with absolute base'
);

$this->assertEquals(
Director::absoluteBaseURL() . '/relative/url?foo=bar',
HTTP::setGetVar('foo', 'bar', '/relative/url'),
'Relative URL with slash prefix returns URL with absolute base'
);


$this->assertEquals( foreach(array($expectedBasePath, '/relative/url?foo=bar') as $e) {
Director::absoluteBaseURL() . '/relative/url?baz=buz&foo=bar', $this->assertContains(
HTTP::setGetVar('foo', 'bar', '/relative/url?baz=buz'), $e,
'Relative URL with existing query params, and new added key' HTTP::setGetVar('foo', 'bar', 'relative/url'),
); 'Relative URL without slash prefix returns URL with absolute base'
);
}

foreach(array($expectedBasePath, '/relative/url?baz=buz&foo=bar') as $e) {
$this->assertContains(
$e,
HTTP::setGetVar('foo', 'bar', '/relative/url?baz=buz'),
'Relative URL with existing query params, and new added key'
);
}


$this->assertEquals( $this->assertEquals(
'http://test.com/?foo=new&buz=baz', 'http://test.com/?foo=new&buz=baz',
HTTP::setGetVar('foo', 'new', 'http://test.com/?foo=old&buz=baz'), HTTP::setGetVar('foo', 'new', 'http://test.com/?foo=old&buz=baz'),
'Absolute URL without path and multipe existing query params, overwriting an existing parameter' 'Absolute URL without path and multipe existing query params, overwriting an existing parameter'
); );


$this->assertEquals( $this->assertContains(
'http://test.com/?foo=new', 'http://test.com/?foo=new',
HTTP::setGetVar('foo', 'new', 'http://test.com/?foo=&foo=old'), HTTP::setGetVar('foo', 'new', 'http://test.com/?foo=&foo=old'),
'Absolute URL and empty query param' 'Absolute URL and empty query param'
Expand Down

0 comments on commit add3165

Please sign in to comment.