|
|
@ -48,7 +48,10 @@ final class AppTest extends TestCase { |
|
|
|
* @param string $rootFolder, |
|
|
|
* @param string $rootFolder, |
|
|
|
* @param string $filePath, |
|
|
|
* @param string $filePath, |
|
|
|
* @param string $shortScriptName, |
|
|
|
* @param string $shortScriptName, |
|
|
|
* @param string $queryString |
|
|
|
* @param string $queryString, |
|
|
|
|
|
|
|
* @param string $waitedBaseUrl, |
|
|
|
|
|
|
|
* @param string $waitedPageId, |
|
|
|
|
|
|
|
* @param string $waitedPageUrl, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function testApiRewrite( |
|
|
|
public function testApiRewrite( |
|
|
|
string $rootFolder, |
|
|
|
string $rootFolder, |
|
|
@ -56,6 +59,8 @@ final class AppTest extends TestCase { |
|
|
|
string $shortScriptName, |
|
|
|
string $shortScriptName, |
|
|
|
string $queryString, |
|
|
|
string $queryString, |
|
|
|
string $waitedBaseUrl, |
|
|
|
string $waitedBaseUrl, |
|
|
|
|
|
|
|
string $waitedPageId, |
|
|
|
|
|
|
|
string $waitedPageUrl, |
|
|
|
): void |
|
|
|
): void |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->saveSERVER(); |
|
|
|
$this->saveSERVER(); |
|
|
@ -76,19 +81,96 @@ final class AppTest extends TestCase { |
|
|
|
} catch (Throwable $th){ |
|
|
|
} catch (Throwable $th){ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$cwd = getcwd(); |
|
|
|
$this->revertSERVER(); |
|
|
|
$this->revertSERVER(); |
|
|
|
$this->assertTrue($thrown,"TestBaseUrlException not found"); |
|
|
|
$this->assertTrue($thrown,"TestBaseUrlException not found"); |
|
|
|
$this->assertEquals($waitedBaseUrl,$foundTh->getBaseUrl(),"Not same baseUrl"); |
|
|
|
$this->assertEquals($waitedBaseUrl,$foundTh->getBaseUrl(),"Not same baseUrl"); |
|
|
|
|
|
|
|
$this->assertEquals("$cwd/vendor/picocms/plugins/",$foundTh->getPluginDir(),"Not same pluginDir"); |
|
|
|
|
|
|
|
$this->assertEquals("$cwd/vendor/picocms/themes/",$foundTh->getThemeDir(),"Not same themeDir"); |
|
|
|
|
|
|
|
$this->assertEquals("$cwd/",$foundTh->getRootDir(),"Not same rootDir"); |
|
|
|
|
|
|
|
$currentPage = $foundTh->getcurrentPage(); |
|
|
|
|
|
|
|
$this->assertIsArray($currentPage,"Current Page should be an array"); |
|
|
|
|
|
|
|
$this->assertArrayHasKey('id',$currentPage,"Current Page should be an array with key 'id'"); |
|
|
|
|
|
|
|
$this->assertEquals($waitedPageId,$currentPage['id'],"Not waited page's id"); |
|
|
|
|
|
|
|
$this->assertArrayHasKey('url',$currentPage,"Current Page should be an array with key 'url'"); |
|
|
|
|
|
|
|
$this->assertEquals($waitedPageUrl,$currentPage['url'],"Not waited page's url"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function apiRewriteProvider() |
|
|
|
public function apiRewriteProvider() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$data = []; |
|
|
|
$data = []; |
|
|
|
$this->prepareData($data,'content/*','content','index.php','/','','http://localhost/'); |
|
|
|
$this->prepareAPage($data,'','content','index'); |
|
|
|
$this->prepareData($data,'content/index.php*','content','index.php','/index.php','','http://localhost/'); |
|
|
|
$this->prepareAPage($data,'','content','sub/index'); |
|
|
|
|
|
|
|
$this->prepareAPage($data,'','content','theme'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->prepareAPage($data,'','sites/default','index'); |
|
|
|
|
|
|
|
$this->prepareAPage($data,'','sites/default','sub/index'); |
|
|
|
|
|
|
|
$this->prepareAPage($data,'','sites/default','theme'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->prepareAPage($data,'/sea','content','index'); |
|
|
|
|
|
|
|
$this->prepareAPage($data,'/sea','content','sub/index'); |
|
|
|
|
|
|
|
$this->prepareAPage($data,'/sea','content','theme'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->prepareAPage($data,'/sea','sites/default','index'); |
|
|
|
|
|
|
|
$this->prepareAPage($data,'/sea','sites/default','sub/index'); |
|
|
|
|
|
|
|
$this->prepareAPage($data,'/sea','sites/default','theme'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// echo "\n"; |
|
|
|
|
|
|
|
// foreach($data as $name => $line){ |
|
|
|
|
|
|
|
// echo "$name => ".implode(',',$line)."\n"; |
|
|
|
|
|
|
|
// } |
|
|
|
return $data; |
|
|
|
return $data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function prepareAPage( |
|
|
|
|
|
|
|
array &$data, |
|
|
|
|
|
|
|
string $baseScriptName, |
|
|
|
|
|
|
|
string $rootFolder, |
|
|
|
|
|
|
|
string $pageId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$baseUrl = 'http://localhost'.$baseScriptName.'/'; |
|
|
|
|
|
|
|
$isIndex = ($pageId == 'index'); |
|
|
|
|
|
|
|
$isSubIndex = (substr($pageId,-strlen('/index')) == '/index'); |
|
|
|
|
|
|
|
$pageIdInUrl = $isIndex ? '' : ($isSubIndex ? substr($pageId,0,-strlen('/index')) : $pageId) ; |
|
|
|
|
|
|
|
$queriesStrings = $isIndex ? [['q'=>'','s'=>'','f'=>'']] : [ |
|
|
|
|
|
|
|
['q'=>$pageIdInUrl,'s'=>'','f'=>''], |
|
|
|
|
|
|
|
['q'=>'','s'=>$pageIdInUrl,'f'=>''], |
|
|
|
|
|
|
|
['q'=>'','s'=>$pageIdInUrl,'f'=>$pageIdInUrl], |
|
|
|
|
|
|
|
['q'=>$pageIdInUrl,'s'=>$pageIdInUrl,'f'=>''], |
|
|
|
|
|
|
|
['q'=>$pageIdInUrl,'s'=>$pageIdInUrl,'f'=>$pageIdInUrl] |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
foreach ($queriesStrings as $queryData) { |
|
|
|
|
|
|
|
$queryString = empty($queryData['q']) ? '' :'?'.$queryData['q']; |
|
|
|
|
|
|
|
$scriptNameMiddle = empty($queryData['s']) ? '' : $queryData['s'].'/'; |
|
|
|
|
|
|
|
foreach (['','index.php'] as $endScriptName) { |
|
|
|
|
|
|
|
$formattedQueryString = str_replace('/','%2F',$queryString); |
|
|
|
|
|
|
|
$pageUrl = empty($queryData['s']) ? (empty($queryData['q']) ? '' : $formattedQueryString) : $queryData['s']; |
|
|
|
|
|
|
|
$canRewriteFromRoot = empty($queryData['s']) && empty($queryData['f']); |
|
|
|
|
|
|
|
if ($rootFolder == 'content' && $canRewriteFromRoot){ |
|
|
|
|
|
|
|
$scriptName = "$baseScriptName/$scriptNameMiddle$endScriptName"; |
|
|
|
|
|
|
|
$name = $rootFolder.$scriptName.$queryString.'*'; |
|
|
|
|
|
|
|
$this->prepareData($data,$name,$rootFolder,'index.php',$scriptName,$queryData['q'],$baseUrl,$pageId,$pageUrl); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
foreach ([false,true] as $withRewrite) { |
|
|
|
|
|
|
|
if ($withRewrite){ |
|
|
|
|
|
|
|
$scriptName = "$baseScriptName/$scriptNameMiddle$endScriptName"; |
|
|
|
|
|
|
|
$name = $rootFolder.$scriptName.$queryString.' R'; |
|
|
|
|
|
|
|
$waitedUrl = $baseUrl; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$scriptName = "$baseScriptName/$rootFolder/$scriptNameMiddle$endScriptName"; |
|
|
|
|
|
|
|
$name = $rootFolder.$scriptName.$queryString; |
|
|
|
|
|
|
|
$waitedUrl = $baseUrl.$rootFolder.'/'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ($canRewriteFromRoot){ |
|
|
|
|
|
|
|
$this->prepareData($data,$name."*",$rootFolder,"index.php",$scriptName,$queryData['q'],$waitedUrl,$pageId,$pageUrl); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$this->prepareData($data,$name,$rootFolder,"$rootFolder/$pageIdInUrl/index.php",$scriptName,$queryData['q'],$waitedUrl,$pageId,$pageUrl); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function prepareData( |
|
|
|
protected function prepareData( |
|
|
|
array &$data, |
|
|
|
array &$data, |
|
|
|
string $name, |
|
|
|
string $name, |
|
|
@ -97,15 +179,20 @@ final class AppTest extends TestCase { |
|
|
|
string $shortScriptName, |
|
|
|
string $shortScriptName, |
|
|
|
string $queryString, |
|
|
|
string $queryString, |
|
|
|
string $waitedBaseUrl, |
|
|
|
string $waitedBaseUrl, |
|
|
|
|
|
|
|
string $waitedPageId, |
|
|
|
|
|
|
|
string $waitedPageEndUrl, |
|
|
|
) |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$data[$name] = [ |
|
|
|
$waitedPageUrl = $waitedBaseUrl.$waitedPageEndUrl; |
|
|
|
'rootFolder' => $rootFolder, |
|
|
|
$data[$name] = compact([ |
|
|
|
'filePath' => $filePath, |
|
|
|
'rootFolder', |
|
|
|
'shortScriptName' => $shortScriptName, |
|
|
|
'filePath', |
|
|
|
'queryString' => $queryString, |
|
|
|
'shortScriptName', |
|
|
|
'waitedBaseUrl' => $waitedBaseUrl, |
|
|
|
'queryString', |
|
|
|
]; |
|
|
|
'waitedBaseUrl', |
|
|
|
|
|
|
|
'waitedPageId', |
|
|
|
|
|
|
|
'waitedPageUrl' |
|
|
|
|
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|