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
30 changes: 14 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
cacheResult="false"
bootstrap="../../../../tests/bootstrap.php"
>
<coverage>
<include>
<directory suffix=".php">./</directory>
</include>
<exclude>
<directory suffix=".php">./language/</directory>
<directory suffix=".php">./migrations/</directory>
<directory suffix=".php">./tests/</directory>
</exclude>
</coverage>
backupStaticProperties="false">
<testsuites>
<testsuite name="Extension Test Suite">
<directory suffix="_test.php">./tests</directory>
Expand All @@ -31,4 +17,16 @@
<directory suffix="_test.php">./tests/functional/</directory>
</testsuite>
</testsuites>
<source restrictDeprecations="true"
restrictNotices="true"
restrictWarnings="true">
<include>
<directory suffix=".php">./</directory>
</include>
<exclude>
<directory suffix=".php">./language/</directory>
<directory suffix=".php">./migrations/</directory>
<directory suffix=".php">./tests/</directory>
</exclude>
</source>
</phpunit>
63 changes: 53 additions & 10 deletions tests/unit/acp_module_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ protected function setUp(): void
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
}

public function test_module_info()
public function test_module_info(): void
{
self::assertEquals([
$expected = [
'\\phpbb\\pwakit\\acp\\pwa_acp_module' => [
'filename' => '\\phpbb\\pwakit\\acp\\pwa_acp_module',
'title' => 'ACP_PWA_KIT_TITLE',
Expand All @@ -71,10 +71,15 @@ public function test_module_info()
],
],
],
], $this->module_manager->get_module_infos('acp', 'pwa_acp_module'));
];

$this->assertSame(
$expected,
$this->module_manager->get_module_infos('acp', 'pwa_acp_module')
);
}

public function module_auth_test_data(): array
public static function module_auth_test_data(): array
{
return [
'invalid auth' => ['ext_foo/bar', false],
Expand All @@ -85,12 +90,12 @@ public function module_auth_test_data(): array
/**
* @dataProvider module_auth_test_data
*/
public function test_module_auth($module_auth, $expected)
public function test_module_auth(string $module_auth, bool $expected): void
{
self::assertEquals($expected, p_master::module_auth($module_auth, 0));
$this->assertEquals($expected, p_master::module_auth($module_auth, 0));
}

public function main_module_test_data(): array
public static function main_module_test_data(): array
{
return [
'valid mode' => ['settings'],
Expand All @@ -100,7 +105,7 @@ public function main_module_test_data(): array
/**
* @dataProvider main_module_test_data
*/
public function test_main_module($mode)
public function test_main_module(string $mode): void
{
global $phpbb_container, $request, $template;

Expand All @@ -123,18 +128,56 @@ public function test_main_module($mode)
->getMock();

$phpbb_container
->expects(self::once())
->expects($this->once())
->method('get')
->with('phpbb.pwakit.admin.controller')
->willReturn($admin_controller);

$admin_controller
->expects(self::once())
->expects($this->once())
->method('main');

$p_master = new p_master();
$p_master->module_ary[0]['is_duplicate'] = 0;
$p_master->module_ary[0]['url_extra'] = '';
$p_master->load('acp', pwa_acp_module::class, $mode);
}

public function test_main_module_with_missing_controller(): void
{
global $phpbb_container, $template, $request;

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

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

// Set up template mock
$template = $this->getMockBuilder(template::class)
->disableOriginalConstructor()
->getMock();

// Set up request mock
$request = $this->getMockBuilder(request::class)
->disableOriginalConstructor()
->getMock();

// Set up container mock
$phpbb_container = $this->getMockBuilder(ContainerInterface::class)
->disableOriginalConstructor()
->getMock();

$phpbb_container
->expects($this->once())
->method('get')
->with('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;
$p_master->module_ary[0]['url_extra'] = '';
$p_master->load('acp', pwa_acp_module::class, 'settings');
}
}
16 changes: 7 additions & 9 deletions tests/unit/admin_controller_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
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\IDataSet;
use PHPUnit\DbUnit\DataSet\XmlDataSet;
use PHPUnit\Framework\MockObject\MockObject;
use phpbb\config\config;
use phpbb\exception\runtime_exception;
Expand All @@ -42,13 +39,14 @@ class admin_controller_test extends phpbb_database_test_case
protected helper $helper;
protected upload $upload;
protected string $phpbb_root_path;
protected admin_controller $admin_controller;

protected static function setup_extensions(): array
{
return ['phpbb/pwakit'];
}

protected function getDataSet(): IDataSet|XmlDataSet|DefaultDataSet
protected function getDataSet()
{
return $this->createXMLDataSet(__DIR__ . '/../fixtures/styles.xml');
}
Expand Down Expand Up @@ -112,7 +110,7 @@ protected function setUp(): void
);
}

public function module_access_test_data(): array
public static function module_access_test_data(): array
{
return [
'correct mode' => ['settings', true],
Expand All @@ -135,7 +133,7 @@ public function test_module_access($mode, $expected)
$this->call_admin_controller($mode);
}

public function form_checks_data(): array
public static function form_checks_data(): array
{
return [
'submit test' => ['submit'],
Expand All @@ -159,7 +157,7 @@ public function test_form_checks($action)
$this->call_admin_controller();
}

public function display_settings_test_data(): array
public static function display_settings_test_data(): array
{
return [
'site name and short name' => [
Expand Down Expand Up @@ -260,7 +258,7 @@ public function test_display_settings($configs, $expected)
$this->call_admin_controller();
}

public function submit_test_data(): array
public static function submit_test_data(): array
{
return [
'all good inputs' => [
Expand Down Expand Up @@ -443,7 +441,7 @@ public function test_resync()
$this->call_admin_controller();
}

public function delete_test_data(): array
public static function delete_test_data(): array
{
return [
'not confirmed' => [
Expand Down
Loading