Skip to content

Commit cd90941

Browse files
authored
Merge pull request #39 from iMattPro/updates
Various php 8 updates
2 parents e0656c3 + 8d94b80 commit cd90941

9 files changed

Lines changed: 97 additions & 86 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Under development...
44

5-
Gives phpBB board admins ability to manage web app icons and colour themes for their site.
5+
Allows phpBB board admins to manage web app icons and colour themes for their site.
66

77
[![Build Status](https://github.com/phpbb-extensions/pwakit/workflows/Tests/badge.svg)](https://github.com/phpbb-extensions/pwakit/actions)
88
[![codecov](https://codecov.io/gh/phpbb-extensions/pwakit/graph/badge.svg?token=34V2MQSY3H)](https://codecov.io/gh/phpbb-extensions/pwakit)

tests/functional/acp_file_test.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ protected function setUp(): void
3939
$this->fixtures = __DIR__ . '/../fixtures/';
4040
$this->icons = __DIR__ . '/../../../../../images/site_icons/';
4141

42-
$this->add_lang('posting');
43-
$this->add_lang_ext('phpbb/pwakit', ['acp_pwa', 'info_acp_pwa']);
42+
self::add_lang('posting');
43+
self::add_lang_ext('phpbb/pwakit', ['acp_pwa', 'info_acp_pwa']);
4444
}
4545

4646
protected function tearDown(): void
@@ -71,9 +71,9 @@ private function upload_file($filename, $mimetype): Crawler
7171
$url = 'index.php?i=-phpbb-pwakit-acp-pwa_acp_module&mode=settings&sid=' . $this->sid;
7272

7373
$crawler = self::$client->request('GET', $url);
74-
$this->assertContainsLang('ACP_PWA_KIT_SETTINGS', $crawler->text());
74+
self::assertContainsLang('ACP_PWA_KIT_SETTINGS', $crawler->text());
7575

76-
$file_form_data = array_merge(['upload' => $this->lang('ACP_PWA_IMG_UPLOAD_BTN')], $this->get_hidden_fields($crawler, $url));
76+
$file_form_data = array_merge(['upload' => self::lang('ACP_PWA_IMG_UPLOAD_BTN')], $this->get_hidden_fields($crawler, $url));
7777

7878
$file = [
7979
'tmp_name' => $this->fixtures . $filename,
@@ -91,40 +91,40 @@ private function upload_file($filename, $mimetype): Crawler
9191
);
9292
}
9393

94-
public function test_upload_empty_file()
94+
public function test_upload_empty_file(): void
9595
{
96-
$this->login();
97-
$this->admin_login();
96+
self::login();
97+
self::admin_login();
9898

9999
$crawler = $this->upload_file('empty.png', 'image/png');
100100

101-
$this->assertEquals($this->lang('EMPTY_FILEUPLOAD'), $crawler->filter('div.errorbox > p')->text());
101+
$this->assertEquals(self::lang('EMPTY_FILEUPLOAD'), $crawler->filter('div.errorbox > p')->text());
102102
}
103103

104-
public function test_upload_invalid_extension()
104+
public function test_upload_invalid_extension(): void
105105
{
106-
$this->login();
107-
$this->admin_login();
106+
self::login();
107+
self::admin_login();
108108

109109
$crawler = $this->upload_file('foo.gif', 'image/gif');
110110

111-
$this->assertEquals($this->lang('DISALLOWED_EXTENSION', 'gif'), $crawler->filter('div.errorbox > p')->text());
111+
$this->assertEquals(self::lang('DISALLOWED_EXTENSION', 'gif'), $crawler->filter('div.errorbox > p')->text());
112112
}
113113

114-
public function test_upload_valid_file()
114+
public function test_upload_valid_file(): void
115115
{
116116
$test_image = 'foo.png';
117117

118118
// Check icon does not yet appear in the html tags
119119
$this->assertAppleTouchIconNotPresent();
120120

121-
$this->login();
122-
$this->admin_login();
121+
self::login();
122+
self::admin_login();
123123

124124
$crawler = $this->upload_file($test_image, 'image/png');
125125

126126
// Ensure there was no error message rendered
127-
$this->assertContainsLang('ACP_PWA_IMG_UPLOAD_SUCCESS', $crawler->text());
127+
self::assertContainsLang('ACP_PWA_IMG_UPLOAD_SUCCESS', $crawler->text());
128128

129129
// Check icon appears in the ACP as expected
130130
$this->assertIconInACP($test_image);
@@ -133,7 +133,7 @@ public function test_upload_valid_file()
133133
$this->assertAppleTouchIconPresent($test_image);
134134
}
135135

136-
public function test_resync_delete_file()
136+
public function test_resync_delete_file(): void
137137
{
138138
$test_image = 'bar.png';
139139

@@ -143,8 +143,8 @@ public function test_resync_delete_file()
143143
// Check icon does not appear in the html tags
144144
$this->assertAppleTouchIconNotPresent();
145145

146-
$this->login();
147-
$this->admin_login();
146+
self::login();
147+
self::admin_login();
148148

149149
// Ensure copied image does not appear in ACP
150150
$crawler = $this->assertIconsNotInACP();
@@ -188,7 +188,7 @@ private function performDelete(string $icon): void
188188
$crawler = self::submit($form);
189189
$form = $crawler->selectButton('confirm')->form(['delete' => $icon]);
190190
$crawler = self::submit($form);
191-
$this->assertStringContainsString($this->lang('ACP_PWA_IMG_DELETED', $icon), $crawler->text());
191+
$this->assertStringContainsString(self::lang('ACP_PWA_IMG_DELETED', $icon), $crawler->text());
192192
}
193193

194194
/**
@@ -222,7 +222,7 @@ private function assertAppleTouchIconPresent(string $icon): void
222222
private function assertIconsNotInACP(): Crawler
223223
{
224224
$crawler = self::request('GET', 'adm/index.php?i=-phpbb-pwakit-acp-pwa_acp_module&mode=settings&sid=' . $this->sid);
225-
$this->assertContainsLang('ACP_PWA_KIT_NO_ICONS', $crawler->filter('fieldset')->eq(3)->html());
225+
self::assertContainsLang('ACP_PWA_KIT_NO_ICONS', $crawler->filter('fieldset')->eq(3)->html());
226226
return $crawler;
227227
}
228228

tests/functional/acp_settings_test.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@ protected static function setup_extensions(): array
2323
return ['phpbb/pwakit'];
2424
}
2525

26-
public function test_extension_enabled()
26+
public function test_extension_enabled(): void
2727
{
28-
$this->login();
29-
$this->admin_login();
30-
$this->add_lang('acp/extensions');
28+
self::login();
29+
self::admin_login();
30+
self::add_lang('acp/extensions');
3131

3232
$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
3333

3434
$this->assertStringContainsString('Progressive Web App Kit', $crawler->filter('.ext_enabled')->eq(0)->text());
35-
$this->assertContainsLang('EXTENSION_DISABLE', $crawler->filter('.ext_enabled')->eq(0)->text());
35+
self::assertContainsLang('EXTENSION_DISABLE', $crawler->filter('.ext_enabled')->eq(0)->text());
3636
}
3737

38-
public function test_basic_form()
38+
public function test_basic_form(): void
3939
{
40-
$this->login();
41-
$this->admin_login();
40+
self::login();
41+
self::admin_login();
4242

43-
$this->add_lang_ext('phpbb/pwakit', 'info_acp_pwa');
43+
self::add_lang_ext('phpbb/pwakit', 'info_acp_pwa');
4444

4545
// Check ACP page loads
4646
$crawler = self::request('GET', 'adm/index.php?i=-phpbb-pwakit-acp-pwa_acp_module&mode=settings&sid=' . $this->sid);
47-
$this->assertContainsLang('ACP_PWA_KIT_TITLE', $crawler->filter('div.main > h1')->text());
47+
self::assertContainsLang('ACP_PWA_KIT_TITLE', $crawler->filter('div.main > h1')->text());
4848

4949
// The _1 means these are for prosilver (style id 1)
5050
$form_data = [
@@ -61,7 +61,7 @@ public function test_basic_form()
6161
// Submit form
6262
$form = $crawler->selectButton('submit')->form($form_data);
6363
$crawler = self::submit($form);
64-
$this->assertStringContainsString($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());
64+
$this->assertStringContainsString(self::lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());
6565

6666
// Check saved data now appears in data fields
6767
$crawler = self::request('GET', 'adm/index.php?i=-phpbb-pwakit-acp-pwa_acp_module&mode=settings&sid=' . $this->sid);

tests/unit/acp_module_test.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace phpbb\pwakit\tests\unit;
1212

13+
use RuntimeException;
1314
use Symfony\Component\DependencyInjection\ContainerInterface;
1415
use p_master;
1516
use phpbb\cache\driver\dummy;
@@ -147,10 +148,11 @@ public function test_main_module_with_missing_controller(): void
147148
{
148149
global $phpbb_container, $template, $request;
149150

150-
$this->expectException(\RuntimeException::class);
151+
$this->expectException(RuntimeException::class);
151152
$this->expectExceptionMessage('Service not found: phpbb.pwakit.admin.controller');
152153

153-
if (!defined('IN_ADMIN')) {
154+
if (!defined('IN_ADMIN'))
155+
{
154156
define('IN_ADMIN', true);
155157
}
156158

@@ -173,7 +175,7 @@ public function test_main_module_with_missing_controller(): void
173175
->expects($this->once())
174176
->method('get')
175177
->with('phpbb.pwakit.admin.controller')
176-
->willThrowException(new \RuntimeException('Service not found: phpbb.pwakit.admin.controller'));
178+
->willThrowException(new RuntimeException('Service not found: phpbb.pwakit.admin.controller'));
177179

178180
$p_master = new p_master();
179181
$p_master->module_ary[0]['is_duplicate'] = 0;

tests/unit/admin_controller_test.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use phpbb\db\driver\driver_interface as dbal;
1515
use phpbb_mock_cache;
1616
use phpbb_mock_event_dispatcher;
17+
use PHPUnit\DbUnit\DataSet\DefaultDataSet;
18+
use PHPUnit\DbUnit\DataSet\XmlDataSet;
1719
use PHPUnit\Framework\MockObject\MockObject;
1820
use phpbb\config\config;
1921
use phpbb\exception\runtime_exception;
@@ -25,6 +27,7 @@
2527
use phpbb\request\request_interface;
2628
use phpbb\template\template;
2729
use phpbb_database_test_case;
30+
use phpbb\pwakit\acp\pwa_acp_module;
2831

2932
class admin_controller_test extends phpbb_database_test_case
3033
{
@@ -34,10 +37,10 @@ class admin_controller_test extends phpbb_database_test_case
3437
protected dbal $db;
3538
protected config $config;
3639
protected language $language;
37-
protected request $request;
38-
protected template|MockObject $template;
39-
protected helper $helper;
40-
protected upload $upload;
40+
protected MockObject|request $request;
41+
protected MockObject|template $template;
42+
protected MockObject|helper $helper;
43+
protected MockObject|upload $upload;
4144
protected string $phpbb_root_path;
4245
protected admin_controller $admin_controller;
4346

@@ -46,7 +49,7 @@ protected static function setup_extensions(): array
4649
return ['phpbb/pwakit'];
4750
}
4851

49-
protected function getDataSet()
52+
protected function getDataSet(): DefaultDataSet|XmlDataSet
5053
{
5154
return $this->createXMLDataSet(__DIR__ . '/../fixtures/styles.xml');
5255
}
@@ -124,12 +127,11 @@ public static function module_access_test_data(): array
124127
* @return void
125128
* @dataProvider module_access_test_data
126129
*/
127-
public function test_module_access($mode, $expected)
130+
public function test_module_access($mode, $expected): void
128131
{
129132
$this->request->expects($expected ? $this->atLeastOnce() : $this->never())
130133
->method('is_set_post');
131134

132-
133135
$this->call_admin_controller($mode);
134136
}
135137

@@ -146,7 +148,7 @@ public static function form_checks_data(): array
146148
* @param $action
147149
* @dataProvider form_checks_data
148150
*/
149-
public function test_form_checks($action)
151+
public function test_form_checks($action): void
150152
{
151153
self::$valid_form = false;
152154

@@ -208,7 +210,7 @@ public static function display_settings_test_data(): array
208210
* @param $expected
209211
* @dataProvider display_settings_test_data
210212
*/
211-
public function test_display_settings($configs, $expected)
213+
public function test_display_settings($configs, $expected): void
212214
{
213215
foreach ($configs as $key => $value)
214216
{
@@ -350,10 +352,10 @@ public static function submit_test_data(): array
350352
* @param $expected_msg
351353
* @dataProvider submit_test_data
352354
*/
353-
public function test_submit($form_data, $expected, $expected_msg)
355+
public function test_submit($form_data, $expected, $expected_msg): void
354356
{
355357
$is_success = $expected_msg === 'CONFIG_UPDATED';
356-
358+
357359
if ($is_success)
358360
{
359361
$this->setExpectedTriggerError(E_USER_NOTICE, 'CONFIG_UPDATED');
@@ -380,7 +382,7 @@ public function test_submit($form_data, $expected, $expected_msg)
380382
]);
381383

382384
$this->request_submit('submit');
383-
385+
384386
if ($is_success)
385387
{
386388
$this->call_admin_controller();
@@ -404,7 +406,7 @@ public function test_submit($form_data, $expected, $expected_msg)
404406
$this->assertSame($expected, $rows);
405407
}
406408

407-
public function test_upload()
409+
public function test_upload(): void
408410
{
409411
$this->setExpectedTriggerError(E_USER_NOTICE, 'ACP_PWA_IMG_UPLOAD_SUCCESS');
410412

@@ -417,7 +419,7 @@ public function test_upload()
417419
$this->call_admin_controller();
418420
}
419421

420-
public function test_upload_error()
422+
public function test_upload_error(): void
421423
{
422424
$this->request_submit('upload');
423425

@@ -431,7 +433,7 @@ public function test_upload_error()
431433
$this->call_admin_controller();
432434
}
433435

434-
public function test_resync()
436+
public function test_resync(): void
435437
{
436438
$this->request_submit('resync');
437439

@@ -468,7 +470,7 @@ public static function delete_test_data(): array
468470
* @param $error
469471
* @dataProvider delete_test_data
470472
*/
471-
public function test_delete($image, $confirmed, $error)
473+
public function test_delete($image, $confirmed, $error): void
472474
{
473475
self::$confirm = $confirmed;
474476

@@ -510,7 +512,7 @@ public function test_delete($image, $confirmed, $error)
510512
*/
511513
private function call_admin_controller(string $mode = 'settings'): void
512514
{
513-
$this->admin_controller->main('\\phpbb\\pwakit\\acp\\pwa_acp_module', $mode, '');
515+
$this->admin_controller->main(pwa_acp_module::class, $mode, '');
514516
}
515517

516518
/**
@@ -533,7 +535,7 @@ private function request_submit($value): void
533535
*/
534536
function check_form_key(): bool
535537
{
536-
return \phpbb\pwakit\controller\admin_controller_test::$valid_form;
538+
return admin_controller_test::$valid_form;
537539
}
538540

539541
/**
@@ -552,7 +554,7 @@ function add_form_key()
552554
*/
553555
function confirm_box(): bool
554556
{
555-
return \phpbb\pwakit\controller\admin_controller_test::$confirm;
557+
return admin_controller_test::$confirm;
556558
}
557559

558560
/**

0 commit comments

Comments
 (0)