Skip to content

Commit

Permalink
Misc fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanAquino committed Jun 20, 2013
1 parent e13a48d commit 9fc819b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/models/Command.php
Expand Up @@ -96,15 +96,22 @@ public function applySwitches($switches) {
$url = $this->url;
$urlencodeValues = true;
$rawurlencodeValues = false;
$spaceReplacement = null;
if (strpos($url, '[no url encoding]') !== false) {
$url = str_replace('[no url encoding]', '', $url);
$urlencodeValues = false;
} elseif (strpos($url, '[use %20 for spaces]') !== false) {
$url = str_replace('[use %20 for spaces]', '', $url);
$rawurlencodeValues = true;
$urlencodeValues = false;
} elseif (preg_match('/\[use (.{1,4}) for spaces\]/', $url, $matches)) {
$url = str_replace($matches[0], '', $url);
$spaceReplacement = $matches[1];
}
foreach ($switches as $name => $value) {
if ($spaceReplacement !== null) {
$value = str_replace(' ', $spaceReplacement, $value);
}
if ($urlencodeValues) {
$value = urlencode($value);
} elseif ($rawurlencodeValues) {
Expand Down
6 changes: 6 additions & 0 deletions test/CommandTest.php
Expand Up @@ -94,5 +94,11 @@ public function testApplySwitches_UsesPercent20ForSpaces() {
$this->assertSame('http://google.com/?a=A%20B', $url);
}

public function testApplySwitches_UsesXForSpaces() {
$this->command->url = 'http://google.com/?a=%s[use X for spaces]';
$url = $this->command->applySwitches(array('%s' => 'A B'));
$this->assertSame('http://google.com/?a=AXB', $url);
}

}

2 changes: 1 addition & 1 deletion test/ControllerTest.php
Expand Up @@ -5,7 +5,7 @@
class ControllerTest extends PHPUnit_Framework_TestCase {

public function setUp() {
$this->controller = new TestController(null);
$this->controller = new TestController(null, null);
}

public function testGetName() {
Expand Down
1 change: 1 addition & 0 deletions test/bootstrap.php
Expand Up @@ -4,3 +4,4 @@
*
* Usage: phpunit --bootstrap test/bootstrap.php test
*/
require_once 'app/helpers/functions.php';

0 comments on commit 9fc819b

Please sign in to comment.