Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Under development...

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

[![Build Status](https://github.com/phpbb-extensions/pwakit/workflows/Tests/badge.svg)](https://github.com/phpbb-extensions/pwakit/actions)
[![codecov](https://codecov.io/gh/phpbb-extensions/pwakit/graph/badge.svg?token=34V2MQSY3H)](https://codecov.io/gh/phpbb-extensions/pwakit)
Expand Down
42 changes: 21 additions & 21 deletions tests/functional/acp_file_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected function setUp(): void
$this->fixtures = __DIR__ . '/../fixtures/';
$this->icons = __DIR__ . '/../../../../../images/site_icons/';

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

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

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

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

$file = [
'tmp_name' => $this->fixtures . $filename,
Expand All @@ -91,40 +91,40 @@ private function upload_file($filename, $mimetype): Crawler
);
}

public function test_upload_empty_file()
public function test_upload_empty_file(): void
{
$this->login();
$this->admin_login();
self::login();
self::admin_login();

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

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

public function test_upload_invalid_extension()
public function test_upload_invalid_extension(): void
{
$this->login();
$this->admin_login();
self::login();
self::admin_login();

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

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

public function test_upload_valid_file()
public function test_upload_valid_file(): void
{
$test_image = 'foo.png';

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

$this->login();
$this->admin_login();
self::login();
self::admin_login();

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

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

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

public function test_resync_delete_file()
public function test_resync_delete_file(): void
{
$test_image = 'bar.png';

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

$this->login();
$this->admin_login();
self::login();
self::admin_login();

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

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

Expand Down
22 changes: 11 additions & 11 deletions tests/functional/acp_settings_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ protected static function setup_extensions(): array
return ['phpbb/pwakit'];
}

public function test_extension_enabled()
public function test_extension_enabled(): void
{
$this->login();
$this->admin_login();
$this->add_lang('acp/extensions');
self::login();
self::admin_login();
self::add_lang('acp/extensions');

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

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

public function test_basic_form()
public function test_basic_form(): void
{
$this->login();
$this->admin_login();
self::login();
self::admin_login();

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

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

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

// Check saved data now appears in data fields
$crawler = self::request('GET', 'adm/index.php?i=-phpbb-pwakit-acp-pwa_acp_module&mode=settings&sid=' . $this->sid);
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/acp_module_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace phpbb\pwakit\tests\unit;

use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use p_master;
use phpbb\cache\driver\dummy;
Expand Down Expand Up @@ -147,10 +148,11 @@ public function test_main_module_with_missing_controller(): void
{
global $phpbb_container, $template, $request;

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

if (!defined('IN_ADMIN')) {
if (!defined('IN_ADMIN'))
{
define('IN_ADMIN', true);
}

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

$p_master = new p_master();
$p_master->module_ary[0]['is_duplicate'] = 0;
Expand Down
40 changes: 21 additions & 19 deletions tests/unit/admin_controller_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use phpbb\db\driver\driver_interface as dbal;
use phpbb_mock_cache;
use phpbb_mock_event_dispatcher;
use PHPUnit\DbUnit\DataSet\DefaultDataSet;
use PHPUnit\DbUnit\DataSet\XmlDataSet;
use PHPUnit\Framework\MockObject\MockObject;
use phpbb\config\config;
use phpbb\exception\runtime_exception;
Expand All @@ -25,6 +27,7 @@
use phpbb\request\request_interface;
use phpbb\template\template;
use phpbb_database_test_case;
use phpbb\pwakit\acp\pwa_acp_module;

class admin_controller_test extends phpbb_database_test_case
{
Expand All @@ -34,10 +37,10 @@ class admin_controller_test extends phpbb_database_test_case
protected dbal $db;
protected config $config;
protected language $language;
protected request $request;
protected template|MockObject $template;
protected helper $helper;
protected upload $upload;
protected MockObject|request $request;
protected MockObject|template $template;
protected MockObject|helper $helper;
protected MockObject|upload $upload;
protected string $phpbb_root_path;
protected admin_controller $admin_controller;

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

protected function getDataSet()
protected function getDataSet(): DefaultDataSet|XmlDataSet
{
return $this->createXMLDataSet(__DIR__ . '/../fixtures/styles.xml');
}
Expand Down Expand Up @@ -124,12 +127,11 @@ public static function module_access_test_data(): array
* @return void
* @dataProvider module_access_test_data
*/
public function test_module_access($mode, $expected)
public function test_module_access($mode, $expected): void
{
$this->request->expects($expected ? $this->atLeastOnce() : $this->never())
->method('is_set_post');


$this->call_admin_controller($mode);
}

Expand All @@ -146,7 +148,7 @@ public static function form_checks_data(): array
* @param $action
* @dataProvider form_checks_data
*/
public function test_form_checks($action)
public function test_form_checks($action): void
{
self::$valid_form = false;

Expand Down Expand Up @@ -208,7 +210,7 @@ public static function display_settings_test_data(): array
* @param $expected
* @dataProvider display_settings_test_data
*/
public function test_display_settings($configs, $expected)
public function test_display_settings($configs, $expected): void
{
foreach ($configs as $key => $value)
{
Expand Down Expand Up @@ -350,10 +352,10 @@ public static function submit_test_data(): array
* @param $expected_msg
* @dataProvider submit_test_data
*/
public function test_submit($form_data, $expected, $expected_msg)
public function test_submit($form_data, $expected, $expected_msg): void
{
$is_success = $expected_msg === 'CONFIG_UPDATED';

if ($is_success)
{
$this->setExpectedTriggerError(E_USER_NOTICE, 'CONFIG_UPDATED');
Expand All @@ -380,7 +382,7 @@ public function test_submit($form_data, $expected, $expected_msg)
]);

$this->request_submit('submit');

if ($is_success)
{
$this->call_admin_controller();
Expand All @@ -404,7 +406,7 @@ public function test_submit($form_data, $expected, $expected_msg)
$this->assertSame($expected, $rows);
}

public function test_upload()
public function test_upload(): void
{
$this->setExpectedTriggerError(E_USER_NOTICE, 'ACP_PWA_IMG_UPLOAD_SUCCESS');

Expand All @@ -417,7 +419,7 @@ public function test_upload()
$this->call_admin_controller();
}

public function test_upload_error()
public function test_upload_error(): void
{
$this->request_submit('upload');

Expand All @@ -431,7 +433,7 @@ public function test_upload_error()
$this->call_admin_controller();
}

public function test_resync()
public function test_resync(): void
{
$this->request_submit('resync');

Expand Down Expand Up @@ -468,7 +470,7 @@ public static function delete_test_data(): array
* @param $error
* @dataProvider delete_test_data
*/
public function test_delete($image, $confirmed, $error)
public function test_delete($image, $confirmed, $error): void
{
self::$confirm = $confirmed;

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

/**
Expand All @@ -533,7 +535,7 @@ private function request_submit($value): void
*/
function check_form_key(): bool
{
return \phpbb\pwakit\controller\admin_controller_test::$valid_form;
return admin_controller_test::$valid_form;
}

/**
Expand All @@ -552,7 +554,7 @@ function add_form_key()
*/
function confirm_box(): bool
{
return \phpbb\pwakit\controller\admin_controller_test::$confirm;
return admin_controller_test::$confirm;
}

/**
Expand Down
Loading