|
18 | 18 | use phpbb\skeleton\ext; |
19 | 19 | use Symfony\Component\DependencyInjection\ContainerInterface; |
20 | 20 |
|
| 21 | +require_once __DIR__ . '/test_helpers.php'; |
| 22 | + |
21 | 23 | class main_test extends \phpbb_test_case |
22 | 24 | { |
23 | 25 | /** @var \phpbb\template\template|\PHPUnit\Framework\MockObject\MockObject */ |
@@ -50,6 +52,9 @@ class main_test extends \phpbb_test_case |
50 | 52 | protected function setUp(): void |
51 | 53 | { |
52 | 54 | global $phpbb_root_path; |
| 55 | + global $phpbb_skeleton_form_key_valid; |
| 56 | + |
| 57 | + $phpbb_skeleton_form_key_valid = true; |
53 | 58 |
|
54 | 59 | // Mocks are dummy implementations that provide the API of components we depend on // |
55 | 60 | $this->template = $this->getMockBuilder('\phpbb\template\template') |
@@ -272,6 +277,30 @@ public function test_handle_unauthorised() |
272 | 277 | $this->get_controller($this->packager_mock)->handle(); |
273 | 278 | } |
274 | 279 |
|
| 280 | + public function test_submit_invalid_form_key() |
| 281 | + { |
| 282 | + global $phpbb_skeleton_form_key_valid; |
| 283 | + |
| 284 | + $this->user->data['is_bot'] = false; |
| 285 | + $phpbb_skeleton_form_key_valid = false; |
| 286 | + |
| 287 | + $this->request->expects($this->once()) |
| 288 | + ->method('is_set_post') |
| 289 | + ->with('submit') |
| 290 | + ->willReturn(true); |
| 291 | + |
| 292 | + $this->packager_mock->expects($this->never()) |
| 293 | + ->method('create_extension'); |
| 294 | + |
| 295 | + $this->packager_mock->expects($this->never()) |
| 296 | + ->method('create_zip'); |
| 297 | + |
| 298 | + $this->expectException(http_exception::class); |
| 299 | + $this->expectExceptionMessage('FORM_INVALID'); |
| 300 | + |
| 301 | + $this->get_controller($this->packager_mock)->handle(); |
| 302 | + } |
| 303 | + |
275 | 304 | public function test_submit_success() |
276 | 305 | { |
277 | 306 | $this->user->data['is_bot'] = false; |
|
0 commit comments