Skip to content

Commit 19dfc27

Browse files
avandenbergheclaude
andcommitted
fix: set global \$config stub so smiley_text() does not fatal in unit tests
After fixing global \$user, smiley_text() now fatals on \$config['allow_smilies'] because global \$config is also null in unit test context. Set allow_smilies=0 so smiley_text() returns early without touching \$user->optionget() at all. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3f4da20 commit 19dfc27

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

tests/core/recenttopics_events_test.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,11 @@ private function make_rt_for_fill_template_events(\phpbb\event\dispatcher_interf
318318
// global to our test dispatcher so that call does not fatal.
319319
$GLOBALS['phpbb_dispatcher'] = $dispatcher;
320320

321-
// phpBB's real censor_text() → smiley_text() reads global $user and
322-
// calls $user->optionget(). Point it at the same user mock.
323-
$GLOBALS['user'] = $this->make_user_stub();
321+
// phpBB's real censor_text() → smiley_text() reads global $config and
322+
// $user. Set both so neither access fatals in unit test context.
323+
// allow_smilies=0 short-circuits smiley_text() before optionget() runs.
324+
$GLOBALS['config'] = ['allow_smilies' => 0];
325+
$GLOBALS['user'] = $this->make_user_stub();
324326

325327
return $rt;
326328
}
@@ -645,7 +647,8 @@ public function test_modify_topictitle_prefix_is_applied_to_template_var()
645647
$this->set_private($rt, 'total_topics_limit', 100);
646648

647649
$GLOBALS['phpbb_dispatcher'] = $dispatcher;
648-
$GLOBALS['user'] = $this->make_user_stub();
650+
$GLOBALS['config'] = ['allow_smilies' => 0];
651+
$GLOBALS['user'] = $this->make_user_stub();
649652

650653
$this->call_private($rt, 'fill_template', ['recent_topics', [], 1]);
651654

@@ -773,7 +776,8 @@ public function test_modify_tpl_ary_added_key_reaches_template()
773776
$this->set_private($rt, 'total_topics_limit', 100);
774777

775778
$GLOBALS['phpbb_dispatcher'] = $dispatcher;
776-
$GLOBALS['user'] = $this->make_user_stub();
779+
$GLOBALS['config'] = ['allow_smilies' => 0];
780+
$GLOBALS['user'] = $this->make_user_stub();
777781

778782
$this->call_private($rt, 'fill_template', ['recent_topics', [], 1]);
779783

0 commit comments

Comments
 (0)