Skip to content

Commit 3f4da20

Browse files
avandenbergheclaude
andcommitted
fix: set global \$user stub so censor_text() does not fatal in unit tests
phpBB's real censor_text() calls smiley_text() which reads global \$user and calls optionget(). In unit test context global \$user is null, causing a fatal error in all fill_template-based event contract tests. Point the global at the existing make_user_stub() mock before each fill_template call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 69c043e commit 3f4da20

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tests/core/recenttopics_events_test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ 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();
324+
321325
return $rt;
322326
}
323327

@@ -641,6 +645,7 @@ public function test_modify_topictitle_prefix_is_applied_to_template_var()
641645
$this->set_private($rt, 'total_topics_limit', 100);
642646

643647
$GLOBALS['phpbb_dispatcher'] = $dispatcher;
648+
$GLOBALS['user'] = $this->make_user_stub();
644649

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

@@ -768,6 +773,7 @@ public function test_modify_tpl_ary_added_key_reaches_template()
768773
$this->set_private($rt, 'total_topics_limit', 100);
769774

770775
$GLOBALS['phpbb_dispatcher'] = $dispatcher;
776+
$GLOBALS['user'] = $this->make_user_stub();
771777

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

0 commit comments

Comments
 (0)