diff --git a/Localization/L11nManager.php b/Localization/L11nManager.php index a63f9084a..6b0b4f8d1 100644 --- a/Localization/L11nManager.php +++ b/Localization/L11nManager.php @@ -114,8 +114,9 @@ final class L11nManager /** @noinspection PhpIncludeInspection */ $lang = include $file; - foreach ($lang as $code => $translation) - $this->loadLanguage($code, $from, $translation); + foreach ($lang as $code => $translation) { + $this->loadLanguage($code, $from, $translation); + } } /** diff --git a/Message/Http/HttpHeader.php b/Message/Http/HttpHeader.php index 58327ebdd..e022c7fbf 100644 --- a/Message/Http/HttpHeader.php +++ b/Message/Http/HttpHeader.php @@ -233,7 +233,7 @@ final class HttpHeader extends HeaderAbstract } foreach ($this->header as $name => $arr) { - foreach ($arr as $ele => $value) { + foreach ($arr as $value) { \header($name . ': ' . $value); } } diff --git a/Message/Http/HttpResponse.php b/Message/Http/HttpResponse.php index c27782714..731a803d2 100644 --- a/Message/Http/HttpResponse.php +++ b/Message/Http/HttpResponse.php @@ -208,7 +208,9 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface */ public function endAllOutputBuffering() : void { - $this->header->push(); + if (!$this->header->isLocked()) { + $this->header->push(); + } $levels = \ob_get_level(); for ($i = 0; $i < $levels; ++$i) { diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index a7f75bdeb..0cd4c140d 100644 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -92,14 +92,14 @@ abstract class RequestAbstract implements MessageInterface $key = \mb_strtolower($key); - if ($type === null) { - return $this->data[$key] ?? null; - } - if (!isset($this->data[$key])) { return null; } + if ($type === null) { + return $this->data[$key] ?? null; + } + switch ($type) { case 'int': return (int) $this->data[$key]; diff --git a/Uri/Argument.php b/Uri/Argument.php index 53098eb87..e5a5a230d 100644 --- a/Uri/Argument.php +++ b/Uri/Argument.php @@ -186,7 +186,7 @@ final class Argument implements UriInterface $end = \stripos($uri, ' ', $start + 1); if ($end === false) { - $end = \strlen($uri); + $end = \strlen($uri); // @codeCoverageIgnore } $path = $start < 8 ? \substr($uri, $start + 1, $end - $start - 1) : $uri; diff --git a/Utils/IO/Zip/Tar.php b/Utils/IO/Zip/Tar.php index 2c5f3667b..6f3654d06 100644 --- a/Utils/IO/Zip/Tar.php +++ b/Utils/IO/Zip/Tar.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace phpOMS\Utils\IO\Zip; use phpOMS\System\File\FileUtils; +use phpOMS\System\File\Local\Directory; /** * Zip class for handling zip files. @@ -102,6 +103,10 @@ class Tar implements ArchiveInterface return false; } + if (!\is_dir($destination)) { + Directory::create($destination, recursive: true); + } + try { $destination = \str_replace('\\', '/', $destination); $destination = \rtrim($destination, '/'); diff --git a/Validation/Finance/Iban.php b/Validation/Finance/Iban.php index 739206677..d408481c8 100644 --- a/Validation/Finance/Iban.php +++ b/Validation/Finance/Iban.php @@ -35,7 +35,7 @@ final class Iban extends ValidatorAbstract $temp = \substr($value, 0, 2); if ($temp === false) { - return false; + return false; // @codeCoverageIgnore } $enumName = 'C_' . \strtoupper($temp); diff --git a/tests/Localization/Defaults/CountryTest.php b/tests/Localization/Defaults/CountryTest.php index c0cc83b3d..6665f17d8 100644 --- a/tests/Localization/Defaults/CountryTest.php +++ b/tests/Localization/Defaults/CountryTest.php @@ -39,5 +39,7 @@ class CountryTest extends \PHPUnit\Framework\TestCase self::assertEquals('', $obj->getCode3()); self::assertEquals(0, $obj->getNumeric()); self::assertEquals('', $obj->getSubdevision()); + self::assertEquals('', $obj->getRegion()); + self::assertFalse($obj->isDeveloped()); } } diff --git a/tests/Localization/Defaults/CurrencyTest.php b/tests/Localization/Defaults/CurrencyTest.php index 9f9ea63f1..78c432067 100644 --- a/tests/Localization/Defaults/CurrencyTest.php +++ b/tests/Localization/Defaults/CurrencyTest.php @@ -39,5 +39,6 @@ class CurrencyTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $obj->getSubunits()); self::assertEquals('', $obj->getDecimals()); self::assertEquals('', $obj->getCountries()); + self::assertEquals('', $obj->getCode()); } } diff --git a/tests/Localization/L11nManagerTest.php b/tests/Localization/L11nManagerTest.php index 0a6fe0662..f16cc5663 100644 --- a/tests/Localization/L11nManagerTest.php +++ b/tests/Localization/L11nManagerTest.php @@ -96,16 +96,31 @@ class L11nManagerTest extends \PHPUnit\Framework\TestCase * @covers phpOMS\Localization\L11nManager * @group framework */ - public function testLanguageFile() : void + public function testLanguageFromLanguageFile() : void { $this->l11nManager2 = new L11nManager('Api'); $this->l11nManager2->loadLanguageFromFile('en', 'Test', __DIR__ . '/langTestFile.php'); + $this->l11nManager2->loadLanguageFromFile('en', 'Test', __DIR__ . '/invalidLangTestFile.php'); // the l11n manager doesn't do anything for invalid lang file paths self::assertEquals('value', $this->l11nManager2->getHtml('en', 'Test', 'RandomThemeDoesNotMatterAlreadyLoaded', 'key')); self::assertEquals(['Test' => ['key' => 'value']], $this->l11nManager2->getModuleLanguage('en')); self::assertEquals(['key' => 'value'], $this->l11nManager2->getModuleLanguage('en', 'Test')); } + /** + * @testdox Language data can be loaded from a file + * @covers phpOMS\Localization\L11nManager + * @group framework + */ + public function testLanguageMultipleLanguagesFromSingleFile() : void + { + $this->l11nManager2 = new L11nManager('Api'); + $this->l11nManager2->loadLanguageFile('Test', __DIR__ . '/multiLangTestFile.php'); + $this->l11nManager2->loadLanguageFile('Test', __DIR__ . '/invalidLangTestFile.php'); // the l11n manager doesn't do anything for invalid lang file paths + self::assertEquals('Test_EN', $this->l11nManager2->getHtml('en', 'Test', 'RandomThemeDoesNotMatterAlreadyLoaded', 'key')); + self::assertEquals('Test_DE', $this->l11nManager2->getHtml('de', 'Test', 'RandomThemeDoesNotMatterAlreadyLoaded', 'key')); + } + /** * @testdox The numeric value can be printed based on the localization * @covers phpOMS\Localization\L11nManager @@ -163,6 +178,7 @@ class L11nManagerTest extends \PHPUnit\Framework\TestCase $date = new \DateTime('2020-01-01 13:45:22'); self::assertEquals('2020.01.01', $this->l11nManager->getDateTime($l11n, $date, 'medium')); self::assertEquals('2020.01.01 01:45', $this->l11nManager->getDateTime($l11n, $date, 'long')); + self::assertEquals('', $this->l11nManager->getDateTime($l11n, null, 'long')); } /** diff --git a/tests/Localization/LocalizationTest.php b/tests/Localization/LocalizationTest.php index 6e080c3a2..3aaffb82d 100644 --- a/tests/Localization/LocalizationTest.php +++ b/tests/Localization/LocalizationTest.php @@ -330,6 +330,17 @@ class LocalizationTest extends \PHPUnit\Framework\TestCase self::assertEquals([1], $this->localization->getSpeed()); } + /** + * @testdox Localization data can be loaded from a locale file + * @covers phpOMS\Localization\Localization + * @group framework + */ + public function testLocalizationFromLanguageCode() : void + { + $l11n = Localization::fromLanguage(ISO639x1Enum::_DE); + self::assertEquals(ISO4217CharEnum::_EUR, $l11n->getCurrency()); + } + /** * @testdox Localization data can be loaded from a locale file * @covers phpOMS\Localization\Localization @@ -337,8 +348,8 @@ class LocalizationTest extends \PHPUnit\Framework\TestCase */ public function testLocalizationLoading() : void { - $this->localization->loadFromLanguage(ISO639x1Enum::_EN); - self::assertEquals(ISO4217CharEnum::_USD, $this->localization->getCurrency()); + $this->localization->loadFromLanguage(ISO639x1Enum::_DE); + self::assertEquals(ISO4217CharEnum::_EUR, $this->localization->getCurrency()); } /** @@ -348,7 +359,7 @@ class LocalizationTest extends \PHPUnit\Framework\TestCase */ public function testLocalizationSerialize() : void { - $this->localization->loadFromLanguage(ISO639x1Enum::_EN); + $this->localization->loadFromLanguage(ISO639x1Enum::_DE); $l11n1 = $this->localization->jsonSerialize(); $l11nObj = Localization::fromJson($l11n1); @@ -364,8 +375,8 @@ class LocalizationTest extends \PHPUnit\Framework\TestCase */ public function testInvalidCountryLocalizationLoading() : void { - $this->localization->loadFromLanguage(ISO639x1Enum::_EN, 'ABC'); - self::assertEquals(ISO4217CharEnum::_USD, $this->localization->getCurrency()); + $this->localization->loadFromLanguage(ISO639x1Enum::_DE, 'ABC'); + self::assertEquals(ISO4217CharEnum::_EUR, $this->localization->getCurrency()); } /** diff --git a/tests/Localization/multiLangTestFile.php b/tests/Localization/multiLangTestFile.php new file mode 100644 index 000000000..6486ffc04 --- /dev/null +++ b/tests/Localization/multiLangTestFile.php @@ -0,0 +1,14 @@ + [ + 'Test' => [ // Identifier e.g. Module/application + 'key' => 'Test_EN', + ], + ], + 'de' => [ + 'Test' => [ // Identifier e.g. Module/application + 'key' => 'Test_DE', + ], + ], +]; diff --git a/tests/Message/Http/HttpRequestTest.php b/tests/Message/Http/HttpRequestTest.php index a2333c5c6..4208ba022 100644 --- a/tests/Message/Http/HttpRequestTest.php +++ b/tests/Message/Http/HttpRequestTest.php @@ -23,6 +23,7 @@ use phpOMS\Message\Http\Rest; use phpOMS\Router\RouteVerb; use phpOMS\System\MimeType; use phpOMS\Uri\HttpUri; +use phpOMS\Localization\ISO639x1Enum; /** * @testdox phpOMS\tests\Message\Http\HttpRequestTest: HttpRequest wrapper for http requests @@ -106,6 +107,18 @@ class HttpRequestTest extends \PHPUnit\Framework\TestCase self::assertEquals(RouteVerb::PUT, $request->getRouteVerb()); } + /** + * @testdox The request referer can be returned + * @covers phpOMS\Message\Http\HttpRequest + * @group framework + */ + public function testRequestRefererOutput() : void + { + $request = new HttpRequest(new HttpUri(''), $l11n = new Localization()); + + self::assertEquals('', $request->getReferer()); + } + /** * @testdox The route verb gets correctly inferred from the request method * @covers phpOMS\Message\Http\HttpRequest @@ -137,6 +150,21 @@ class HttpRequestTest extends \PHPUnit\Framework\TestCase self::assertEquals('http://www.google.com/test/path', $request->__toString()); } + /** + * @testdox The request langauge can be returned + * @covers phpOMS\Message\Http\HttpRequest + * @group framework + */ + public function testLangaugeOutput() : void + { + $request = new HttpRequest(new HttpUri('http://www.google.com/test/path'), $l11n = new Localization()); + + $request->header->l11n = new Localization(); + $request->header->l11n->setLanguage(ISO639x1Enum::_DE); + + self::assertEquals(ISO639x1Enum::_DE, $request->getLanguage()); + } + /** * @testdox The url hashes for the different paths get correctly generated * @covers phpOMS\Message\Http\HttpRequest @@ -155,21 +183,6 @@ class HttpRequestTest extends \PHPUnit\Framework\TestCase self::assertEquals($l11n, $request->header->l11n); } - /** - * @testdox Request data can be set and returned - * @covers phpOMS\Message\Http\HttpRequest - * @group framework - */ - public function testDataInputOutput() : void - { - $request = new HttpRequest(new HttpUri('http://www.google.com/test/path'), $l11n = new Localization()); - - self::assertTrue($request->setData('key', 'value')); - self::assertEquals('value', $request->getData('key')); - self::assertTrue($request->hasData('key')); - self::assertEquals(['key' => 'value'], $request->getData()); - } - /** * @testdox Request data can be forcefully overwritten * @covers phpOMS\Message\Http\HttpRequest diff --git a/tests/Message/Http/HttpResponseTest.php b/tests/Message/Http/HttpResponseTest.php index 8ffc54f2e..f0782f127 100644 --- a/tests/Message/Http/HttpResponseTest.php +++ b/tests/Message/Http/HttpResponseTest.php @@ -16,6 +16,8 @@ namespace phpOMS\tests\Message\Http; use phpOMS\Message\Http\HttpResponse; use phpOMS\System\MimeType; +use phpOMS\Localization\Localization; +use phpOMS\Localization\ISO639x1Enum; /** * @testdox phpOMS\tests\Message\Http\ResponseTest: HttpResponse wrapper for http responses @@ -83,6 +85,40 @@ class ResponseTest extends \PHPUnit\Framework\TestCase self::assertFalse($this->response->remove('a')); } + /** + * @testdox Test disabling output buffering + * @covers phpOMS\Message\Http\HttpResponse + * @group framework + */ + public function testEndAllOutputBuffering() : void + { + if (\headers_sent()) { + $this->response->header->lock(); + } + $start = \ob_get_level(); + + \ob_start(); + \ob_start(); + + self::assertEquals($start + 2, \ob_get_level()); + $this->response->endAllOutputBuffering(); + self::assertEquals(0, \ob_get_level()); + } + + /** + * @testdox The response langauge can be returned + * @covers phpOMS\Message\Http\HttpResponse + * @group framework + */ + public function testLangaugeOutput() : void + { + + $this->response->header->l11n = new Localization(); + $this->response->header->l11n->setLanguage(ISO639x1Enum::_DE); + + self::assertEquals(ISO639x1Enum::_DE, $this->response->getLanguage()); + } + /** * @testdox Response data can be turned into an array * @covers phpOMS\Message\Http\HttpResponse diff --git a/tests/Message/RequestAbstractTest.php b/tests/Message/RequestAbstractTest.php new file mode 100644 index 000000000..f97a494bc --- /dev/null +++ b/tests/Message/RequestAbstractTest.php @@ -0,0 +1,95 @@ +request = new class() extends RequestAbstract + { + public function getOrigin() : string + { + return ''; + } + + public function getBody(bool $optimize = false) : string + { + return ''; + } + }; + } + + /** + * @testdox Request data can be set and returned + * @covers phpOMS\Message\RequestAbstract + * @group framework + */ + public function testDataInputOutput() : void + { + self::assertTrue($this->request->setData('key', 'value')); + self::assertEquals('value', $this->request->getData('key')); + self::assertTrue($this->request->hasData('key')); + self::assertEquals(['key' => 'value'], $this->request->getData()); + } + + /** + * @testdox A invalid data key returns null + * @covers phpOMS\Message\RequestAbstract + * @group framework + */ + public function testInvalidDataKeyOutput() : void + { + self::assertEquals(null, $this->request->getData('invalid')); + } + + /** + * @testdox Request data can be set and returned with correct types + * @covers phpOMS\Message\RequestAbstract + * @group framework + */ + public function testDataTypeInputOutput() : void + { + $this->request->setData('key1', 1); + self::assertEquals('1', $this->request->getData('key1', 'string')); + + $this->request->setData('key2', '2'); + self::assertEquals(2, $this->request->getData('key2', 'int')); + + $this->request->setData('key3', '1'); + self::assertEquals(true, $this->request->getData('key3', 'bool')); + + $this->request->setData('key4', '1.23'); + self::assertEquals(1.23, $this->request->getData('key4', 'float')); + + $this->request->setData('key5', 1); + self::assertEquals(1, $this->request->getData('key5', 'invalid')); + } +} diff --git a/tests/Router/SocketRouterTest.php b/tests/Router/SocketRouterTest.php index e7a70dc0d..d2d5ae230 100644 --- a/tests/Router/SocketRouterTest.php +++ b/tests/Router/SocketRouterTest.php @@ -83,6 +83,22 @@ class SocketRouterTest extends \PHPUnit\Framework\TestCase ); } + /** + * @testdox The routes can be removed from the router + * @covers phpOMS\Router\SocketRouter + * @group framework + */ + public function testRouteClearing() : void + { + self::assertTrue($this->router->importFromFile(__DIR__ . '/socketRouterTestFile.php')); + $this->router->clear(); + + self::assertEquals( + [], + $this->router->route('backend_admin -settings=general -t 123') + ); + } + /** * @testdox Routes can be added dynamically * @covers phpOMS\Router\SocketRouter diff --git a/tests/Router/WebRouterTest.php b/tests/Router/WebRouterTest.php index 272aabf3f..317a0add9 100644 --- a/tests/Router/WebRouterTest.php +++ b/tests/Router/WebRouterTest.php @@ -95,6 +95,26 @@ class WebRouterTest extends \PHPUnit\Framework\TestCase ); } + /** + * @testdox The routes can be removed from the router + * @covers phpOMS\Router\WebRouter + * @group framework + */ + public function testRouteClearing() : void + { + self::assertTrue($this->router->importFromFile(__DIR__ . '/webRouterTestFile.php')); + $this->router->clear(); + + self::assertEquals( + [], + $this->router->route( + (new HttpRequest( + new HttpUri('http://test.com/backend/admin/settings/general/something?test') + ))->uri->getRoute() + ) + ); + } + /** * @testdox Invalid routing verbs don't match even if the route matches * @covers phpOMS\Router\WebRouter diff --git a/tests/Stdlib/Base/LocationTest.php b/tests/Stdlib/Base/LocationTest.php index 75b009ebd..deaea99d0 100644 --- a/tests/Stdlib/Base/LocationTest.php +++ b/tests/Stdlib/Base/LocationTest.php @@ -217,4 +217,27 @@ class LocationTest extends \PHPUnit\Framework\TestCase self::assertEquals($expected, $this->location->jsonSerialize()); self::assertEquals(\json_encode($this->location->jsonSerialize()), $this->location->serialize()); } + + /** + * @testdox The location can unserialized + * @covers phpOMS\Stdlib\Base\Location + * @group framework + */ + public function testUnserialize() : void + { + $expected = [ + 'postal' => '0123456789', + 'city' => 'city', + 'country' => 'Country', + 'address' => 'Some address here', + 'state' => 'This is a state 123', + 'geo' => [ + 'lat' => 12.1, + 'long' => 11.2, + ], + ]; + + $this->location->unserialize(\json_encode($expected)); + self::assertEquals(\json_encode($expected), $this->location->serialize()); + } } diff --git a/tests/System/MimeTypeTest.php b/tests/System/MimeTypeTest.php index 4997fee27..88d89b19c 100644 --- a/tests/System/MimeTypeTest.php +++ b/tests/System/MimeTypeTest.php @@ -39,4 +39,22 @@ class MimeTypeTest extends \PHPUnit\Framework\TestCase self::assertTrue(true); } + + /** + * @covers phpOMS\System\MimeType + * @group framework + */ + public function testExtensionToMime() : void + { + self::assertEquals('application/pdf', MimeType::extensionToMime('pdf')); + } + + /** + * @covers phpOMS\System\MimeType + * @group framework + */ + public function testInvalidExtensionToMime() : void + { + self::assertEquals('application/octet-stream', MimeType::extensionToMime('INVALID')); + } } diff --git a/tests/Uri/HttpUriTest.php b/tests/Uri/HttpUriTest.php index ce907c520..47183acc3 100644 --- a/tests/Uri/HttpUriTest.php +++ b/tests/Uri/HttpUriTest.php @@ -202,6 +202,20 @@ class HttpUriTest extends \PHPUnit\Framework\TestCase self::assertEquals('new', $obj->getPath()); } + /** + * @covers phpOMS\Uri\HttpUri + * @group framework + */ + public function testPathElementInputOutput() : void + { + $obj = new HttpUri('https://www.google.com/test/second/path.php?para1=abc¶2=2#frag'); + + self::assertEquals(['test', 'second', 'path'], $obj->getPathElements()); + + $obj->setPath('new/test'); + self::assertEquals(['new', 'test'], $obj->getPathElements()); + } + /** * @testdox The path offset can be set and returned * @covers phpOMS\Uri\HttpUri diff --git a/tests/Utils/IO/Zip/TarTest.php b/tests/Utils/IO/Zip/TarTest.php index 97a083951..671b0bc3e 100644 --- a/tests/Utils/IO/Zip/TarTest.php +++ b/tests/Utils/IO/Zip/TarTest.php @@ -82,6 +82,27 @@ class TarTest extends \PHPUnit\Framework\TestCase self::assertEquals($e, \file_get_contents(__DIR__ . '/test/sub/test e.txt')); \unlink(__DIR__ . '/test.tar'); + + /* @todo: fix this, this is not working "cannot open test.tar" + // second test + self::assertTrue(Tar::pack( + [__DIR__ . '/test' => 'test'], + __DIR__ . '/test.tar' + )); + + self::assertTrue(Tar::unpack(__DIR__ . '/test.tar', __DIR__ . '/new_dir')); + self::assertFileExists(__DIR__ . '/new_dir/test'); + self::assertEquals($c, \file_get_contents(__DIR__ . '/new_dir/test/test c.txt')); + + \unlink(__DIR__ . '/new_dir/test/test c.txt'); + \unlink(__DIR__ . '/new_dir/test/test d.txt'); + \unlink(__DIR__ . '/new_dir/test/sub/test e.txt'); + \rmdir(__DIR__ . '/new_dir/test/sub'); + \rmdir(__DIR__ . '/new_dir/test'); + \rmdir(__DIR__ . '/new_dir'); + + \unlink(__DIR__ . '/test.tar'); + */ } /** diff --git a/tests/Utils/IO/Zip/ZipTest.php b/tests/Utils/IO/Zip/ZipTest.php index 0be7b8fac..8d247f03e 100644 --- a/tests/Utils/IO/Zip/ZipTest.php +++ b/tests/Utils/IO/Zip/ZipTest.php @@ -83,6 +83,25 @@ class ZipTest extends \PHPUnit\Framework\TestCase self::assertEquals($e, \file_get_contents(__DIR__ . '/test/sub/test e.txt')); \unlink(__DIR__ . '/test.zip'); + + // second test + self::assertTrue(Zip::pack( + __DIR__ . '/test', + __DIR__ . '/test.zip' + )); + + self::assertTrue(Zip::unpack(__DIR__ . '/test.zip', __DIR__ . '/new_dir')); + self::assertFileExists(__DIR__ . '/new_dir/test'); + self::assertEquals($c, \file_get_contents(__DIR__ . '/new_dir/test/test c.txt')); + + \unlink(__DIR__ . '/new_dir/test/test c.txt'); + \unlink(__DIR__ . '/new_dir/test/test d.txt'); + \unlink(__DIR__ . '/new_dir/test/sub/test e.txt'); + \rmdir(__DIR__ . '/new_dir/test/sub'); + \rmdir(__DIR__ . '/new_dir/test'); + \rmdir(__DIR__ . '/new_dir'); + + \unlink(__DIR__ . '/test.zip'); } /** diff --git a/tests/Utils/StringUtilsTest.php b/tests/Utils/StringUtilsTest.php index 0fa6206be..85ed3cdd9 100644 --- a/tests/Utils/StringUtilsTest.php +++ b/tests/Utils/StringUtilsTest.php @@ -228,4 +228,16 @@ class StringUtilsTest extends \PHPUnit\Framework\TestCase StringUtils::createDiffMarkup($original, $new) ); } + + /** + * @testdox A string can be validated for shell safety + * @covers phpOMS\Utils\StringUtils + * @group framework + */ + public function testIsShellSafe() : void + { + self::assertTrue(StringUtils::isShellSafe('asdf')); + self::assertFalse(StringUtils::isShellSafe('&#;`|*?~<>^()[]{}$\\')); + self::assertFalse(StringUtils::isShellSafe('™')); + } } diff --git a/tests/Views/ViewTest.php b/tests/Views/ViewTest.php index bcb88d821..78c782d1d 100644 --- a/tests/Views/ViewTest.php +++ b/tests/Views/ViewTest.php @@ -389,6 +389,19 @@ class ViewTest extends \PHPUnit\Framework\TestCase self::assertEquals('Test', $view->render()); } + /** + * @testdox A view template can be build + * @covers phpOMS\Views\View + * @group framework + */ + public function testBuild() : void + { + $view = new View(); + + $view->setTemplate('/phpOMS/tests/Views/testTemplate'); + self::assertEquals('Test', $view->build()); + } + /** * @testdox A view template can be serialized * @covers phpOMS\Views\View @@ -440,6 +453,19 @@ class ViewTest extends \PHPUnit\Framework\TestCase self::assertEquals('', $view->render()); } + /** + * @testdox Building a invalid template throws a PathException + * @covers phpOMS\Views\View + * @group framework + */ + public function testBuildException() : void + { + $view = new View($this->app->l11nManager); + $view->setTemplate('something.txt'); + + self::assertEquals('', $view->build()); + } + /** * @testdox Serializing a invalid template throws a PathException * @covers phpOMS\Views\View