mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Implement missing tests
This commit is contained in:
parent
719996dc07
commit
2be8f427c9
|
|
@ -310,7 +310,7 @@ class Head implements RenderableInterface
|
|||
$rendered .= ' ' . $key . '="' . $attribute . '"';
|
||||
}
|
||||
|
||||
$rendered .='></script>';
|
||||
$rendered .= '></script>';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -328,14 +328,14 @@ class Head implements RenderableInterface
|
|||
{
|
||||
$rendered = '';
|
||||
foreach ($this->assets as $uri => $asset) {
|
||||
if ($asset['type']=== AssetType::JSLATE) {
|
||||
if ($asset['type'] === AssetType::JSLATE) {
|
||||
$rendered .= '<script src="' . $uri . '"';
|
||||
|
||||
foreach ($asset['attributes'] as $key => $attribute) {
|
||||
$rendered .= ' ' . $key . '="' . $attribute . '"';
|
||||
}
|
||||
|
||||
$rendered .='></script>';
|
||||
$rendered .= '></script>';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,4 +68,15 @@ class HeadTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
self::assertEquals('<script src="/path/late.js"></script>', $head->renderAssetsLate());
|
||||
}
|
||||
|
||||
public function testAssetWithAttribute() : void
|
||||
{
|
||||
$head = new Head();
|
||||
|
||||
$head->addAsset(AssetType::JSLATE, '/path/late.js', ['testkey' => 'testvalue']);
|
||||
self::assertEquals('<script src="/path/late.js" testkey="testvalue"></script>', $head->renderAssetsLate());
|
||||
|
||||
$head->addAsset(AssetType::JS, '/path/late.js', ['testkey' => 'testvalue']);
|
||||
self::assertEquals('<script src="/path/late.js" testkey="testvalue"></script>', $head->renderAssets());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,6 +105,31 @@ class RouterTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testWithCSRF() : void
|
||||
{
|
||||
$router = new Router();
|
||||
self::assertTrue($router->importFromFile(__Dir__ . '/routeTestCsrf.php'));
|
||||
|
||||
self::assertEquals(
|
||||
[['dest' => '\Modules\Admin\Controller:viewCsrf']],
|
||||
$router->route(
|
||||
(new Request(
|
||||
new Http('http://test.com/backend/admin/settings/csrf/something?test')
|
||||
))->getUri()->getRoute(),
|
||||
'csrf_string'
|
||||
)
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
[],
|
||||
$router->route(
|
||||
(new Request(
|
||||
new Http('http://test.com/backend/admin/settings/csrf/something?test')
|
||||
))->getUri()->getRoute(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testWithPermissions() : void
|
||||
{
|
||||
$router = new Router();
|
||||
|
|
|
|||
10
tests/Router/routeTestCsrf.php
Normal file
10
tests/Router/routeTestCsrf.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
return [
|
||||
'^.*/backend/admin/settings/csrf.*$' => [
|
||||
0 => [
|
||||
'dest' => '\Modules\Admin\Controller:viewCsrf',
|
||||
'verb' => 1,
|
||||
'csrf' => true
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php declare(strict_types=1);
|
||||
return [
|
||||
"^.*/backend/admin/settings/general.*$" => [
|
||||
'^.*/backend/admin/settings/general.*$' => [
|
||||
0 => [
|
||||
"dest" => "\Modules\Admin\Controller:viewSettingsGeneral",
|
||||
"verb" => 1,
|
||||
'dest' => '\Modules\Admin\Controller:viewSettingsGeneral',
|
||||
'verb' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ use phpOMS\Account\PermissionType;
|
|||
use phpOMS\Router\RouteVerb;
|
||||
|
||||
return [
|
||||
"^.*/backend/admin/settings/general.*$" => [
|
||||
'^.*/backend/admin/settings/general.*$' => [
|
||||
0 => [
|
||||
"dest" => "\Modules\Admin\Controller:viewSettingsGeneral",
|
||||
"verb" => RouteVerb::GET,
|
||||
'dest' => '\Modules\Admin\Controller:viewSettingsGeneral',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::READ,
|
||||
|
|
|
|||
|
|
@ -50,30 +50,65 @@ class HttpTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertFalse(Http::isValid('https:/google.de'));
|
||||
}
|
||||
|
||||
public function testSetGet() : void
|
||||
public function testGeneralUriComponents() : void
|
||||
{
|
||||
$obj = new Http($uri = 'https://www.google.com/test/path.php?para1=abc¶2=2#frag');
|
||||
|
||||
self::assertEquals('', $obj->getRootPath());
|
||||
self::assertEquals(0, $obj->getPathOffset());
|
||||
self::assertEquals('https', $obj->getScheme());
|
||||
self::assertEquals('www.google.com', $obj->getHost());
|
||||
self::assertEquals(80, $obj->getPort());
|
||||
self::assertEquals('', $obj->getPass());
|
||||
self::assertEquals('', $obj->getUser());
|
||||
self::assertEquals('/test/path', $obj->getPath());
|
||||
self::assertEquals('/test/path?para1=abc¶2=2', $obj->getRoute());
|
||||
self::assertEquals('test', $obj->getPathElement(0));
|
||||
self::assertEquals('para1=abc¶2=2', $obj->getQuery());
|
||||
self::assertEquals(['para1' => 'abc', 'para2' => '2'], $obj->getQueryArray());
|
||||
self::assertEquals('2', $obj->getQuery('para2'));
|
||||
self::assertEquals('frag', $obj->getFragment());
|
||||
self::assertEquals('https://www.google.com', $obj->getBase());
|
||||
self::assertEquals($uri, $obj->__toString());
|
||||
self::assertEquals('www.google.com:80', $obj->getAuthority());
|
||||
self::assertEquals('', $obj->getUserInfo());
|
||||
}
|
||||
|
||||
public function testRootPath() : void
|
||||
{
|
||||
$obj = new Http('https://www.google.com/test/path.php?para1=abc¶2=2#frag');
|
||||
self::assertEquals('', $obj->getRootPath());
|
||||
|
||||
$obj->setRootPath('a');
|
||||
self::assertEquals('a', $obj->getRootPath());
|
||||
}
|
||||
|
||||
public function testPathOffset() : void
|
||||
{
|
||||
$obj = new Http('https://www.google.com/test/path.php?para1=abc¶2=2#frag');
|
||||
self::assertEquals(0, $obj->getPathOffset());
|
||||
|
||||
$obj->setPathOffset(2);
|
||||
self::assertEquals(2, $obj->getPathOffset());
|
||||
}
|
||||
|
||||
public function testSubdmonain() : void
|
||||
{
|
||||
$obj = new Http('https://www.google.com/test/path.php?para1=abc¶2=2#frag');
|
||||
self::assertEquals('www', $obj->getSubmdomain());
|
||||
|
||||
$obj = new Http('https://google.com/test/path.php?para1=abc¶2=2#frag');
|
||||
self::assertEquals('', $obj->getSubmdomain());
|
||||
|
||||
$obj = new Http('https://test.www.google.com/test/path.php?para1=abc¶2=2#frag');
|
||||
self::assertEquals('test.www', $obj->getSubmdomain());
|
||||
}
|
||||
|
||||
public function testQueryData() : void
|
||||
{
|
||||
$obj = new Http('https://www.google.com/test/path.php?para1=abc¶2=2#frag');
|
||||
self::assertEquals('para1=abc¶2=2', $obj->getQuery());
|
||||
self::assertEquals(['para1' => 'abc', 'para2' => '2'], $obj->getQueryArray());
|
||||
self::assertEquals('2', $obj->getQuery('para2'));
|
||||
self::assertEquals('frag', $obj->getFragment());
|
||||
}
|
||||
|
||||
public function testPathData() : void
|
||||
{
|
||||
$obj = new Http('https://www.google.com/test/path.php?para1=abc¶2=2#frag');
|
||||
self::assertEquals('/test/path', $obj->getPath());
|
||||
self::assertEquals('/test/path?para1=abc¶2=2', $obj->getRoute());
|
||||
self::assertEquals('test', $obj->getPathElement(0));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,6 +113,16 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertFalse($view->getView('test'));
|
||||
}
|
||||
|
||||
public function testOverwritingView() : void
|
||||
{
|
||||
$view = new View();
|
||||
$tView = new View();
|
||||
|
||||
self::assertTrue($view->addView('test', $tView));
|
||||
self::assertTrue($view->addView('test', $tView, 0, true));
|
||||
self::assertFalse($view->addView('test', $tView));
|
||||
}
|
||||
|
||||
public function testRender() : void
|
||||
{
|
||||
$view = new View();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user