Merge pull request #636 from marc1706/ticket/634
[ticket/634] Increase test coverage
This commit is contained in:
@@ -465,6 +465,8 @@ function get_user_groups()
|
|||||||
|
|
||||||
if ($groups_ary === false)
|
if ($groups_ary === false)
|
||||||
{
|
{
|
||||||
|
$groups_ary = array();
|
||||||
|
|
||||||
// get user's groups
|
// get user's groups
|
||||||
$sql = 'SELECT group_id
|
$sql = 'SELECT group_id
|
||||||
FROM ' . USER_GROUP_TABLE . '
|
FROM ' . USER_GROUP_TABLE . '
|
||||||
|
|||||||
@@ -437,12 +437,12 @@ class calendar extends module_base
|
|||||||
trigger_error($this->user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
|
trigger_error($this->user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
$event_title = $this->request->variable('event_title', ' ', true);
|
$event_title = $this->request->variable('event_title', '', true);
|
||||||
$event_desc = $this->request->variable('event_desc', ' ', true);
|
$event_desc = $this->request->variable('event_desc', '', true);
|
||||||
$event_start_date = trim($this->request->variable('event_start_date', ''));
|
$event_start_date = trim($this->request->variable('event_start_date', ''));
|
||||||
$event_end_date = trim($this->request->variable('event_end_date', ''));
|
$event_end_date = trim($this->request->variable('event_end_date', ''));
|
||||||
$event_all_day = $this->request->variable('event_all_day', false); // default to false
|
$event_all_day = $this->request->variable('event_all_day', false); // default to false
|
||||||
$event_url = $this->request->variable('event_url', ' ');
|
$event_url = $this->request->variable('event_url', '');
|
||||||
$event_permission = $this->request->variable('permission-setting-calendar', array(0 => ''));
|
$event_permission = $this->request->variable('permission-setting-calendar', array(0 => ''));
|
||||||
$groups_ary = array();
|
$groups_ary = array();
|
||||||
|
|
||||||
@@ -488,11 +488,6 @@ class calendar extends module_base
|
|||||||
trigger_error($this->user->lang['NO_EVENT_TITLE'] . adm_back_link($u_action), E_USER_WARNING);
|
trigger_error($this->user->lang['NO_EVENT_TITLE'] . adm_back_link($u_action), E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$start_time || $start_time == 0)
|
|
||||||
{
|
|
||||||
trigger_error($this->user->lang['NO_EVENT_START'] . adm_back_link($u_action), E_USER_WARNING);
|
|
||||||
}
|
|
||||||
|
|
||||||
// overwrite already existing events and make sure we don't try to save an event outside of the normal array size of $events
|
// overwrite already existing events and make sure we don't try to save an event outside of the normal array size of $events
|
||||||
if (isset($link_id) && $link_id < sizeof($events))
|
if (isset($link_id) && $link_id < sizeof($events))
|
||||||
{
|
{
|
||||||
|
|||||||
20
tests/mock/check_form_key.php
Normal file
20
tests/mock/check_form_key.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) Board3 Group ( www.board3.de )
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace board3\portal\modules;
|
||||||
|
|
||||||
|
abstract class check_form_key
|
||||||
|
{
|
||||||
|
static public $form_key_valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_form_key($value)
|
||||||
|
{
|
||||||
|
return check_form_key::$form_key_valid;
|
||||||
|
}
|
||||||
@@ -68,12 +68,12 @@ class listener_test extends \phpbb_template_template_test_case
|
|||||||
|
|
||||||
$this->config = new \phpbb\config\config(array(
|
$this->config = new \phpbb\config\config(array(
|
||||||
'enable_mod_rewrite' => '1',
|
'enable_mod_rewrite' => '1',
|
||||||
'board3_portal_enable' => '1',
|
'board3_enable' => '1',
|
||||||
));
|
));
|
||||||
$provider = new \phpbb\controller\provider();
|
$provider = new \phpbb\controller\provider();
|
||||||
$provider->find_routing_files($finder);
|
$provider->find_routing_files($finder);
|
||||||
$provider->find(dirname(__FILE__) . '/');
|
$provider->find(dirname(__FILE__) . '/');
|
||||||
$this->controller_helper = new \phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, new \phpbb\symfony_request($request), $request, new \phpbb\filesystem(), '', 'php', dirname(__FILE__) . '/');
|
$this->controller_helper = new mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, new \phpbb\symfony_request($request), $request, new \phpbb\filesystem(), '', 'php', dirname(__FILE__) . '/');
|
||||||
|
|
||||||
$this->path_helper = new \phpbb\path_helper(
|
$this->path_helper = new \phpbb\path_helper(
|
||||||
new \phpbb\symfony_request(
|
new \phpbb\symfony_request(
|
||||||
@@ -85,14 +85,13 @@ class listener_test extends \phpbb_template_template_test_case
|
|||||||
$this->php_ext
|
$this->php_ext
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->auth = new \phpbb\auth\auth();
|
$this->auth = $this->getMockBuilder('\phpbb\auth\auth')
|
||||||
$userdata = array(
|
->disableOriginalConstructor()
|
||||||
'user_id' => 2,
|
->getMock();
|
||||||
);
|
$this->auth->expects($this->any())
|
||||||
$this->auth->acl($userdata);
|
->method('acl_get')
|
||||||
// Pretend to allow downloads
|
->with($this->anything())
|
||||||
$this->auth->acl_options['global']['u_view_portal'] = 0;
|
->will($this->returnValue(true));
|
||||||
$this->auth->acl[0][0] = true;
|
|
||||||
|
|
||||||
$this->controller = $this->getMockBuilder('\board3\portal\controller\main')
|
$this->controller = $this->getMockBuilder('\board3\portal\controller\main')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
@@ -160,14 +159,30 @@ class listener_test extends \phpbb_template_template_test_case
|
|||||||
|
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
|
|
||||||
$this->user->data['session_page'] = '/app.php/portal';
|
$this->controller_helper->set_current_url('/app.php/portal');
|
||||||
$result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars));
|
$result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars));
|
||||||
|
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
|
|
||||||
// Make sure user shouldn't see link
|
// Make sure user shouldn't see link
|
||||||
unset($this->auth->cache[0]['u_view_portal']);
|
$this->config->set('board3_enable', 0);
|
||||||
$this->auth->acl[0][0] = false;
|
$this->controller_helper->set_current_url('');
|
||||||
|
$result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars));
|
||||||
|
|
||||||
|
$this->assertEmpty($result);
|
||||||
|
$this->config->set('board3_enable', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_check_portal_all()
|
||||||
|
{
|
||||||
|
$this->phpbb_dispatcher->addListener('core.page_header', array($this->listener, 'add_portal_link'));
|
||||||
|
|
||||||
|
$this->controller_helper->set_current_url('');
|
||||||
|
$result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars));
|
||||||
|
|
||||||
|
$this->assertEmpty($result);
|
||||||
|
|
||||||
|
$this->config->set('board3_show_all_pages', true);
|
||||||
$result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars));
|
$result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars));
|
||||||
|
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
@@ -196,3 +211,18 @@ class listener_test extends \phpbb_template_template_test_case
|
|||||||
)), $result['lang_set_ext']);
|
)), $result['lang_set_ext']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class mock_controller_helper extends \phpbb_mock_controller_helper
|
||||||
|
{
|
||||||
|
protected $current_url = '';
|
||||||
|
|
||||||
|
public function set_current_url($url)
|
||||||
|
{
|
||||||
|
$this->current_url = $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_current_url()
|
||||||
|
{
|
||||||
|
return $this->current_url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,15 +9,26 @@
|
|||||||
|
|
||||||
namespace board3\portal\modules;
|
namespace board3\portal\modules;
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/../../mock/check_form_key.php';
|
||||||
|
|
||||||
class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframework\database_test_case
|
class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframework\database_test_case
|
||||||
{
|
{
|
||||||
protected $path_helper;
|
protected $path_helper;
|
||||||
protected $calendar;
|
|
||||||
static $config;
|
static $config;
|
||||||
|
|
||||||
protected $expected_config = array();
|
protected $expected_config = array();
|
||||||
protected $expected_portal_config = array();
|
protected $expected_portal_config = array();
|
||||||
|
|
||||||
|
/** @var \board3\portal\modules\calendar */
|
||||||
|
protected $calendar;
|
||||||
|
|
||||||
|
/** @var \phpbb\request\request_interface */
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
/** @var \board3\portal\tests\mock\template */
|
||||||
|
protected $template;
|
||||||
|
|
||||||
public function getDataSet()
|
public function getDataSet()
|
||||||
{
|
{
|
||||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/configs.xml');
|
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/configs.xml');
|
||||||
@@ -26,7 +37,7 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
global $cache, $phpbb_root_path, $phpEx;
|
global $cache, $phpbb_root_path, $phpEx, $phpbb_dispatcher, $request, $user;
|
||||||
|
|
||||||
$this->path_helper = new \phpbb\path_helper(
|
$this->path_helper = new \phpbb\path_helper(
|
||||||
new \phpbb\symfony_request(
|
new \phpbb\symfony_request(
|
||||||
@@ -37,11 +48,33 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
|
|||||||
$phpbb_root_path,
|
$phpbb_root_path,
|
||||||
'php'
|
'php'
|
||||||
);
|
);
|
||||||
|
$db = $this->new_dbal();
|
||||||
|
$phpbb_dispatcher = $this->getMockBuilder('\phpbb\event\dispatcher')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$phpbb_dispatcher->expects($this->any())
|
||||||
|
->method('trigger_event')
|
||||||
|
->with($this->anything())
|
||||||
|
->will($this->returnArgument(1));
|
||||||
self::$config = new \phpbb\config\config(array());
|
self::$config = new \phpbb\config\config(array());
|
||||||
|
\set_config('foobar', false, false, self::$config);
|
||||||
|
$this->template = new \board3\portal\tests\mock\template($this);
|
||||||
$controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx);
|
$controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx);
|
||||||
$controller_helper->add_route('board3_portal_controller', 'portal');
|
$controller_helper->add_route('board3_portal_controller', 'portal');
|
||||||
$modules_helper = new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), new \phpbb\config\config(array()), $controller_helper, new \phpbb_mock_request());
|
$modules_helper = new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), new \phpbb\config\config(array()), $controller_helper, new \phpbb_mock_request());
|
||||||
$this->calendar = new \board3\portal\modules\calendar(self::$config, $modules_helper, null, null, null, dirname(__FILE__) . '/../../../', 'php', null, $this->path_helper, null);
|
$request = $this->request = new \phpbb_mock_request();
|
||||||
|
$user = new \phpbb\user('\phpbb\datetime');
|
||||||
|
$user->timezone = new \DateTimeZone('UTC');
|
||||||
|
$user->add_lang('common');
|
||||||
|
$log = $this->getMockBuilder('\phpbb\log')
|
||||||
|
->setMethods(array('add'))
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$log->expects($this->any())
|
||||||
|
->method('add')
|
||||||
|
->with($this->anything())
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$this->calendar = new \board3\portal\modules\calendar(self::$config, $modules_helper, $this->template, $db, $this->request, dirname(__FILE__) . '/../../../', 'php', $user, $this->path_helper, $log);
|
||||||
define('PORTAL_MODULES_TABLE', 'phpbb_portal_modules');
|
define('PORTAL_MODULES_TABLE', 'phpbb_portal_modules');
|
||||||
define('PORTAL_CONFIG_TABLE', 'phpbb_portal_config');
|
define('PORTAL_CONFIG_TABLE', 'phpbb_portal_config');
|
||||||
$cache = $this->getMock('\phpbb\cache\cache', array('destroy', 'sql_exists', 'get', 'put'));
|
$cache = $this->getMock('\phpbb\cache\cache', array('destroy', 'sql_exists', 'get', 'put'));
|
||||||
@@ -114,6 +147,213 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
|
|||||||
$this->assertFalse(isset($portal_config[$key]));
|
$this->assertFalse(isset($portal_config[$key]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_get_template_side()
|
||||||
|
{
|
||||||
|
set_portal_config('board3_calendar_events_5', '[{"title":"foobar","desc":" ","start_time":' . (time() - 3600) . ',"end_time":"","all_day":true,"permission":"","url":" "},{"title":"foobar","desc":" ","start_time":' . (time() + 90000) . ',"end_time":"","all_day":true,"permission":"","url":" "}]');
|
||||||
|
$this->assertSame('calendar_side.html', $this->calendar->get_template_side(5));
|
||||||
|
|
||||||
|
self::$config->set('board3_sunday_first_5', true);
|
||||||
|
$this->request->overwrite('m5', 1);
|
||||||
|
$this->assertSame('calendar_side.html', $this->calendar->get_template_side(5));
|
||||||
|
|
||||||
|
$this->request->overwrite('m5', -1);
|
||||||
|
$this->assertSame('calendar_side.html', $this->calendar->get_template_side(5));
|
||||||
|
|
||||||
|
self::$config->set('board3_display_events_5', true);
|
||||||
|
$this->assertSame('calendar_side.html', $this->calendar->get_template_side(5));
|
||||||
|
$this->assertSame(1, sizeof($this->template->get_row('minical.cur_events')));
|
||||||
|
$this->assertSame(1, sizeof($this->template->get_row('minical.upcoming_events')));
|
||||||
|
|
||||||
|
set_portal_config('board3_calendar_events_5', '[{"title":"foobar","desc":" ","start_time":' . (time() - 10800) . ',"end_time":"","all_day":true,"permission":"","url":"http://example.com"},{"title":"foobar","desc":" ","start_time":' . (time() + 108000) . ',"end_time":"","all_day":true,"permission":"","url":"' . generate_board_url() . '"},{"title":"foobar3","desc":" ","start_time":' . (time() - 90000) . ',"end_time":' . (time() + 90000) . ',"all_day":false,"permission":"","url":" "}]');
|
||||||
|
$this->template->delete_var('minical.cur_events');
|
||||||
|
$this->template->delete_var('minical.upcoming_events');
|
||||||
|
$this->assertSame('calendar_side.html', $this->calendar->get_template_side(5));
|
||||||
|
$this->assertSame(2, sizeof($this->template->get_row('minical.cur_events')));
|
||||||
|
$this->assertSame(1, sizeof($this->template->get_row('minical.upcoming_events')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_template_acp()
|
||||||
|
{
|
||||||
|
$acp_template = $this->calendar->get_template_acp(5);
|
||||||
|
$this->assertArrayHasKey('title', $acp_template);
|
||||||
|
$this->assertArrayHasKey('vars', $acp_template);
|
||||||
|
$this->assertArrayHasKey('board3_display_events_5', $acp_template['vars']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_update_events_no_error()
|
||||||
|
{
|
||||||
|
$this->calendar->update_events('foobar', 5);
|
||||||
|
$this->assertNull($this->template->get_row('events'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function data_update_events()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'event_start_date' => date('d.m.Y G:i', time() + 3600 * 3),
|
||||||
|
'event_all_day' => true,
|
||||||
|
'event_title' => 'foobar',
|
||||||
|
'id' => 0,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'save' => true,
|
||||||
|
),
|
||||||
|
E_USER_NOTICE,
|
||||||
|
'<br /><br /><a href="index.php?i=-board3-portal-acp-portal_module&mode=config&module_id=5">« Back to previous page</a>',
|
||||||
|
'[{"title":"foobar","desc":" ","start_time":' . (time() + 3600) . ',"end_time":"","all_day":true,"permission":"","url":" "}]',
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
// Form key invalid
|
||||||
|
array(
|
||||||
|
array(),
|
||||||
|
array(
|
||||||
|
'save' => true,
|
||||||
|
),
|
||||||
|
E_USER_WARNING,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
// Wrong start time
|
||||||
|
array(
|
||||||
|
array(),
|
||||||
|
array(
|
||||||
|
'save' => true,
|
||||||
|
),
|
||||||
|
E_USER_WARNING,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
// Wrong end time
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'event_start_date' => '15.06.2035 13:00',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'save' => true,
|
||||||
|
),
|
||||||
|
E_USER_WARNING,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
// End time in past
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'event_start_date' => '15.06.2035 13:00',
|
||||||
|
'event_end_date' => '15.06.2005 19:00',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'save' => true,
|
||||||
|
),
|
||||||
|
E_USER_WARNING,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
// End time before start
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'event_start_date' => '15.06.2035 13:00',
|
||||||
|
'event_end_date' => '15.06.2035 12:00',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'save' => true,
|
||||||
|
),
|
||||||
|
E_USER_WARNING,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
// No event title
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'event_start_date' => date('d.m.Y G:i', time() + 3600 * 3),
|
||||||
|
'event_all_day' => true,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'save' => true,
|
||||||
|
),
|
||||||
|
E_USER_WARNING,
|
||||||
|
'',
|
||||||
|
'[{"title":"foobar","desc":" ","start_time":' . (time() + 3600) . ',"end_time":"","all_day":true,"permission":"","url":" "}]',
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
// Create valid event
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'event_start_date' => date('d.m.Y G:i', time() + 3600 * 3),
|
||||||
|
'event_all_day' => true,
|
||||||
|
'event_title' => 'foobar',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'save' => true,
|
||||||
|
),
|
||||||
|
E_USER_NOTICE,
|
||||||
|
'<br /><br /><a href="index.php?i=-board3-portal-acp-portal_module&mode=config&module_id=5">« Back to previous page</a>',
|
||||||
|
'[{"title":"foobar","desc":" ","start_time":' . (time() + 3600) . ',"end_time":"","all_day":true,"permission":"","url":" "}]',
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
// Display existing events
|
||||||
|
array(
|
||||||
|
array(),
|
||||||
|
array(),
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
'board3_calendar_events_5' => '[{"title":"foobar","desc":" ","start_time":2065518000,"end_time":"","all_day":true,"permission":"","url":" "}]',
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
// Edit event
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'id' => 0,
|
||||||
|
'action' => 'edit',
|
||||||
|
),
|
||||||
|
array(),
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
'[{"title":"foobar","desc":" ","start_time":' . (time() + 3600) . ',"end_time":"","all_day":true,"permission":"","url":" "}]',
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data_update_events
|
||||||
|
*/
|
||||||
|
public function test_update_events($get_variables, $post_variables, $expected_error = E_USER_WARNING, $expected_error_message = '', $portal_config = array(), $form_key_valid = false)
|
||||||
|
{
|
||||||
|
check_form_key::$form_key_valid = $form_key_valid;
|
||||||
|
|
||||||
|
foreach ($get_variables as $key => $value)
|
||||||
|
{
|
||||||
|
$this->request->overwrite($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($post_variables as $key => $value)
|
||||||
|
{
|
||||||
|
$this->request->overwrite($key, $value, \phpbb\request\request_interface::POST);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_portal_config('board3_calendar_events_5', $portal_config);
|
||||||
|
|
||||||
|
if ($expected_error !== false)
|
||||||
|
{
|
||||||
|
if (!empty($expected_error_message))
|
||||||
|
{
|
||||||
|
$this->setExpectedTriggerError($expected_error, $expected_error_message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->setExpectedTriggerError($expected_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->calendar->update_events('foobar', 5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_config($config_name, $config_value, $is_dynamic = false)
|
function set_config($config_name, $config_value, $is_dynamic = false)
|
||||||
|
|||||||
57
tests/unit/modules/clock_test.php
Normal file
57
tests/unit/modules/clock_test.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) Board3 Group ( www.board3.de )
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace board3\portal\modules;
|
||||||
|
|
||||||
|
class phpbb_unit_modules_clock_test extends \board3\portal\tests\testframework\test_case
|
||||||
|
{
|
||||||
|
/** @var \board3\portal\tests\mock\template */
|
||||||
|
protected $template;
|
||||||
|
|
||||||
|
/** @var \board3\portal\modules\clock */
|
||||||
|
protected $clock;
|
||||||
|
|
||||||
|
/** @var \phpbb\config\config */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->template = new \board3\portal\tests\mock\template($this);
|
||||||
|
$this->config = new \phpbb\config\config(array());
|
||||||
|
$this->clock = new \board3\portal\modules\clock($this->config, $this->template);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_template_side()
|
||||||
|
{
|
||||||
|
$this->assertSame('clock_side.html', $this->clock->get_template_side(5));
|
||||||
|
$this->template->assert_same(null, 'B3P_CLOCK_SRC');
|
||||||
|
$this->config->set('board3_clock_src_5', 'foobar');
|
||||||
|
$this->assertSame('clock_side.html', $this->clock->get_template_side(5));
|
||||||
|
$this->template->assert_same('foobar', 'B3P_CLOCK_SRC');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_template_acp()
|
||||||
|
{
|
||||||
|
$acp_template = $this->clock->get_template_acp(5);
|
||||||
|
$this->assertNotEmpty($acp_template);
|
||||||
|
$this->assertArrayHasKey('board3_clock_src_5', $acp_template['vars']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_install_uninstall()
|
||||||
|
{
|
||||||
|
$this->config->delete('board3_clock_src_5');
|
||||||
|
$this->assertTrue($this->clock->install(5));
|
||||||
|
$this->assertTrue(isset($this->config['board3_clock_src_5']));
|
||||||
|
$this->assertSame('', $this->config['board3_clock_src_5']);
|
||||||
|
$this->assertTrue($this->clock->uninstall(5, ''));
|
||||||
|
$this->assertFalse(isset($this->config['board3_clock_src_5']));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,4 +8,14 @@
|
|||||||
<column>config_name</column>
|
<column>config_name</column>
|
||||||
<column>config_value</column>
|
<column>config_value</column>
|
||||||
</table>
|
</table>
|
||||||
|
<table name="phpbb_groups">
|
||||||
|
<column>group_id</column>
|
||||||
|
<column>group_name</column>
|
||||||
|
<column>group_desc</column>
|
||||||
|
<row>
|
||||||
|
<value>5</value>
|
||||||
|
<value>admins</value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
</table>
|
||||||
</dataset>
|
</dataset>
|
||||||
|
|||||||
39
tests/unit/modules/search_test.php
Normal file
39
tests/unit/modules/search_test.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) Board3 Group ( www.board3.de )
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace board3\portal\modules;
|
||||||
|
|
||||||
|
class phpbb_unit_modules_search_test extends \board3\portal\tests\testframework\test_case
|
||||||
|
{
|
||||||
|
/** @var \board3\portal\tests\mock\template */
|
||||||
|
protected $template;
|
||||||
|
|
||||||
|
/** @var \board3\portal\modules\search */
|
||||||
|
protected $search;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->template = new \board3\portal\tests\mock\template($this);
|
||||||
|
$this->search = new \board3\portal\modules\search($this->template, '', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_template_side()
|
||||||
|
{
|
||||||
|
$this->assertSame('search_side.html', $this->search->get_template_side(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_template_acp()
|
||||||
|
{
|
||||||
|
$acp_template = $this->search->get_template_acp(5);
|
||||||
|
$this->assertNotEmpty($acp_template);
|
||||||
|
$this->assertEmpty($acp_template['vars']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
namespace board3\portal\modules;
|
namespace board3\portal\modules;
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/../../mock/check_form_key.php';
|
||||||
|
|
||||||
class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework\database_test_case
|
class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework\database_test_case
|
||||||
{
|
{
|
||||||
protected $path_helper;
|
protected $path_helper;
|
||||||
@@ -28,8 +30,6 @@ class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework
|
|||||||
protected $expected_config = array();
|
protected $expected_config = array();
|
||||||
protected $expected_portal_config = array();
|
protected $expected_portal_config = array();
|
||||||
|
|
||||||
static public $form_key_valid = false;
|
|
||||||
|
|
||||||
public function getDataSet()
|
public function getDataSet()
|
||||||
{
|
{
|
||||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/configs.xml');
|
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/configs.xml');
|
||||||
@@ -74,6 +74,7 @@ class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework
|
|||||||
$this->welcome = new \board3\portal\modules\welcome($this->config, $this->request, $this->template, $this->user, $phpbb_root_path, $phpEx);
|
$this->welcome = new \board3\portal\modules\welcome($this->config, $this->request, $this->template, $this->user, $phpbb_root_path, $phpEx);
|
||||||
\set_config('foobar', 0, false, $this->config);
|
\set_config('foobar', 0, false, $this->config);
|
||||||
$this->config->delete('foobar');
|
$this->config->delete('foobar');
|
||||||
|
check_form_key::$form_key_valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_get_template_center()
|
public function test_get_template_center()
|
||||||
@@ -143,10 +144,10 @@ class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework
|
|||||||
$this->request = new \phpbb_mock_request();
|
$this->request = new \phpbb_mock_request();
|
||||||
$this->welcome = new \board3\portal\modules\welcome($this->config, $this->request, $this->template, $this->user, '', '');
|
$this->welcome = new \board3\portal\modules\welcome($this->config, $this->request, $this->template, $this->user, '', '');
|
||||||
$this->request->overwrite('submit', true, \phpbb\request\request_interface::POST);
|
$this->request->overwrite('submit', true, \phpbb\request\request_interface::POST);
|
||||||
self::$form_key_valid = true;
|
check_form_key::$form_key_valid = true;
|
||||||
$this->request->overwrite('welcome_message', 'foobar101');
|
$this->request->overwrite('welcome_message', 'foobar101');
|
||||||
$this->welcome->update_welcome('foobar', 5);
|
$this->welcome->update_welcome('foobar', 5);
|
||||||
self::$form_key_valid = false;
|
check_form_key::$form_key_valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_update_welcome_invalid_form_key()
|
public function test_update_welcome_invalid_form_key()
|
||||||
@@ -166,11 +167,7 @@ class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework
|
|||||||
$this->request->overwrite('submit', true, \phpbb\request\request_interface::POST);
|
$this->request->overwrite('submit', true, \phpbb\request\request_interface::POST);
|
||||||
$this->request->overwrite('welcome_message', '');
|
$this->request->overwrite('welcome_message', '');
|
||||||
$this->setExpectedTriggerError(E_USER_WARNING);
|
$this->setExpectedTriggerError(E_USER_WARNING);
|
||||||
|
check_form_key::$form_key_valid = true;
|
||||||
$this->welcome->update_welcome('foobar', 5);
|
$this->welcome->update_welcome('foobar', 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_form_key($value)
|
|
||||||
{
|
|
||||||
return phpbb_unit_modules_welcome_test::$form_key_valid;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user