From e30f49a79164ca8e3242660bf1b7d8f50ac4f886 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 18 Nov 2018 20:04:12 +0100 Subject: [PATCH] Simplified error templates --- .../Extension/TranslatorExtension.php | 3 +- .../Extension/TranslatorExtensionTest.php | 7 ++- module/Core/templates/error/404.phtml | 18 +++--- module/Core/templates/error/error.phtml | 26 ++++----- module/Core/templates/layout/default.phtml | 57 ++++++++----------- 5 files changed, 50 insertions(+), 61 deletions(-) diff --git a/module/Common/src/Template/Extension/TranslatorExtension.php b/module/Common/src/Template/Extension/TranslatorExtension.php index 1779880a..f614ec1f 100644 --- a/module/Common/src/Template/Extension/TranslatorExtension.php +++ b/module/Common/src/Template/Extension/TranslatorExtension.php @@ -19,9 +19,8 @@ class TranslatorExtension implements ExtensionInterface $this->translator = $translator; } - public function register(Engine $engine) + public function register(Engine $engine): void { $engine->registerFunction('translate', [$this->translator, 'translate']); - $engine->registerFunction('translate_plural', [$this->translator, 'translatePlural']); } } diff --git a/module/Common/test/Template/Extension/TranslatorExtensionTest.php b/module/Common/test/Template/Extension/TranslatorExtensionTest.php index 6aa6a111..c33f43db 100644 --- a/module/Common/test/Template/Extension/TranslatorExtensionTest.php +++ b/module/Common/test/Template/Extension/TranslatorExtensionTest.php @@ -27,10 +27,11 @@ class TranslatorExtensionTest extends TestCase public function properFunctionsAreReturned() { $engine = $this->prophesize(Engine::class); + $registerFunction = $engine->registerFunction('translate', Argument::type('callable'))->will(function () { + }); - $engine->registerFunction('translate', Argument::type('callable'))->shouldBeCalledOnce(); - $engine->registerFunction('translate_plural', Argument::type('callable'))->shouldBeCalledOnce(); + $this->extension->register($engine->reveal()); - $funcs = $this->extension->register($engine->reveal()); + $registerFunction->shouldHaveBeenCalledOnce(); } } diff --git a/module/Core/templates/error/404.phtml b/module/Core/templates/error/404.phtml index 94f42c05..ca9d7dbf 100644 --- a/module/Core/templates/error/404.phtml +++ b/module/Core/templates/error/404.phtml @@ -1,19 +1,19 @@ layout('ShlinkCore::layout/default') ?> start('title') ?> - translate('URL Not Found') ?> + translate('URL Not Found') ?> end() ?> start('stylesheets') ?> - + end() ?> start('main') ?> -

404

-
-

translate('Page not found.') ?>

-

translate('The page you requested could not be found.') ?>

+

404

+
+

translate('Page not found.') ?>

+

translate('The page you requested could not be found.') ?>

end() ?> diff --git a/module/Core/templates/error/error.phtml b/module/Core/templates/error/error.phtml index 6d22ed9f..666f6ec3 100644 --- a/module/Core/templates/error/error.phtml +++ b/module/Core/templates/error/error.phtml @@ -1,25 +1,25 @@ layout('ShlinkCore::layout/default') ?> start('title') ?> - e($status . ' ' . $reason) ?> + e($status . ' ' . $reason) ?> end() ?> start('stylesheets') ?> - + end() ?> start('main') ?> -

translate('Oops!') ?>

-
+

translate('Oops!') ?>

+
- -

translate('We encountered a %s %s error.'), $status, $reason) ?>

- -

translate('This short URL doesn\'t seem to be valid.') ?>

-

translate('Make sure you included all the characters, with no extra punctuation.') ?>

- + +

translate('We encountered a %s %s error.'), $status, $reason) ?>

+ +

translate('This short URL doesn\'t seem to be valid.') ?>

+

translate('Make sure you included all the characters, with no extra punctuation.') ?>

+ end() ?> diff --git a/module/Core/templates/layout/default.phtml b/module/Core/templates/layout/default.phtml index 802bf466..431c1d73 100644 --- a/module/Core/templates/layout/default.phtml +++ b/module/Core/templates/layout/default.phtml @@ -1,42 +1,31 @@ - - - <?= $this->section('title', '') ?> | URL shortener - - - - - section('stylesheets', '') ?> + <?= $this->section('title', '') ?> | URL shortener + + + + + + section('stylesheets', '') ?> -
-
- section('main', '') ?> -
+
+
+ section('main', '') ?> +
+
+ +