From b6f6930eb56b9fd64f200a7b0e6d8cd28f0e73f6 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Thu, 29 Nov 2018 19:56:24 +0100 Subject: [ticket/15886] Group helper functions PHPBB3-15886 --- tests/group/helper_test_case.php | 123 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 tests/group/helper_test_case.php (limited to 'tests/group/helper_test_case.php') diff --git a/tests/group/helper_test_case.php b/tests/group/helper_test_case.php new file mode 100644 index 0000000000..1318cf9040 --- /dev/null +++ b/tests/group/helper_test_case.php @@ -0,0 +1,123 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +class phpbb_group_helper_test_case extends phpbb_test_case +{ + /** @var \phpbb\group\helper */ + protected $group_helper; + + protected function config_defaults() + { + $defaults = array( + 'ranks_path' => 'images/ranks' + ); + return $defaults; + } + + protected function get_test_language_data_set() + { + return array( + 'G_BOTS' => 'Bots', + 'G_NEW_GROUP' => 'Some new group', + 'G_not_uppercase' => 'The key does not contain uppercase letters', + 'G_GROUP_WITH_ÜMLAUTS' => 'Should work', + ); + } + + protected function get_test_rank_data_set() + { + return array( + 'special' => array( + 1 => array( + 'rank_id' => 1, + 'rank_title' => 'Site admin', + 'rank_special' => 1, + 'rank_image' => 'siteadmin.png', + ), + 2 => array( + 'rank_id' => 2, + 'rank_title' => 'Test member', + 'rank_special' => 1, + 'rank_image' => '', + ) + ) + ); + } + + protected function setup_engine(array $new_config = array()) + { + global $cache, $phpbb_dispatcher, $phpbb_root_path, $phpEx; + + // Set up authentication data for testing + $auth = $this->getMock('\phpbb\auth\auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap(array( + array('u_viewprofile', true), + ))); + + // Set up cache service + $cache_service = $this->getMockBuilder('\phpbb\cache\service')->disableOriginalConstructor()->getMock(); + $cache_service->expects($this->any()) + ->method('obtain_ranks') + ->will($this->returnValue($this->get_test_rank_data_set())); + + // Set up configuration + $defaults = $this->config_defaults(); + $config = new \phpbb\config\config(array_merge($defaults, $new_config)); + + // Set up language service + $lang = new \phpbb\language\language( + new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx) + ); + + // Set up language data for testing + $reflection_class = new ReflectionClass('\phpbb\language\language'); + + // Set default language files loaded flag to true + $loaded_flag = $reflection_class->getProperty('common_language_files_loaded'); + $loaded_flag->setAccessible(true); + $loaded_flag->setValue($lang, true); + + // Set up test language data + $lang_array = $reflection_class->getProperty('lang'); + $lang_array->setAccessible(true); + $lang_array->setValue($lang, $this->get_test_language_data_set()); + + // Set up event dispatcher + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // Set up path helper + $filesystem = new \phpbb\filesystem\filesystem(); + $path_helper = new \phpbb\path_helper( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $filesystem, + $this->getMock('\phpbb\request\request'), + $phpbb_root_path, + $phpEx + ); + + $user = new \phpbb\user($lang, '\phpbb\datetime'); + $user->data['user_id'] = ANONYMOUS; + + $this->group_helper = new \phpbb\group\helper($auth, $cache_service, $config, $lang, $phpbb_dispatcher, $path_helper, $user, $phpbb_root_path, $phpEx); + } + + public function setUp() + { + $this->setup_engine(); + } +} -- cgit v1.2.1 From e2e3d402a25b6203f2c29296eddf2dae002053da Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Sat, 29 Dec 2018 13:28:00 +0100 Subject: [ticket/15886] Clean up services PHPBB3-15886 --- tests/group/helper_test_case.php | 246 +++++++++++++++++++-------------------- 1 file changed, 123 insertions(+), 123 deletions(-) (limited to 'tests/group/helper_test_case.php') diff --git a/tests/group/helper_test_case.php b/tests/group/helper_test_case.php index 1318cf9040..cfbcd5890c 100644 --- a/tests/group/helper_test_case.php +++ b/tests/group/helper_test_case.php @@ -1,123 +1,123 @@ - - * @license GNU General Public License, version 2 (GPL-2.0) - * - * For full copyright and license information, please see - * the docs/CREDITS.txt file. - * - */ - -class phpbb_group_helper_test_case extends phpbb_test_case -{ - /** @var \phpbb\group\helper */ - protected $group_helper; - - protected function config_defaults() - { - $defaults = array( - 'ranks_path' => 'images/ranks' - ); - return $defaults; - } - - protected function get_test_language_data_set() - { - return array( - 'G_BOTS' => 'Bots', - 'G_NEW_GROUP' => 'Some new group', - 'G_not_uppercase' => 'The key does not contain uppercase letters', - 'G_GROUP_WITH_ÜMLAUTS' => 'Should work', - ); - } - - protected function get_test_rank_data_set() - { - return array( - 'special' => array( - 1 => array( - 'rank_id' => 1, - 'rank_title' => 'Site admin', - 'rank_special' => 1, - 'rank_image' => 'siteadmin.png', - ), - 2 => array( - 'rank_id' => 2, - 'rank_title' => 'Test member', - 'rank_special' => 1, - 'rank_image' => '', - ) - ) - ); - } - - protected function setup_engine(array $new_config = array()) - { - global $cache, $phpbb_dispatcher, $phpbb_root_path, $phpEx; - - // Set up authentication data for testing - $auth = $this->getMock('\phpbb\auth\auth'); - $auth->expects($this->any()) - ->method('acl_get') - ->with($this->stringContains('_'), $this->anything()) - ->will($this->returnValueMap(array( - array('u_viewprofile', true), - ))); - - // Set up cache service - $cache_service = $this->getMockBuilder('\phpbb\cache\service')->disableOriginalConstructor()->getMock(); - $cache_service->expects($this->any()) - ->method('obtain_ranks') - ->will($this->returnValue($this->get_test_rank_data_set())); - - // Set up configuration - $defaults = $this->config_defaults(); - $config = new \phpbb\config\config(array_merge($defaults, $new_config)); - - // Set up language service - $lang = new \phpbb\language\language( - new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx) - ); - - // Set up language data for testing - $reflection_class = new ReflectionClass('\phpbb\language\language'); - - // Set default language files loaded flag to true - $loaded_flag = $reflection_class->getProperty('common_language_files_loaded'); - $loaded_flag->setAccessible(true); - $loaded_flag->setValue($lang, true); - - // Set up test language data - $lang_array = $reflection_class->getProperty('lang'); - $lang_array->setAccessible(true); - $lang_array->setValue($lang, $this->get_test_language_data_set()); - - // Set up event dispatcher - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - - // Set up path helper - $filesystem = new \phpbb\filesystem\filesystem(); - $path_helper = new \phpbb\path_helper( - new \phpbb\symfony_request( - new phpbb_mock_request() - ), - $filesystem, - $this->getMock('\phpbb\request\request'), - $phpbb_root_path, - $phpEx - ); - - $user = new \phpbb\user($lang, '\phpbb\datetime'); - $user->data['user_id'] = ANONYMOUS; - - $this->group_helper = new \phpbb\group\helper($auth, $cache_service, $config, $lang, $phpbb_dispatcher, $path_helper, $user, $phpbb_root_path, $phpEx); - } - - public function setUp() - { - $this->setup_engine(); - } -} + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +class phpbb_group_helper_test_case extends phpbb_test_case +{ + /** @var \phpbb\group\helper */ + protected $group_helper; + + protected function config_defaults() + { + $defaults = array( + 'ranks_path' => 'images/ranks' + ); + return $defaults; + } + + protected function get_test_language_data_set() + { + return array( + 'G_BOTS' => 'Bots', + 'G_NEW_GROUP' => 'Some new group', + 'G_not_uppercase' => 'The key does not contain uppercase letters', + 'G_GROUP_WITH_ÜMLAUTS' => 'Should work', + ); + } + + protected function get_test_rank_data_set() + { + return array( + 'special' => array( + 1 => array( + 'rank_id' => 1, + 'rank_title' => 'Site admin', + 'rank_special' => 1, + 'rank_image' => 'siteadmin.png', + ), + 2 => array( + 'rank_id' => 2, + 'rank_title' => 'Test member', + 'rank_special' => 1, + 'rank_image' => '', + ) + ) + ); + } + + protected function setup_engine(array $new_config = array()) + { + global $phpbb_dispatcher, $phpbb_root_path, $phpEx; + + // Set up authentication data for testing + $auth = $this->getMock('\phpbb\auth\auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap(array( + array('u_viewprofile', true), + ))); + + // Set up cache service + $cache_service = $this->getMockBuilder('\phpbb\cache\service')->disableOriginalConstructor()->getMock(); + $cache_service->expects($this->any()) + ->method('obtain_ranks') + ->will($this->returnValue($this->get_test_rank_data_set())); + + // Set up configuration + $defaults = $this->config_defaults(); + $config = new \phpbb\config\config(array_merge($defaults, $new_config)); + + // Set up language service + $lang = new \phpbb\language\language( + new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx) + ); + + // Set up language data for testing + $reflection_class = new ReflectionClass('\phpbb\language\language'); + + // Set default language files loaded flag to true + $loaded_flag = $reflection_class->getProperty('common_language_files_loaded'); + $loaded_flag->setAccessible(true); + $loaded_flag->setValue($lang, true); + + // Set up test language data + $lang_array = $reflection_class->getProperty('lang'); + $lang_array->setAccessible(true); + $lang_array->setValue($lang, $this->get_test_language_data_set()); + + // Set up event dispatcher + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // Set up path helper + $filesystem = new \phpbb\filesystem\filesystem(); + $path_helper = new \phpbb\path_helper( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $filesystem, + $this->getMock('\phpbb\request\request'), + $phpbb_root_path, + $phpEx + ); + + $user = new \phpbb\user($lang, '\phpbb\datetime'); + $user->data['user_id'] = ANONYMOUS; + + $this->group_helper = new \phpbb\group\helper($auth, $cache_service, $config, $lang, $phpbb_dispatcher, $path_helper, $user); + } + + public function setUp() + { + $this->setup_engine(); + } +} -- cgit v1.2.1 From f023dd590f28b2721773f8429a2d1fbf995f544f Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Wed, 2 Jan 2019 12:33:25 +0100 Subject: [ticket/15886] Mock path helper in group helper tests PHPBB3-15886 --- tests/group/helper_test_case.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/group/helper_test_case.php') diff --git a/tests/group/helper_test_case.php b/tests/group/helper_test_case.php index cfbcd5890c..e298770331 100644 --- a/tests/group/helper_test_case.php +++ b/tests/group/helper_test_case.php @@ -99,16 +99,16 @@ class phpbb_group_helper_test_case extends phpbb_test_case $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); // Set up path helper - $filesystem = new \phpbb\filesystem\filesystem(); - $path_helper = new \phpbb\path_helper( - new \phpbb\symfony_request( - new phpbb_mock_request() - ), - $filesystem, - $this->getMock('\phpbb\request\request'), - $phpbb_root_path, - $phpEx - ); + $path_helper = $this->getMockBuilder('\phpbb\path_helper') + ->disableOriginalConstructor() + ->setMethods(array()) + ->getMock(); + $path_helper->method('get_phpbb_root_path') + ->willReturn($phpbb_root_path); + $path_helper->method('get_php_ext') + ->willReturn($phpEx); + $path_helper->method('update_web_root_path') + ->will($this->returnArgument(0)); $user = new \phpbb\user($lang, '\phpbb\datetime'); $user->data['user_id'] = ANONYMOUS; -- cgit v1.2.1