|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * |
| 4 | + * Ideas extension for the phpBB Forum Software package. |
| 5 | + * |
| 6 | + * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | + * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +require_once __DIR__ . '/../../../../../includes/functions_module.php'; |
| 12 | + |
| 13 | +class acp_module_test extends \phpbb_test_case |
| 14 | +{ |
| 15 | + /** @var \phpbb_mock_extension_manager */ |
| 16 | + protected $extension_manager; |
| 17 | + |
| 18 | + /** @var \phpbb\module\module_manager */ |
| 19 | + protected $module_manager; |
| 20 | + |
| 21 | + protected function setUp(): void |
| 22 | + { |
| 23 | + global $phpbb_dispatcher, $phpbb_extension_manager, $phpbb_root_path, $phpEx; |
| 24 | + |
| 25 | + $this->extension_manager = new \phpbb_mock_extension_manager( |
| 26 | + $phpbb_root_path, |
| 27 | + [ |
| 28 | + 'phpbb/ideas' => [ |
| 29 | + 'ext_name' => 'phpbb/ideas', |
| 30 | + 'ext_active' => '1', |
| 31 | + 'ext_path' => 'ext/phpbb/ideas/', |
| 32 | + ], |
| 33 | + ]); |
| 34 | + $phpbb_extension_manager = $this->extension_manager; |
| 35 | + |
| 36 | + $this->module_manager = new \phpbb\module\module_manager( |
| 37 | + new \phpbb\cache\driver\dummy(), |
| 38 | + $this->getMockBuilder('\phpbb\db\driver\driver_interface')->getMock(), |
| 39 | + $this->extension_manager, |
| 40 | + MODULES_TABLE, |
| 41 | + $phpbb_root_path, |
| 42 | + $phpEx |
| 43 | + ); |
| 44 | + |
| 45 | + $phpbb_dispatcher = new \phpbb_mock_event_dispatcher(); |
| 46 | + } |
| 47 | + |
| 48 | + public function test_module_info() |
| 49 | + { |
| 50 | + self::assertEquals([ |
| 51 | + '\\phpbb\\ideas\\acp\\ideas_module' => [ |
| 52 | + 'filename' => '\\phpbb\\ideas\\acp\\ideas_module', |
| 53 | + 'title' => 'ACP_PHPBB_IDEAS', |
| 54 | + 'modes' => [ |
| 55 | + 'settings' => [ |
| 56 | + 'title' => 'ACP_PHPBB_IDEAS_SETTINGS', |
| 57 | + 'auth' => 'ext_phpbb/ideas && acl_a_board', |
| 58 | + 'cat' => ['ACP_PHPBB_IDEAS'] |
| 59 | + ], |
| 60 | + ], |
| 61 | + ], |
| 62 | + ], $this->module_manager->get_module_infos('acp', 'acp_ideas_module')); |
| 63 | + } |
| 64 | + |
| 65 | + public function module_auth_test_data() |
| 66 | + { |
| 67 | + return [ |
| 68 | + // module_auth, expected result |
| 69 | + ['ext_foo/bar', false], |
| 70 | + ['ext_phpbb/ideas', true], |
| 71 | + ]; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @dataProvider module_auth_test_data |
| 76 | + */ |
| 77 | + public function test_module_auth($module_auth, $expected) |
| 78 | + { |
| 79 | + self::assertEquals($expected, p_master::module_auth($module_auth, 0)); |
| 80 | + } |
| 81 | + |
| 82 | + public function main_module_test_data() |
| 83 | + { |
| 84 | + return [ |
| 85 | + ['submit'], |
| 86 | + ['ideas_forum_setup'], |
| 87 | + [''] |
| 88 | + ]; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * @dataProvider main_module_test_data |
| 93 | + * @param string $post |
| 94 | + */ |
| 95 | + public function test_main_module($post) |
| 96 | + { |
| 97 | + global $phpbb_container, $request, $template; |
| 98 | + |
| 99 | + if (!defined('IN_ADMIN')) |
| 100 | + { |
| 101 | + define('IN_ADMIN', true); |
| 102 | + } |
| 103 | + |
| 104 | + if ($post) |
| 105 | + { |
| 106 | + $this->expectException('\Exception'); |
| 107 | + } |
| 108 | + |
| 109 | + $request = $this->getMockBuilder('\phpbb\request\request') |
| 110 | + ->disableOriginalConstructor() |
| 111 | + ->getMock(); |
| 112 | + $language = $this->getMockBuilder('\phpbb\language\language') |
| 113 | + ->disableOriginalConstructor() |
| 114 | + ->getMock(); |
| 115 | + $template = $this->getMockBuilder('\phpbb\template\template') |
| 116 | + ->disableOriginalConstructor() |
| 117 | + ->getMock(); |
| 118 | + $phpbb_container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface') |
| 119 | + ->disableOriginalConstructor() |
| 120 | + ->getMock(); |
| 121 | + $admin_controller = $this->getMockBuilder('\phpbb\ideas\controller\admin_controller') |
| 122 | + ->disableOriginalConstructor() |
| 123 | + ->getMock(); |
| 124 | + |
| 125 | + $phpbb_container |
| 126 | + ->expects(self::exactly(3)) |
| 127 | + ->method('get') |
| 128 | + ->withConsecutive(['language'], ['request'], ['phpbb.ideas.admin.controller']) |
| 129 | + ->willReturnOnConsecutiveCalls($language, $request, $admin_controller); |
| 130 | + |
| 131 | + // Add the phpBB Ideas ACP lang file |
| 132 | + $language->expects(self::once()) |
| 133 | + ->method('add_lang') |
| 134 | + ->with('phpbb_ideas_acp', 'phpbb/ideas'); |
| 135 | + |
| 136 | + // Make the $u_action url available in the admin controller |
| 137 | + $admin_controller |
| 138 | + ->expects(self::once()) |
| 139 | + ->method('set_page_url'); |
| 140 | + |
| 141 | + if ($post === 'submit') |
| 142 | + { |
| 143 | + $request->expects(self::once()) |
| 144 | + ->method('is_set_post') |
| 145 | + ->with('submit') |
| 146 | + ->willReturn(true); |
| 147 | + } |
| 148 | + |
| 149 | + if ($post === 'ideas_forum_setup') |
| 150 | + { |
| 151 | + $request->expects(self::exactly(2)) |
| 152 | + ->method('is_set_post') |
| 153 | + ->withConsecutive(['submit'], ['ideas_forum_setup']) |
| 154 | + ->willReturnOnConsecutiveCalls(false, true); |
| 155 | + } |
| 156 | + |
| 157 | + // Apply Ideas configuration settings |
| 158 | + $admin_controller->expects($post === 'submit' ? self::once() : self::never()) |
| 159 | + ->method('set_config_options') |
| 160 | + ->willThrowException(new \Exception()); |
| 161 | + |
| 162 | + // Set Ideas forum options and registered user group forum permissions |
| 163 | + $admin_controller->expects($post === 'ideas_forum_setup' ? self::once() : self::never()) |
| 164 | + ->method('set_ideas_forum_options') |
| 165 | + ->willThrowException(new \Exception()); |
| 166 | + |
| 167 | + // Display/set ACP configuration settings |
| 168 | + $admin_controller->expects(empty($post) ? self::once() : self::never()) |
| 169 | + ->method('display_options'); |
| 170 | + |
| 171 | + $p_master = new p_master(); |
| 172 | + $p_master->module_ary[0]['is_duplicate'] = 0; |
| 173 | + $p_master->module_ary[0]['url_extra'] = ''; |
| 174 | + $p_master->load('acp', '\phpbb\ideas\acp\ideas_module'); |
| 175 | + } |
| 176 | +} |
0 commit comments