diff --git a/tests/mock/template.php b/tests/mock/template.php index 36fc4caa..30e7bb5a 100644 --- a/tests/mock/template.php +++ b/tests/mock/template.php @@ -29,10 +29,15 @@ class template $this->data[$row] = array(); } + $index = (sizeof($this->data[$row])) ? sizeof($this->data[$row]) : 0; foreach ($values as $key => $column) { $this->test_case->assertArrayNotHasKey($key, $this->data[$row]); - $this->data[$row][$key] = $column; + if (!isset($this->data[$row][$index])) + { + $this->data[$row][$index] = array(); + } + $this->data[$row][$index][$key] = $column; } } @@ -63,4 +68,9 @@ class template { unset($this->data[$key]); } + + public function get_row($row) + { + return $this->data[$row]; + } } diff --git a/tests/unit/acp/move_module_test.php b/tests/unit/acp/move_module_test.php index 125b1977..6c1d8537 100644 --- a/tests/unit/acp/move_module_test.php +++ b/tests/unit/acp/move_module_test.php @@ -9,9 +9,6 @@ namespace board3\portal\portal\modules; -require_once(dirname(__FILE__) . '/../../../includes/functions.php'); -require_once(dirname(__FILE__) . '/../../../acp/portal_module.php'); - class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\database_test_case { static public $redirected = false; @@ -31,12 +28,26 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data /** @var \board3\portal\includes\helper */ protected $portal_helper; + /** @var \board3\portal\acp\portal_module */ + protected $portal_module; + + /** @var \board3\portal\tests\mock\template */ + protected $template; + + /** @var \phpbb_mock_request */ + protected $request; + public function setUp() { parent::setUp(); global $db, $cache, $phpbb_root_path, $phpEx, $user, $phpbb_container, $request, $template, $table_prefix; + global $phpbb_dispatcher; + $user = new \board3\portal\tests\mock\user(); + $template = new \board3\portal\tests\mock\template($this); + $this->template = $template; $request = new \phpbb_mock_request; + $this->request = $request; $phpbb_container = new \phpbb_mock_container_builder(); // Mock module service collection $config = new \phpbb\config\config(array()); @@ -91,6 +102,11 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data )); $this->database_handler = new \board3\portal\portal\modules\database_handler($db); $this->constraints_handler = new \board3\portal\portal\modules\constraints_handler($this->portal_columns, $user); + $phpbb_dispatcher = $this->getMock('\phpbb\event\dispatcher', array('trigger_event'), array($phpbb_container)); + $phpbb_dispatcher->expects($this->any()) + ->method('trigger_event') + ->with($this->anything()) + ->will($this->returnArgument(1)); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( @@ -377,6 +393,32 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data { $this->assertSame($expected, $this->constraints_handler->can_add_module($this->portal_helper->get_module($module_class), $column)); } + + public function test_main_wrong_mode() + { + $this->setExpectedTriggerError(E_USER_ERROR, 'NO_MODE'); + $this->portal_module->main(5, 'foobar'); + } + + public function test_main_config() + { + $this->portal_module->main(5, 'config'); + $this->template->assert_equals(array(), 'options'); + $options = $this->template->get_row('options'); + $this->assertNotEmpty($this->template->get_row('options')); + $this->assertEquals(true, in_array('board3_show_all_pages', $options[9])); + } + + public function test_main_invalid_submit() + { + $this->request->overwrite('submit', true, \phpbb\request\request_interface::POST); + $this->portal_module->main(5, 'config'); + $this->template->assert_equals(array(), 'options'); + $options = $this->template->get_row('options'); + $this->assertNotEmpty($this->template->get_row('options')); + $this->assertEquals(true, in_array('board3_show_all_pages', $options[9])); + $this->template->assert_same(true, 'S_ERROR'); + } } function redirect($url) diff --git a/tests/unit/acp/portal_module_test.php b/tests/unit/acp/portal_module_test.php new file mode 100644 index 00000000..89fa8b87 --- /dev/null +++ b/tests/unit/acp/portal_module_test.php @@ -0,0 +1,23 @@ +module(); + $this->assertArrayHasKey('filename', $module_info); + $this->assertSame('\board3\portal\acp\portal_module', $module_info['filename']); + } +} \ No newline at end of file diff --git a/tests/unit/functions/check_file_src_test.php b/tests/unit/functions/check_file_src_test.php index 7fb7014f..1e63bef2 100644 --- a/tests/unit/functions/check_file_src_test.php +++ b/tests/unit/functions/check_file_src_test.php @@ -7,7 +7,6 @@ * */ -require_once(dirname(__FILE__) . '/../../../includes/functions.php'); require_once(dirname(__FILE__) . '/../../../../../../includes/functions_acp.php'); require_once(dirname(__FILE__) . '/../../../../../../includes/functions.php'); diff --git a/tests/unit/functions/fetch_news_test.php b/tests/unit/functions/fetch_news_test.php index 434a267b..aed5ebdd 100644 --- a/tests/unit/functions/fetch_news_test.php +++ b/tests/unit/functions/fetch_news_test.php @@ -7,7 +7,6 @@ * */ -require_once(dirname(__FILE__) . '/../../../includes/functions.php'); require_once(dirname(__FILE__) . '/../../../../../../includes/functions_acp.php'); require_once(dirname(__FILE__) . '/../../../../../../includes/functions.php'); require_once(dirname(__FILE__) . '/../../../../../../includes/utf/utf_tools.php'); diff --git a/tests/unit/functions/functions_test.php b/tests/unit/functions/functions_test.php index c95ca4d2..7fdf7f16 100644 --- a/tests/unit/functions/functions_test.php +++ b/tests/unit/functions/functions_test.php @@ -7,7 +7,6 @@ * */ -require_once(dirname(__FILE__) . '/../../../includes/functions.php'); require_once(dirname(__FILE__) . '/../../../../../../includes/utf/utf_tools.php'); require_once(dirname(__FILE__) . '/../../../../../../includes/functions_content.php'); diff --git a/tests/unit/functions/get_user_groups_test.php b/tests/unit/functions/get_user_groups_test.php index c5ea4a20..62763d1f 100644 --- a/tests/unit/functions/get_user_groups_test.php +++ b/tests/unit/functions/get_user_groups_test.php @@ -7,8 +7,6 @@ * */ -require_once(dirname(__FILE__) . '/../../../includes/functions.php'); - class phpbb_unit_functions_get_user_groups_test extends \board3\portal\tests\testframework\database_test_case { public function getDataSet() diff --git a/tests/unit/functions/simple_test.php b/tests/unit/functions/simple_test.php index 0349b055..58906d41 100644 --- a/tests/unit/functions/simple_test.php +++ b/tests/unit/functions/simple_test.php @@ -7,8 +7,6 @@ * */ -require_once(dirname(__FILE__) . '/../../../includes/functions.php'); - class phpbb_functions_simple_test extends PHPUnit_Framework_TestCase { public function test_ap_validate() diff --git a/tests/unit/modules/calendar_test.php b/tests/unit/modules/calendar_test.php index 86cce026..d8e855c6 100644 --- a/tests/unit/modules/calendar_test.php +++ b/tests/unit/modules/calendar_test.php @@ -9,8 +9,6 @@ namespace board3\portal\modules; -require_once(dirname(__FILE__) . '/../../../includes/functions.php'); - class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframework\database_test_case { protected $path_helper; diff --git a/tests/unit/portal/fetch_posts_test.php b/tests/unit/portal/fetch_posts_test.php index ef04a258..557b77c5 100644 --- a/tests/unit/portal/fetch_posts_test.php +++ b/tests/unit/portal/fetch_posts_test.php @@ -7,7 +7,6 @@ * */ -require_once(dirname(__FILE__) . '/../../../includes/functions.php'); require_once(dirname(__FILE__) . '/../../../../../../includes/functions_acp.php'); require_once(dirname(__FILE__) . '/../../../../../../includes/functions.php'); require_once(dirname(__FILE__) . '/../../../../../../includes/utf/utf_tools.php');