From 1e7dc9b576f84308b4a04e52972270a03773875c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 13 Feb 2015 22:23:23 +0100 Subject: [PATCH] [ticket/469] Add tests for displaying all pages using main controller B3P-469 --- tests/mock/template.php | 15 +++++ tests/mock/user.php | 5 ++ tests/unit/controller/main_test.php | 94 +++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 tests/unit/controller/main_test.php diff --git a/tests/mock/template.php b/tests/mock/template.php index 539de39f..8806962f 100644 --- a/tests/mock/template.php +++ b/tests/mock/template.php @@ -36,6 +36,16 @@ class template } } + public function assign_vars($vars) + { + $this->data = array_merge($this->data, $vars); + } + + public function assign_var($key, $var) + { + $this->data[$key] = $var; + } + public function assert_equals($data, $row) { foreach ($data as $key => $value) @@ -43,4 +53,9 @@ class template $this->test_case->assertEquals($value, $this->data[$row][$key]); } } + + public function assert_same($expected, $row) + { + $this->test_case->assertSame($expected, $this->data[$row]); + } } diff --git a/tests/mock/user.php b/tests/mock/user.php index eb603e89..b0ca4c45 100644 --- a/tests/mock/user.php +++ b/tests/mock/user.php @@ -53,4 +53,9 @@ class user extends \PHPUnit_Framework_TestCase $this->markTestIncomplete('Unable to include language file ' . $file); } } + + public function lang($var) + { + return $this->lang[$var]; + } } diff --git a/tests/unit/controller/main_test.php b/tests/unit/controller/main_test.php new file mode 100644 index 00000000..6eb1109f --- /dev/null +++ b/tests/unit/controller/main_test.php @@ -0,0 +1,94 @@ +createXMLDataSet(dirname(__FILE__) . '/../acp/fixtures/modules.xml'); + } + + public function setUp() + { + global $phpbb_root_path, $phpEx, $table_prefix, $cache; + + parent::setUp(); + + $path_helper = new \phpbb\path_helper( + new \phpbb\symfony_request( + new \phpbb_mock_request() + ), + new \phpbb\filesystem(), + new \phpbb_mock_request(), + $phpbb_root_path, + $phpEx + ); + + $cache = new \phpbb\cache\driver\null(); + + $user = new \board3\portal\tests\mock\user(); + + $config_table = $table_prefix . 'portal_config'; + $modules_table = $table_prefix . 'portal_modules'; + $this->template = new \board3\portal\tests\mock\template($this); + $portal_columns = new \board3\portal\portal\columns(); + $this->config = new \phpbb\config\config(array('board3_enable' => true)); + $modules = array( + '\board3\portal\modules\clock' => new \board3\portal\modules\clock($this->config, $this->template), + ); + $portal_helper = new \board3\portal\includes\helper($modules); + $auth = $this->getMock('\phpbb\auth\auth', array('acl_get')); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->anything()) + ->will($this->returnValue(true)); + + $controller_helper = new \board3\portal\controller\helper( + $auth, + $portal_columns, + $this->config, + $this->template, + $user, + $path_helper, + $portal_helper, + $phpbb_root_path, + '.' . $phpEx + ); + + $this->controller_main = new \board3\portal\controller\main( + $portal_columns, + $this->config, + $controller_helper, + $this->template, + $user, + $path_helper, + $phpbb_root_path, + '.' . $phpEx, + $config_table, + $modules_table + ); + } + + public function test_display_all_pages() + { + $this->assertNull($this->controller_main->handle(array('left' => 1))); + $this->template->assert_same(true, 'S_PORTAL_ALL'); + } +}