Merge branch 'twig-templates'
commit
66038eda14
@ -1,14 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use FastRoute\RouteCollector;
|
use FastRoute\RouteCollector;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
|
|
||||||
/** @var RouteCollector $route */
|
/** @var RouteCollector $route */
|
||||||
|
|
||||||
/** Demo route endpoint, TODO: Remove */
|
$route->get('/credits', 'CreditsController@index');
|
||||||
$route->addRoute('GET', '/hello/{name}', function ($request) {
|
|
||||||
/** @var ServerRequestInterface $request */
|
|
||||||
$name = $request->getAttribute('name');
|
|
||||||
|
|
||||||
return response(sprintf('Hello %s!', htmlspecialchars($name)));
|
|
||||||
});
|
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function credits_title()
|
|
||||||
{
|
|
||||||
return __('Credits');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function guest_credits()
|
|
||||||
{
|
|
||||||
return view(__DIR__ . '/../../resources/views/pages/credits.html');
|
|
||||||
}
|
|
@ -0,0 +1,36 @@
|
|||||||
|
<div class="col-md-12">
|
||||||
|
<hr/>
|
||||||
|
<div class="text-center footer" style="margin-bottom: 10px;">
|
||||||
|
{% block eventinfo %}
|
||||||
|
{% if event_config.event_name %}
|
||||||
|
{% if event_config.event_start_date and event_config.event_end_date %}
|
||||||
|
{{ __('%s, from %s to %s', [
|
||||||
|
event_config.event_name,
|
||||||
|
date(event_config.event_start_date).format(__('Y-m-d')),
|
||||||
|
date(event_config.event_end_date).format(__('Y-m-d'))
|
||||||
|
]) }}
|
||||||
|
{% elseif event_config.event_start_date %}
|
||||||
|
{{ __('%s, starting %s', [
|
||||||
|
event_config.event_name,
|
||||||
|
date(event_config.event_start_date).format(__('Y-m-d'))
|
||||||
|
]) }}
|
||||||
|
{% else %}
|
||||||
|
{{ event_config.event_name }}
|
||||||
|
{% endif %} <br>
|
||||||
|
{% elseif event_config.event_start_date and event_config.event_end_date %}
|
||||||
|
{{ __('Event from %s to %s', [
|
||||||
|
date(event_config.event_start_date).format(__('Y-m-d')),
|
||||||
|
date(event_config.event_end_date).format(__('Y-m-d'))
|
||||||
|
]) }} <br>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
<a href="{{ config('faq_url') }}">{{ __('FAQ') }}</a>
|
||||||
|
· <a href="{{ config('contact_email') }}">
|
||||||
|
<span class="glyphicon glyphicon-envelope"></span> {{ __('Contact') }}
|
||||||
|
</a>
|
||||||
|
· <a href="https://github.com/engelsystem/engelsystem/issues">{{ __('Bugs / Features') }}</a>
|
||||||
|
· <a href="https://github.com/engelsystem/engelsystem/">{{ __('Development Platform') }}</a>
|
||||||
|
· <a href="{{ url('credits') }}">{{ __('Credits') }}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -0,0 +1,74 @@
|
|||||||
|
{% import _self as elements %}
|
||||||
|
|
||||||
|
{% macro toolbar_item(label, link, active_page, icon) %}
|
||||||
|
<li{% if page() == active_page %} class="active"{% endif %}>
|
||||||
|
<a href="{{ link }}">
|
||||||
|
{% if icon %}<span class="glyphicon {{ icon }}"></span>{% endif %}
|
||||||
|
{{ label|raw }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
<div class="navbar navbar-default navbar-fixed-top">
|
||||||
|
<div class="container-fluid">
|
||||||
|
{% block navbar %}
|
||||||
|
<div class="navbar-header">
|
||||||
|
<button type="button" class="navbar-toggle collapsed"
|
||||||
|
data-toggle="collapse" data-target="#navbar-collapse-1">
|
||||||
|
<span class="sr-only">Toggle navigation</span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
</button>
|
||||||
|
<a class="navbar-brand" href="{{ url('/') }}">
|
||||||
|
<span class="icon-icon_angel"></span> <strong class="visible-lg-inline">ENGELSYSTEM</strong>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% block menu %}
|
||||||
|
<div class="collapse navbar-collapse" id="navbar-collapse-1">
|
||||||
|
{% block menu_items %}
|
||||||
|
{{ menu() }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block menu_toolbar %}
|
||||||
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
|
||||||
|
{% if is_user() %}
|
||||||
|
{{ elements.toolbar_item(menuUserShiftState(user), url('shifts', {'action': 'next'}), '', 'glyphicon-time') }}
|
||||||
|
{% elseif has_permission_to('register') and config('registration_enabled') %}
|
||||||
|
{{ elements.toolbar_item(__('Register'), url('register'), 'register', 'glyphicon-plus') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if has_permission_to('login') %}
|
||||||
|
{{ elements.toolbar_item(__('Login'), url('login'), 'login', 'glyphicon-log-in') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if is_user() and has_permission_to('user_messages') %}
|
||||||
|
{{ elements.toolbar_item(menuUserMessages(), url('user-messages'), 'user-messages', 'glyphicon-envelope') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{{ menuUserHints() }}
|
||||||
|
|
||||||
|
{% if has_permission_to('user_myshifts') %}
|
||||||
|
{{ elements.toolbar_item(user.Nick, url('users', {'action': 'view'}), 'users', 'icon-icon_angel') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if has_permission_to('user_settings') or has_permission_to('logout') %}
|
||||||
|
<li class="dropdown">
|
||||||
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
|
<span class="caret"></span>
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu" role="menu">
|
||||||
|
{{ menuUserSubmenu()|join(" ")|raw }}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -1,36 +0,0 @@
|
|||||||
<div class="container">
|
|
||||||
<h1>Credits</h1>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<h2>Source code</h2>
|
|
||||||
<p>
|
|
||||||
The original system was written by <a href="https://github.com/cookieBerlin/engelsystem">cookie</a>.
|
|
||||||
It was then completely rewritten and enhanced by
|
|
||||||
<a href="https://notrademark.de">msquare</a> (maintainer),
|
|
||||||
<a href="https://myigel.name">MyIgel</a>,
|
|
||||||
<a href="https://mortzu.de">mortzu</a>,
|
|
||||||
<a href="https://jplitza.de">jplitza</a> and
|
|
||||||
<a href="https://github.com/gnomus">gnomus</a>.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Please look at the <a href="https://github.com/engelsystem/engelsystem/graphs/contributors">
|
|
||||||
contributor list on github</a> for a more complete version.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-4">
|
|
||||||
<h2>Hosting</h2>
|
|
||||||
<p>
|
|
||||||
Webspace, development platform and domain on <a href="https://engelsystem.de">engelsystem.de</a>
|
|
||||||
is currently provided by <a href="https://www.wybt.net/">would you buy this?</a> (ichdasich)
|
|
||||||
and adminstrated by <a href="https://mortzu.de">mortzu</a>,
|
|
||||||
<a href="http://derf.homelinux.org">derf</a> and ichdasich.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-4">
|
|
||||||
<h2>Translation</h2>
|
|
||||||
<p>
|
|
||||||
Many thanks for the german translation: <a href="http://e7p.de">e7p</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -0,0 +1,42 @@
|
|||||||
|
{% extends "layouts/app.twig" %}
|
||||||
|
|
||||||
|
{% block title %}{{ __('Credits') }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1>Credits</h1>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<h2>Source code</h2>
|
||||||
|
<p>
|
||||||
|
The original system was written by <a href="https://github.com/cookieBerlin/engelsystem">cookie</a>.
|
||||||
|
It was then completely rewritten and enhanced by
|
||||||
|
<a href="https://notrademark.de">msquare</a> (maintainer),
|
||||||
|
<a href="https://myigel.name">MyIgel</a>,
|
||||||
|
<a href="https://mortzu.de">mortzu</a>,
|
||||||
|
<a href="https://jplitza.de">jplitza</a> and
|
||||||
|
<a href="https://github.com/gnomus">gnomus</a>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Please look at the <a href="https://github.com/engelsystem/engelsystem/graphs/contributors">
|
||||||
|
contributor list on github</a> for a more complete version.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<h2>Hosting</h2>
|
||||||
|
<p>
|
||||||
|
Webspace, development platform and domain on <a href="https://engelsystem.de">engelsystem.de</a>
|
||||||
|
is currently provided by <a href="https://www.wybt.net/">would you buy this?</a> (ichdasich)
|
||||||
|
and adminstrated by <a href="https://mortzu.de">mortzu</a>,
|
||||||
|
<a href="http://derf.homelinux.org">derf</a> and ichdasich.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<h2>Translation</h2>
|
||||||
|
<p>
|
||||||
|
Many thanks for the german translation: <a href="http://e7p.de">e7p</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Controllers;
|
||||||
|
|
||||||
|
abstract class BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Controllers;
|
||||||
|
|
||||||
|
use Engelsystem\Http\Response;
|
||||||
|
|
||||||
|
class CreditsController extends BaseController
|
||||||
|
{
|
||||||
|
/** @var Response */
|
||||||
|
protected $response;
|
||||||
|
|
||||||
|
public function __construct(Response $response)
|
||||||
|
{
|
||||||
|
$this->response = $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return $this->response->withView('pages/credits.twig');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Renderer\Twig\Extensions;
|
||||||
|
|
||||||
|
use Twig_Extension as TwigExtension;
|
||||||
|
use Twig_Function as TwigFunction;
|
||||||
|
|
||||||
|
class Authentication extends TwigExtension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return TwigFunction[]
|
||||||
|
*/
|
||||||
|
public function getFunctions()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new TwigFunction('is_user', [$this, 'isAuthenticated']),
|
||||||
|
new TwigFunction('is_guest', [$this, 'isGuest']),
|
||||||
|
new TwigFunction('has_permission_to', [$this, 'checkAuth']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isAuthenticated()
|
||||||
|
{
|
||||||
|
global $user;
|
||||||
|
|
||||||
|
return !empty($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isGuest()
|
||||||
|
{
|
||||||
|
return !$this->isAuthenticated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkAuth($privilege)
|
||||||
|
{
|
||||||
|
global $privileges;
|
||||||
|
|
||||||
|
return in_array($privilege, $privileges);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Renderer\Twig\Extensions;
|
||||||
|
|
||||||
|
use Engelsystem\Http\Request;
|
||||||
|
use Twig_Extension as TwigExtension;
|
||||||
|
use Twig_Function as TwigFunction;
|
||||||
|
|
||||||
|
class Legacy extends TwigExtension
|
||||||
|
{
|
||||||
|
/** @var Request */
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
*/
|
||||||
|
public function __construct(Request $request)
|
||||||
|
{
|
||||||
|
$this->request = $request;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TwigFunction[]
|
||||||
|
*/
|
||||||
|
public function getFunctions()
|
||||||
|
{
|
||||||
|
$isSafeHtml = ['is_safe' => ['html']];
|
||||||
|
return [
|
||||||
|
new TwigFunction('menu', 'make_navigation', $isSafeHtml),
|
||||||
|
new TwigFunction('menuUserShiftState', 'User_shift_state_render', $isSafeHtml),
|
||||||
|
new TwigFunction('menuUserMessages', 'user_unread_messages', $isSafeHtml),
|
||||||
|
new TwigFunction('menuUserHints', 'header_render_hints', $isSafeHtml),
|
||||||
|
new TwigFunction('menuUserSubmenu', 'make_user_submenu', $isSafeHtml),
|
||||||
|
new TwigFunction('page', [$this, 'getPage']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPage()
|
||||||
|
{
|
||||||
|
if ($this->request->has('p')) {
|
||||||
|
return $this->request->get('p');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->request->path();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
<div class="col-md-12">
|
||||||
|
<hr/>
|
||||||
|
<div class="text-center footer" style="margin-bottom: 10px;">
|
||||||
|
{% block eventinfo %}
|
||||||
|
{% if event_config.event_name %}
|
||||||
|
{% if event_config.event_start_date and event_config.event_end_date %}
|
||||||
|
{{ __('%s, from %s to %s', [
|
||||||
|
event_config.event_name,
|
||||||
|
date(event_config.event_start_date).format(__('Y-m-d')),
|
||||||
|
date(event_config.event_end_date).format(__('Y-m-d'))
|
||||||
|
]) }}
|
||||||
|
{% elseif event_config.event_start_date %}
|
||||||
|
{{ __('%s, starting %s', [
|
||||||
|
event_config.event_name,
|
||||||
|
date(event_config.event_start_date).format(__('Y-m-d'))
|
||||||
|
]) }}
|
||||||
|
{% else %}
|
||||||
|
{{ event_config.event_name }}
|
||||||
|
{% endif %} <br>
|
||||||
|
{% elseif event_config.event_start_date and event_config.event_end_date %}
|
||||||
|
{{ __('Event from %s to %s', [
|
||||||
|
date(event_config.event_start_date).format(__('Y-m-d')),
|
||||||
|
date(event_config.event_end_date).format(__('Y-m-d'))
|
||||||
|
]) }} <br>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
<a href="{{ config('faq_url') }}">{{ __('FAQ') }}</a>
|
||||||
|
· <a href="{{ config('contact_email') }}">
|
||||||
|
<span class="glyphicon glyphicon-envelope"></span> {{ __('Contact') }}
|
||||||
|
</a>
|
||||||
|
· <a href="https://github.com/engelsystem/engelsystem/issues">{{ __('Bugs / Features') }}</a>
|
||||||
|
· <a href="https://github.com/engelsystem/engelsystem/">{{ __('Development Platform') }}</a>
|
||||||
|
· <a href="{{ url('credits') }}">{{ __('Credits') }}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -0,0 +1,74 @@
|
|||||||
|
{% import _self as elements %}
|
||||||
|
|
||||||
|
{% macro toolbar_item(label, link, active_page, icon) %}
|
||||||
|
<li{% if page() == active_page %} class="active"{% endif %}>
|
||||||
|
<a href="{{ link }}">
|
||||||
|
{% if icon %}<span class="glyphicon {{ icon }}"></span>{% endif %}
|
||||||
|
{{ label|raw }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
<div class="navbar navbar-default navbar-fixed-top">
|
||||||
|
<div class="container-fluid">
|
||||||
|
{% block navbar %}
|
||||||
|
<div class="navbar-header">
|
||||||
|
<button type="button" class="navbar-toggle collapsed"
|
||||||
|
data-toggle="collapse" data-target="#navbar-collapse-1">
|
||||||
|
<span class="sr-only">Toggle navigation</span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
</button>
|
||||||
|
<a class="navbar-brand" href="{{ url('/') }}">
|
||||||
|
<span class="icon-icon_angel"></span> <strong class="visible-lg-inline">ENGELSYSTEM</strong>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% block menu %}
|
||||||
|
<div class="collapse navbar-collapse" id="navbar-collapse-1">
|
||||||
|
{% block menu_items %}
|
||||||
|
{{ menu() }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block menu_toolbar %}
|
||||||
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
|
||||||
|
{% if is_user() %}
|
||||||
|
{{ elements.toolbar_item(menuUserShiftState(user), url('shifts', {'action': 'next'}), '', 'glyphicon-time') }}
|
||||||
|
{% elseif has_permission_to('register') and config('registration_enabled') %}
|
||||||
|
{{ elements.toolbar_item(__('Register'), url('register'), 'register', 'glyphicon-plus') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if has_permission_to('login') %}
|
||||||
|
{{ elements.toolbar_item(__('Login'), url('login'), 'login', 'glyphicon-log-in') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if is_user() and has_permission_to('user_messages') %}
|
||||||
|
{{ elements.toolbar_item(menuUserMessages(), url('user-messages'), 'user-messages', 'glyphicon-envelope') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{{ menuUserHints() }}
|
||||||
|
|
||||||
|
{% if has_permission_to('user_myshifts') %}
|
||||||
|
{{ elements.toolbar_item(user.Nick, url('users', {'action': 'view'}), 'users', 'icon-icon_angel') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if has_permission_to('user_settings') or has_permission_to('logout') %}
|
||||||
|
<li class="dropdown">
|
||||||
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
|
<span class="caret"></span>
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu" role="menu">
|
||||||
|
{{ menuUserSubmenu()|join(" ")|raw }}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Unit\Controllers;
|
||||||
|
|
||||||
|
use Engelsystem\Controllers\CreditsController;
|
||||||
|
use Engelsystem\Http\Response;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class CreditsControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Controllers\CreditsController::__construct
|
||||||
|
* @covers \Engelsystem\Controllers\CreditsController::index
|
||||||
|
*/
|
||||||
|
public function testIndex()
|
||||||
|
{
|
||||||
|
/** @var Response|MockObject $response */
|
||||||
|
$response = $this->createMock(Response::class);
|
||||||
|
|
||||||
|
$response->expects($this->once())
|
||||||
|
->method('withView')
|
||||||
|
->with('pages/credits.twig');
|
||||||
|
|
||||||
|
$controller = new CreditsController($response);
|
||||||
|
$controller->index();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
||||||
|
|
||||||
|
use Engelsystem\Renderer\Twig\Extensions\Authentication;
|
||||||
|
|
||||||
|
class AuthenticationTest extends ExtensionTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Authentication::getFunctions
|
||||||
|
*/
|
||||||
|
public function testGetFunctions()
|
||||||
|
{
|
||||||
|
$extension = new Authentication();
|
||||||
|
$functions = $extension->getFunctions();
|
||||||
|
|
||||||
|
$this->assertExtensionExists('is_user', [$extension, 'isAuthenticated'], $functions);
|
||||||
|
$this->assertExtensionExists('is_guest', [$extension, 'isGuest'], $functions);
|
||||||
|
$this->assertExtensionExists('has_permission_to', [$extension, 'checkAuth'], $functions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Authentication::isAuthenticated
|
||||||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Authentication::isGuest
|
||||||
|
*/
|
||||||
|
public function testIsAuthenticated()
|
||||||
|
{
|
||||||
|
global $user;
|
||||||
|
$user = [];
|
||||||
|
|
||||||
|
$extension = new Authentication();
|
||||||
|
|
||||||
|
$this->assertFalse($extension->isAuthenticated());
|
||||||
|
$this->assertTrue($extension->isGuest());
|
||||||
|
|
||||||
|
$user = ['lorem' => 'ipsum'];
|
||||||
|
$this->assertTrue($extension->isAuthenticated());
|
||||||
|
$this->assertFalse($extension->isGuest());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Authentication::checkAuth
|
||||||
|
*/
|
||||||
|
public function testCheckAuth()
|
||||||
|
{
|
||||||
|
global $privileges;
|
||||||
|
$privileges = [];
|
||||||
|
|
||||||
|
$extension = new Authentication();
|
||||||
|
|
||||||
|
$this->assertFalse($extension->checkAuth('foo.bar'));
|
||||||
|
|
||||||
|
$privileges = ['foo.bar'];
|
||||||
|
$this->assertTrue($extension->checkAuth('foo.bar'));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
||||||
|
|
||||||
|
use Engelsystem\Http\Request;
|
||||||
|
use Engelsystem\Renderer\Twig\Extensions\Legacy;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
|
class LegacyTest extends ExtensionTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Legacy::getFunctions
|
||||||
|
*/
|
||||||
|
public function testGetFunctions()
|
||||||
|
{
|
||||||
|
$isSafeHtml = ['is_safe' => ['html']];
|
||||||
|
/** @var Request|MockObject $request */
|
||||||
|
$request = $this->createMock(Request::class);
|
||||||
|
|
||||||
|
$extension = new Legacy($request);
|
||||||
|
$functions = $extension->getFunctions();
|
||||||
|
|
||||||
|
$this->assertExtensionExists('menu', 'make_navigation', $functions, $isSafeHtml);
|
||||||
|
$this->assertExtensionExists('menuUserShiftState', 'User_shift_state_render', $functions, $isSafeHtml);
|
||||||
|
$this->assertExtensionExists('menuUserMessages', 'user_unread_messages', $functions, $isSafeHtml);
|
||||||
|
$this->assertExtensionExists('menuUserHints', 'header_render_hints', $functions, $isSafeHtml);
|
||||||
|
$this->assertExtensionExists('menuUserSubmenu', 'make_user_submenu', $functions, $isSafeHtml);
|
||||||
|
$this->assertExtensionExists('page', [$extension, 'getPage'], $functions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Legacy::getPage
|
||||||
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Legacy::__construct
|
||||||
|
*/
|
||||||
|
public function testIsAuthenticated()
|
||||||
|
{
|
||||||
|
/** @var Request|MockObject $request */
|
||||||
|
$request = $this->createMock(Request::class);
|
||||||
|
|
||||||
|
$extension = new Legacy($request);
|
||||||
|
|
||||||
|
$request->expects($this->exactly(2))
|
||||||
|
->method('has')
|
||||||
|
->with('p')
|
||||||
|
->willReturnOnConsecutiveCalls(true, false);
|
||||||
|
|
||||||
|
$request->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('p')
|
||||||
|
->willReturn('foo-bar');
|
||||||
|
|
||||||
|
$request->expects($this->once())
|
||||||
|
->method('path')
|
||||||
|
->willReturn('batz');
|
||||||
|
|
||||||
|
$this->assertEquals('foo-bar', $extension->getPage());
|
||||||
|
$this->assertEquals('batz', $extension->getPage());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue