Updated LegacyMiddleware to use Translator class
This commit is contained in:
parent
acfe72cb91
commit
3a11641647
|
@ -83,9 +83,12 @@ class LegacyMiddleware implements MiddlewareInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($title) and empty($content)) {
|
if (empty($title) and empty($content)) {
|
||||||
|
/** @var Translator $translator */
|
||||||
|
$translator = $this->container->get('translator');
|
||||||
|
|
||||||
$page = 404;
|
$page = 404;
|
||||||
$title = _('Page not found');
|
$title = $translator->translate('Page not found');
|
||||||
$content = _('This page could not be found or you don\'t have permission to view it. You probably have to sign in or register in order to gain access!');
|
$content = $translator->translate('This page could not be found or you don\'t have permission to view it. You probably have to sign in or register in order to gain access!');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->renderPage($page, $title, $content);
|
return $this->renderPage($page, $title, $content);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Engelsystem\Test\Unit\Middleware;
|
namespace Engelsystem\Test\Unit\Middleware;
|
||||||
|
|
||||||
|
use Engelsystem\Helpers\Translator;
|
||||||
use Engelsystem\Http\Request;
|
use Engelsystem\Http\Request;
|
||||||
use Engelsystem\Middleware\LegacyMiddleware;
|
use Engelsystem\Middleware\LegacyMiddleware;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
@ -37,6 +38,10 @@ class LegacyMiddlewareTest extends TestCase
|
||||||
$handler = $this->getMockForAbstractClass(RequestHandlerInterface::class);
|
$handler = $this->getMockForAbstractClass(RequestHandlerInterface::class);
|
||||||
/** @var ServerRequestInterface|MockObject $request */
|
/** @var ServerRequestInterface|MockObject $request */
|
||||||
$request = $this->getMockForAbstractClass(ServerRequestInterface::class);
|
$request = $this->getMockForAbstractClass(ServerRequestInterface::class);
|
||||||
|
/** @var Translator|MockObject $translator */
|
||||||
|
$translator = $this->getMockBuilder(Translator::class)
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
$middleware->expects($this->exactly(2))
|
$middleware->expects($this->exactly(2))
|
||||||
->method('loadPage')
|
->method('loadPage')
|
||||||
|
@ -50,15 +55,27 @@ class LegacyMiddlewareTest extends TestCase
|
||||||
->method('renderPage')
|
->method('renderPage')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
['user_worklog', 'title', 'content'],
|
['user_worklog', 'title', 'content'],
|
||||||
['404', 'Page not found'],
|
['404', 'Page not found', 'It\'s not available!'],
|
||||||
['login', 'title2', 'content2']
|
['login', 'title2', 'content2']
|
||||||
)
|
)
|
||||||
->willReturn($response);
|
->willReturn($response);
|
||||||
|
|
||||||
$container->expects($this->atLeastOnce())
|
$container->expects($this->exactly(4))
|
||||||
->method('get')
|
->method('get')
|
||||||
->with('request')
|
->withConsecutive(['request'], ['request'], ['translator'], ['request'])
|
||||||
->willReturn($defaultRequest);
|
->willReturnOnConsecutiveCalls(
|
||||||
|
$defaultRequest,
|
||||||
|
$defaultRequest,
|
||||||
|
$translator,
|
||||||
|
$defaultRequest
|
||||||
|
);
|
||||||
|
|
||||||
|
$translator->expects($this->exactly(2))
|
||||||
|
->method('translate')
|
||||||
|
->willReturnOnConsecutiveCalls(
|
||||||
|
'Page not found',
|
||||||
|
'It\'s not available!'
|
||||||
|
);
|
||||||
|
|
||||||
$defaultRequest->query = $parameters;
|
$defaultRequest->query = $parameters;
|
||||||
$defaultRequest->expects($this->once())
|
$defaultRequest->expects($this->once())
|
||||||
|
|
Loading…
Reference in New Issue