From c0b90e919e6e5a24ac7bf8df07c3a77cfce4e904 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 18 Jan 2024 09:42:11 -0800 Subject: [PATCH] Handle empty prefix tag on form entry in ACP Signed-off-by: Matt Friedman --- controller/admin_controller.php | 6 +++++- tests/controller/add_prefix_test.php | 28 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/controller/admin_controller.php b/controller/admin_controller.php index 2fc85f6..c02b29e 100644 --- a/controller/admin_controller.php +++ b/controller/admin_controller.php @@ -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) + { + $this->log($prefix['prefix_tag'], 'ACP_LOG_PREFIX_ADDED'); + } } } diff --git a/tests/controller/add_prefix_test.php b/tests/controller/add_prefix_test.php index 09978bd..0fa9d55 100644 --- a/tests/controller/add_prefix_test.php +++ b/tests/controller/add_prefix_test.php @@ -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) { @@ -59,13 +61,19 @@ public function test_add_prefix($submit, $valid_form) } 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']); }