Skip to content

Commit

Permalink
Adds coverage for path originating from .do and ?do=
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Manderson committed Sep 24, 2014
1 parent f5d4de4 commit 29b4b32
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Action/RequestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ protected function processPath(\Symfony\Component\HttpFoundation\Request $reques
$path = $request->getPathInfo();
}

// Always have a forward slash in the path
if(substr($path, 0, 1) !== '/') $path = '/' . $path;

// For extension matching, strip the module prefix and extension
$prefix = $this->moduleConfig->getPrefix();
if (!empty($prefix)) {
Expand Down
38 changes: 37 additions & 1 deletion tests/BehavioursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ public function testConfigPaths()
$this->assertTrue($client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Welcome")'));

// Test paths as queries (matched by routes)
$crawler = $client->request('GET', '/?do=resourceA');
$this->assertTrue($client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Resource 1")'));

$crawler = $client->request('GET', '/forwardA');
$this->assertTrue($client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Resource 1")'));

// Test matched by extenions
$crawler = $client->request('GET', '/my/resourceA.do');
$this->assertTrue($client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Resource 1")'));

// Test the module
$crawler = $client->request('GET', '/moduleA/resourceD');
$this->assertTrue($client->getResponse()->isOk());
Expand Down Expand Up @@ -160,12 +174,34 @@ public function createApplication()
})
->assert('path', '.+\.html');

// Add routes to be matched by Phruts
$app->get('/my/{path}.do', function (Request $request) use ($app) {
return $app[Phruts\Util\Globals::ACTION_KERNEL]->handle($request, HttpKernelInterface::SUB_REQUEST, false);
})
->assert('path', '.*')
->before(function(Request $request) {
// Match a ".do" as context path
$path = $request->attributes->get('path');
if(!empty($path)) {
$request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, $path);
}
});

// Add routes to be matched by Phruts
$app->get('{path}', function (Request $request) use ($app) {
return $app[Phruts\Util\Globals::ACTION_KERNEL]->handle($request, HttpKernelInterface::SUB_REQUEST, false);
})
->assert('path', '.*')
->value('path', '/'); // Set the welcome path
->value('path', '/') // Set the welcome path
->before(function(Request $request) {
// Match a "?do=" as context path
$do = $request->get('do');
if(!empty($do)) {
$request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, $do);
}
});



return $app;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Resources/module1-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
parameter="resource">
<forward name="resource" path="/" />
</action>
<action path="/forwardA"
type="\Phruts\Actions\ForwardAction"
parameter="forward">
<forward name="forward" path="/?do=resourceA" />
</action>
</action-mappings>

</phruts-config>

0 comments on commit 29b4b32

Please sign in to comment.