Skip to content

Commit

Permalink
Testing & refactoring in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Nov 17, 2023
1 parent 9013288 commit d03c167
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ public function __construct(

if($uri_path === '/') {

///////////////////////////////////////////////////
// no controller, no action, no explicit base path
///////////////////////////////////////////////////

$recomputed_uri =
(
$this->controller_name_from_uri !== ''
Expand All @@ -228,6 +231,10 @@ public function __construct(

} elseif (str_contains($uri_path, $this->getAppBasePath())) {

/////////////////////////////////////////////
// base path is contained in the request uri
/////////////////////////////////////////////

$recomputed_uri =
(
$this->controller_name_from_uri !== ''
Expand All @@ -254,11 +261,11 @@ public function __construct(
(($this->controller_name_from_uri === '') || ($this->action_name_from_uri === ''))
&& ( ($uri_path !== '') && ($uri_path !== '/') && (strpos($uri_path, '/') !== false) )
) {
// calculate $this->controller_name_from_uri and / or
// Calculate $this->controller_name_from_uri and / or
// $this->action_name_from_uri if necessary
if( $uri_path[0] === '/' ) {

// remove leading slash /
// Remove leading slash /
$uri_path = substr($uri_path, 1);
}

Expand Down
35 changes: 34 additions & 1 deletion tests/BaseControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public function testThat_Constructor_WorksAsExpected() {
// constructor
//////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////
// Test that when no controller and no action are in the
// request uri, that the controller & action passed to the
Expand All @@ -159,6 +158,40 @@ public function testThat_Constructor_WorksAsExpected() {
'http://google.com/controller-from-constructor/action-from-constructor',
$controller5->getCurrentUriComputed()
);

//////////////////////////////////////////////////////////

// Make sure that uri's with no controller & no action but just
// forward slashes lead to an empty string value for both
// getActionNameFromUri() & getControllerNameFromUri()

$req6 = $this->newRequest('http://google.com/');
$controller6 = new BaseController(
$psr11Container, '', '', $req6, $resp
);
self::assertEquals('', $controller6->getActionNameFromUri());
self::assertEquals('', $controller6->getControllerNameFromUri());

$req7 = $this->newRequest('http://google.com//');
$controller7 = new BaseController(
$psr11Container, '', '', $req7, $resp
);
self::assertEquals('', $controller7->getActionNameFromUri());
self::assertEquals('', $controller7->getControllerNameFromUri());

$req8 = $this->newRequest('http://google.com///');
$controller8 = new BaseController(
$psr11Container, '', '', $req8, $resp
);
self::assertEquals('', $controller8->getActionNameFromUri());
self::assertEquals('', $controller8->getControllerNameFromUri());

$req9 = $this->newRequest('http://google.com////');
$controller9 = new BaseController(
$psr11Container, '', '', $req9, $resp
);
self::assertEquals('', $controller9->getActionNameFromUri());
self::assertEquals('', $controller9->getControllerNameFromUri());
}

public function testThat_getActionNameFromUri_WorksAsExpected() {
Expand Down

0 comments on commit d03c167

Please sign in to comment.