[ticket/207] Add links to portal in header and footer
Also added tests for listener.
This commit is contained in:
@@ -78,3 +78,13 @@ services:
|
|||||||
- @dbal.conn
|
- @dbal.conn
|
||||||
- @board3.portal.modules_helper
|
- @board3.portal.modules_helper
|
||||||
- @user
|
- @user
|
||||||
|
|
||||||
|
board3.portal.listener:
|
||||||
|
class: board3\portal\event\listener
|
||||||
|
arguments:
|
||||||
|
- @controller.helper
|
||||||
|
- @template
|
||||||
|
- @user
|
||||||
|
- %core.php_ext%
|
||||||
|
tags:
|
||||||
|
- { name: event.listener }
|
||||||
|
|||||||
101
event/listener.php
Normal file
101
event/listener.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package Board3 Portal v2.1
|
||||||
|
* @copyright (c) 2014 Board3 Group ( www.board3.de )
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace board3\portal\event;
|
||||||
|
|
||||||
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
|
||||||
|
class listener implements EventSubscriberInterface
|
||||||
|
{
|
||||||
|
/** @var \phpbb\controller\helper */
|
||||||
|
protected $controller_helper;
|
||||||
|
|
||||||
|
/** @var \phpbb\template\template */
|
||||||
|
protected $template;
|
||||||
|
|
||||||
|
/** @var \phpbb\user */
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
/** @var string phpEx */
|
||||||
|
protected $php_ext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor of Board3 Portal event listener
|
||||||
|
*
|
||||||
|
* @param \phpbb\controller\helper $controller_helper Controller helper object
|
||||||
|
* @param \phpbb\template\template $template Template object
|
||||||
|
* @param \phpbb\user $user User object
|
||||||
|
* @param string $php_ext phpEx
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\controller\helper $controller_helper, \phpbb\template\template $template, \phpbb\user $user, $php_ext)
|
||||||
|
{
|
||||||
|
$this->controller_helper = $controller_helper;
|
||||||
|
$this->template = $template;
|
||||||
|
$this->user = $user;
|
||||||
|
$this->php_ext = $php_ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign functions defined in this class to event listeners in the core
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
static public function getSubscribedEvents()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'core.user_setup' => 'load_portal_language',
|
||||||
|
'core.viewonline_overwrite_location' => 'viewonline_page',
|
||||||
|
'core.page_header' => 'add_portal_link',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load portal language during user setup
|
||||||
|
*
|
||||||
|
* @param object $event The event object
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public function load_portal_language($event)
|
||||||
|
{
|
||||||
|
$lang_set_ext = $event['lang_set_ext'];
|
||||||
|
$lang_set_ext[] = array(
|
||||||
|
'ext_name' => 'board3/portal',
|
||||||
|
'lang_set' => 'portal',
|
||||||
|
);
|
||||||
|
$event['lang_set_ext'] = $lang_set_ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show users as viewing the portals on Who Is Online page
|
||||||
|
*
|
||||||
|
* @param object $event The event object
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public function viewonline_page($event)
|
||||||
|
{
|
||||||
|
if ($event['on_page'][1] == 'app' && strrpos($event['row']['session_page'], 'app.' . $this->php_ext . '/portal') === 0)
|
||||||
|
{
|
||||||
|
$event['location'] = $this->user->lang('VIEWING_PORTAL');
|
||||||
|
$event['location_url'] = $this->controller_helper->route('board3_controller');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add portal link
|
||||||
|
*
|
||||||
|
* @param object $event The event object
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public function add_portal_link($event)
|
||||||
|
{
|
||||||
|
$this->template->assign_vars(array(
|
||||||
|
'U_PORTAL' => $this->controller_helper->route('board3_controller'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<span class="crumb"><a href="{U_PORTAL}" data-navbar-reference="portal">{L_PORTAL}</a></span>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<span class="crumb"><a href="{U_PORTAL}" data-navbar-reference="portal">{L_PORTAL}</a></span>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<a href="{U_PORTAL}" data-navbar-reference="portal">{L_PORTAL}</a> »
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<a href="{U_PORTAL}" data-navbar-reference="portal">{L_PORTAL}</a> »
|
||||||
3
tests/unit/event/config/routing.yml
Normal file
3
tests/unit/event/config/routing.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
board3_controller:
|
||||||
|
pattern: /portal
|
||||||
|
defaults: { _controller: board3.portal.main:handle }
|
||||||
135
tests/unit/event/listener_test.php
Normal file
135
tests/unit/event/listener_test.php
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package Quickedit
|
||||||
|
* @copyright (c) 2014 Marc Alexander ( www.m-a-styles.de )
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace board3\portal\tests\event;
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/../../../../../../../tests/template/template_test_case.php';
|
||||||
|
|
||||||
|
class listener_test extends \phpbb_template_template_test_case
|
||||||
|
{
|
||||||
|
/** @var \board3\portal\event\listener */
|
||||||
|
protected $listener;
|
||||||
|
|
||||||
|
static public $hidden_fields = array();
|
||||||
|
|
||||||
|
public function setup()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->setup_listener();
|
||||||
|
|
||||||
|
global $phpbb_dispatcher;
|
||||||
|
|
||||||
|
$phpbb_dispatcher = new \phpbb\event\dispatcher(new \phpbb_mock_container_builder());
|
||||||
|
$this->phpbb_dispatcher = $phpbb_dispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup_listener()
|
||||||
|
{
|
||||||
|
$this->user = $this->getMock('\phpbb\user');
|
||||||
|
$this->user->expects($this->any())
|
||||||
|
->method('lang')
|
||||||
|
->will($this->returnValue('foo'));
|
||||||
|
|
||||||
|
$manager = new \phpbb_mock_extension_manager(dirname(__FILE__) . '/', array());
|
||||||
|
$finder = new \phpbb\finder(
|
||||||
|
new \phpbb\filesystem(),
|
||||||
|
dirname(__FILE__) . '/',
|
||||||
|
new \phpbb_mock_cache()
|
||||||
|
);
|
||||||
|
$finder->set_extensions(array_keys($manager->all_enabled()));
|
||||||
|
|
||||||
|
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
|
||||||
|
$provider = new \phpbb\controller\provider();
|
||||||
|
$provider->find_routing_files($finder);
|
||||||
|
$provider->find(dirname(__FILE__) . '/');
|
||||||
|
$this->controller_helper = new \phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, '', 'php', dirname(__FILE__) . '/');
|
||||||
|
|
||||||
|
$this->listener = new \board3\portal\event\listener(
|
||||||
|
$this->controller_helper,
|
||||||
|
$this->template,
|
||||||
|
$this->user,
|
||||||
|
'php'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_construct()
|
||||||
|
{
|
||||||
|
$this->setup_listener();
|
||||||
|
$this->assertInstanceOf('\Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_getSubscribedEvents()
|
||||||
|
{
|
||||||
|
$this->assertEquals(array(
|
||||||
|
'core.user_setup',
|
||||||
|
'core.viewonline_overwrite_location',
|
||||||
|
'core.page_header',
|
||||||
|
), array_keys(\board3\portal\event\listener::getSubscribedEvents()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_viewonline_page()
|
||||||
|
{
|
||||||
|
$this->phpbb_dispatcher->addListener('core.viewonline_overwrite_location', array($this->listener, 'viewonline_page'));
|
||||||
|
$on_page = array(
|
||||||
|
'foobar',
|
||||||
|
'app',
|
||||||
|
);
|
||||||
|
$row = array(
|
||||||
|
'session_page' => 'app.php/portal',
|
||||||
|
);
|
||||||
|
$location = 'foo';
|
||||||
|
$location_url = 'bar.php';
|
||||||
|
|
||||||
|
$vars = array(
|
||||||
|
'on_page',
|
||||||
|
'row',
|
||||||
|
'location',
|
||||||
|
'location_url',
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $this->phpbb_dispatcher->trigger_event('core.viewonline_overwrite_location', compact($vars));
|
||||||
|
|
||||||
|
$this->assertEquals('foo', $location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_add_portal_link()
|
||||||
|
{
|
||||||
|
$this->phpbb_dispatcher->addListener('core.page_header', array($this->listener, 'add_portal_link'));
|
||||||
|
|
||||||
|
$vars = array();
|
||||||
|
|
||||||
|
$result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars));
|
||||||
|
|
||||||
|
$this->assertEmpty($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_load_portal_language()
|
||||||
|
{
|
||||||
|
$this->phpbb_dispatcher->addListener('core.user_setup', array($this->listener, 'load_portal_language'));
|
||||||
|
|
||||||
|
$lang_set_ext = array(array(
|
||||||
|
'ext_name' => 'foo/bar',
|
||||||
|
'lang_set' => 'bar',
|
||||||
|
));
|
||||||
|
$vars = array('lang_set_ext');
|
||||||
|
|
||||||
|
$result = $this->phpbb_dispatcher->trigger_event('core.user_setup', compact($vars));
|
||||||
|
|
||||||
|
$this->assertEquals(array(
|
||||||
|
array(
|
||||||
|
'ext_name' => 'foo/bar',
|
||||||
|
'lang_set' => 'bar',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'ext_name' => 'board3/portal',
|
||||||
|
'lang_set' => 'portal',
|
||||||
|
)), $result['lang_set_ext']);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user