feat(AppTest): next test to usr phpunit
This commit is contained in:
parent
43dd441473
commit
1f89a43499
35
src/TestBaseUrl.php
Normal file
35
src/TestBaseUrl.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
// Authors: see README.md
|
||||
|
||||
namespace SeaCMS\App;
|
||||
|
||||
use SeacmsAppPlugin;
|
||||
use SeaCMS\App\TestException;
|
||||
use SeaCMS\App\TestInterface;
|
||||
use SeaCMS\App\TestBaseUrlException;
|
||||
|
||||
/**
|
||||
* test base Url
|
||||
*/
|
||||
class TestBaseUrl implements TestInterface
|
||||
{
|
||||
/**
|
||||
* run tests
|
||||
* @param SeacmsAppPlugin $plugin
|
||||
* @param string $output
|
||||
* @throws TestException
|
||||
*/
|
||||
public function run(SeacmsAppPlugin $plugin, string $output){
|
||||
$pico = $plugin->getPico();
|
||||
throw new TestBaseUrlException(
|
||||
$pico->getBaseUrl(),
|
||||
$pico->getRootDir(),
|
||||
$pico->getPluginsDir(),
|
||||
$pico->getThemesDir(),
|
||||
$pico->getCurrentPage(),
|
||||
"Testing base url"
|
||||
);
|
||||
|
||||
}
|
||||
}
|
109
src/TestBaseUrlException.php
Normal file
109
src/TestBaseUrlException.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
// Authors: see README.md
|
||||
|
||||
namespace SeaCMS\App;
|
||||
|
||||
use SeaCMS\App\TestException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* define exception to caught return for tests
|
||||
*/
|
||||
class TestBaseUrlException extends TestException
|
||||
{
|
||||
/**
|
||||
* caught baseUrl
|
||||
* @var string
|
||||
*/
|
||||
protected $baseUrl;
|
||||
|
||||
/**
|
||||
* plugin dir
|
||||
* @var string
|
||||
*/
|
||||
protected $pluginDir;
|
||||
|
||||
/**
|
||||
* root dir
|
||||
* @var string
|
||||
*/
|
||||
protected $rootDir;
|
||||
|
||||
/**
|
||||
* theme dir
|
||||
* @var string
|
||||
*/
|
||||
protected $themeDir;
|
||||
|
||||
/**
|
||||
* currentPage
|
||||
* @var null|array
|
||||
*/
|
||||
protected $currentPage;
|
||||
|
||||
public function __construct(
|
||||
string $baseUrl,
|
||||
string $rootDir,
|
||||
string $pluginDir,
|
||||
string $themeDir,
|
||||
?array $currentPage,
|
||||
string $message = "",
|
||||
int $code=0,
|
||||
Throwable $th = null
|
||||
)
|
||||
{
|
||||
parent::__construct($message,$code,$th);
|
||||
$this->baseUrl = $baseUrl;
|
||||
$this->rootDir = $rootDir;
|
||||
$this->pluginDir = $pluginDir;
|
||||
$this->themeDir = $themeDir;
|
||||
$this->currentPage = $currentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* get baseUrl
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseUrl(): string
|
||||
{
|
||||
return $this->baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* get pluginDir
|
||||
* @return string
|
||||
*/
|
||||
public function getPluginDir(): string
|
||||
{
|
||||
return $this->pluginDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* get rootDir
|
||||
* @return string
|
||||
*/
|
||||
public function getRootDir(): string
|
||||
{
|
||||
return $this->rootDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* get themeDir
|
||||
* @return string
|
||||
*/
|
||||
public function getThemeDir(): string
|
||||
{
|
||||
return $this->themeDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* get currentPage
|
||||
* @return null|array
|
||||
*/
|
||||
public function getcurrentPage(): ?array
|
||||
{
|
||||
return $this->currentPage;
|
||||
}
|
||||
|
||||
}
|
@ -7,26 +7,78 @@
|
||||
|
||||
namespace SeaCMS\App\Test;
|
||||
|
||||
use SeaCMS\App;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SeaCMS\App;
|
||||
use SeaCMS\App\TestBaseUrl;
|
||||
use SeaCMS\App\TestBaseUrlException;
|
||||
use Throwable;
|
||||
|
||||
final class AppTest extends TestCase {
|
||||
|
||||
public function testSuccess(): void
|
||||
/**
|
||||
* @dataProvider apiRewriteProvider
|
||||
* @covers App::update_SERVERIfNeeded
|
||||
* @param string $rootFolder,
|
||||
* @param string $filePath,
|
||||
* @param string $shortScriptName,
|
||||
* @param string $queryString
|
||||
*/
|
||||
public function testApiRewrite(
|
||||
string $rootFolder,
|
||||
string $filePath,
|
||||
string $shortScriptName,
|
||||
string $queryString,
|
||||
string $waitedBaseUrl,
|
||||
): void
|
||||
{
|
||||
$this->saveSERVER();
|
||||
$this->defineServer(
|
||||
true,
|
||||
'index.php',
|
||||
'/',
|
||||
''
|
||||
$filePath,
|
||||
$shortScriptName,
|
||||
$queryString
|
||||
);
|
||||
$app = new App('');
|
||||
$app = new App($rootFolder,new TestBaseUrl());
|
||||
$thrown = false;
|
||||
$foundTh = null;
|
||||
try {
|
||||
$output = $app->runPico();
|
||||
$this->assertTrue($app instanceof App);
|
||||
} catch (TestBaseUrlException $th) {
|
||||
$thrown = true;
|
||||
$foundTh = $th;
|
||||
} catch (Throwable $th){
|
||||
|
||||
}
|
||||
public function testFailure(): void
|
||||
$this->revertSERVER();
|
||||
$this->assertTrue($thrown,"TestBaseUrlException not found");
|
||||
$this->assertEquals($waitedBaseUrl,$foundTh->getBaseUrl(),"Not same baseUrl");
|
||||
}
|
||||
|
||||
public function apiRewriteProvider()
|
||||
{
|
||||
$this->assertTrue(false);
|
||||
$data = [];
|
||||
$this->prepareData($data,'content/*','content','index.php','/','','http://localhost/');
|
||||
$this->prepareData($data,'content/index.php*','content','index.php','/index.php','','http://localhost/');
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function prepareData(
|
||||
array &$data,
|
||||
string $name,
|
||||
string $rootFolder,
|
||||
string $filePath,
|
||||
string $shortScriptName,
|
||||
string $queryString,
|
||||
string $waitedBaseUrl,
|
||||
)
|
||||
{
|
||||
$data[$name] = [
|
||||
'rootFolder' => $rootFolder,
|
||||
'filePath' => $filePath,
|
||||
'shortScriptName' => $shortScriptName,
|
||||
'queryString' => $queryString,
|
||||
'waitedBaseUrl' => $waitedBaseUrl,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user