[ticket/634] Add tests for clock module and improve tests for calendar
B3P-634
This commit is contained in:
@@ -9,15 +9,26 @@
|
||||
|
||||
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
|
||||
{
|
||||
protected $path_helper;
|
||||
protected $calendar;
|
||||
|
||||
static $config;
|
||||
|
||||
protected $expected_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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
parent::setUp();
|
||||
global $cache, $phpbb_root_path, $phpEx;
|
||||
global $cache, $phpbb_root_path, $phpEx, $phpbb_dispatcher, $request;
|
||||
|
||||
$this->path_helper = new \phpbb\path_helper(
|
||||
new \phpbb\symfony_request(
|
||||
@@ -37,11 +48,32 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
|
||||
$phpbb_root_path,
|
||||
'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());
|
||||
$this->template = new \board3\portal\tests\mock\template($this);
|
||||
$controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx);
|
||||
$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());
|
||||
$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_CONFIG_TABLE', 'phpbb_portal_config');
|
||||
$cache = $this->getMock('\phpbb\cache\cache', array('destroy', 'sql_exists', 'get', 'put'));
|
||||
@@ -114,6 +146,68 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
|
||||
$this->assertFalse(isset($portal_config[$key]));
|
||||
}
|
||||
}
|
||||
|
||||
public function test_get_template_side()
|
||||
{
|
||||
$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));
|
||||
}
|
||||
|
||||
public function test_update_events_no_error()
|
||||
{
|
||||
$this->calendar->update_events('foobar', 5);
|
||||
}
|
||||
|
||||
public function test_update_events_form_key_fail()
|
||||
{
|
||||
// Save event
|
||||
check_form_key::$form_key_valid = false;
|
||||
$this->request->overwrite('save', true, \phpbb\request\request_interface::POST);
|
||||
$this->setExpectedTriggerError(E_USER_WARNING);
|
||||
$this->calendar->update_events('foobar', 5);
|
||||
}
|
||||
|
||||
public function test_update_events_wrong_start_time()
|
||||
{
|
||||
// Save event
|
||||
check_form_key::$form_key_valid = true;
|
||||
$this->request->overwrite('save', true, \phpbb\request\request_interface::POST);
|
||||
$this->setExpectedTriggerError(E_USER_WARNING);
|
||||
$this->calendar->update_events('foobar', 5);
|
||||
}
|
||||
|
||||
public function test_update_events_wrong_end_time()
|
||||
{
|
||||
// Save event
|
||||
check_form_key::$form_key_valid = true;
|
||||
$this->request->overwrite('event_start_date', '15.06.2035 13:00');
|
||||
$this->request->overwrite('save', true, \phpbb\request\request_interface::POST);
|
||||
$this->setExpectedTriggerError(E_USER_WARNING);
|
||||
$this->calendar->update_events('foobar', 5);
|
||||
}
|
||||
|
||||
public function test_update_events_all_day()
|
||||
{
|
||||
// Save event
|
||||
check_form_key::$form_key_valid = true;
|
||||
$this->request->overwrite('event_start_date', '15.06.2035 13:00');
|
||||
$this->request->overwrite('event_all_day', true);
|
||||
$this->request->overwrite('event_title', 'foobar');
|
||||
$this->request->overwrite('save', true, \phpbb\request\request_interface::POST);
|
||||
$this->setExpectedTriggerError(E_USER_NOTICE, '<br /><br /><a href="index.php?i=-board3-portal-acp-portal_module&mode=config&module_id=5">« </a>');
|
||||
$this->calendar->update_events('foobar', 5);
|
||||
}
|
||||
|
||||
public function test_display_events()
|
||||
{
|
||||
set_portal_config('board3_calendar_events_5', '[{"title":"foobar","desc":" ","start_time":2065518000,"end_time":"","all_day":true,"permission":"","url":" "}]');
|
||||
check_form_key::$form_key_valid = false;
|
||||
$this->calendar->manage_events('', 'foobar', 5);
|
||||
}
|
||||
}
|
||||
|
||||
function set_config($config_name, $config_value, $is_dynamic = false)
|
||||
|
||||
Reference in New Issue
Block a user