Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor updates #27

Merged
merged 6 commits into from
Jan 20, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ jobs:
db: "mysql:5.7"
- php: '8.2'
db: "mysql:5.7"
- php: '8.3'
db: "mysql:5.7"

name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}

Expand Down Expand Up @@ -266,6 +268,8 @@ jobs:
db: "postgres:14"
- php: '8.2'
db: "postgres:14"
- php: '8.3'
db: "postgres:14"

name: PHP ${{ matrix.php }} - ${{ matrix.db }}

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"version-check": {
"host": "www.phpbb.com",
"directory": "/customise/db/extension/topicprefixes",
"filename": "version_check"
"filename": "version_check",
"ssl": true
}
}
}
6 changes: 5 additions & 1 deletion controller/admin_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ public function add_prefix()

$tag = $this->request->variable('prefix_tag', '', true);
$prefix = $this->manager->add_prefix($tag, $this->forum_id);
$this->log($prefix['prefix_tag'], 'ACP_LOG_PREFIX_ADDED');

if ($prefix)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it not give feedback to the user, if this fails?

{
$this->log($prefix['prefix_tag'], 'ACP_LOG_PREFIX_ADDED');
}
}
}

Expand Down
32 changes: 20 additions & 12 deletions tests/controller/add_prefix_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ class add_prefix_test extends admin_controller_base
*/
public function data_add_prefix()
{
return array(
array(true, true),
array(true, false),
array(false, false),
);
return [
['', true, true],
['topic_prefix1', true, true],
['topic_prefix2', true, false],
['topic_prefix3', false, false],
];
}

/**
* Test add_prefix()
*
* @dataProvider data_add_prefix
* @param $prefix
* @param $submit
* @param $valid_form
*/
public function test_add_prefix($submit, $valid_form)
public function test_add_prefix($prefix, $submit, $valid_form)
{
if ($submit)
{
Expand All @@ -52,20 +54,26 @@ public function test_add_prefix($submit, $valid_form)
if (!$valid_form)
{
// Throws E_WARNING in PHP 8.0+ and E_USER_WARNING in earlier versions
$exceptionName = version_compare(PHP_VERSION, '8.0', '<') ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Warning::class;
$errno = version_compare(PHP_VERSION, '8.0', '<') ? E_USER_WARNING : E_WARNING;
$exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Warning::class;
$errno = PHP_VERSION_ID < 80000 ? E_USER_WARNING : E_WARNING;
$this->expectException($exceptionName);
$this->expectExceptionCode($errno);
}
else
{
$valid_prefix = $prefix !== '';
$this->request->expects(static::once())
->method('variable')
->willReturnMap([
['prefix_tag', '', true, \phpbb\request\request_interface::REQUEST, $prefix],
]);
$this->manager->expects(static::once())
->method('add_prefix')
->willReturn(['prefix_tag' => 'topic_prefix']);
$this->log->expects(static::once())
->willReturn($valid_prefix ? ['prefix_tag' => $prefix] : false);
$this->log->expects($valid_prefix ? static::once() : static::never())
->method('add')
->with('admin', static::anything(), static::anything(), 'ACP_LOG_PREFIX_ADDED', static::anything(), ['topic_prefix', 'Test Forum']);
$this->db->expects(static::once())
->with('admin', static::anything(), static::anything(), 'ACP_LOG_PREFIX_ADDED', static::anything(), [$prefix, 'Test Forum']);
$this->db->expects($valid_prefix ? static::once() : static::never())
->method('sql_fetchrow')
->willReturn(['forum_name' => 'Test Forum']);
}
Expand Down