@@ -25,21 +25,23 @@ class add_prefix_test extends admin_controller_base
2525 */
2626 public function data_add_prefix ()
2727 {
28- return array (
29- array (true , true ),
30- array (true , false ),
31- array (false , false ),
32- );
28+ return [
29+ ['' , true , true ],
30+ ['topic_prefix1 ' , true , true ],
31+ ['topic_prefix2 ' , true , false ],
32+ ['topic_prefix3 ' , false , false ],
33+ ];
3334 }
3435
3536 /**
3637 * Test add_prefix()
3738 *
3839 * @dataProvider data_add_prefix
40+ * @param $prefix
3941 * @param $submit
4042 * @param $valid_form
4143 */
42- public function test_add_prefix ($ submit , $ valid_form )
44+ public function test_add_prefix ($ prefix , $ submit , $ valid_form )
4345 {
4446 if ($ submit )
4547 {
@@ -52,20 +54,26 @@ public function test_add_prefix($submit, $valid_form)
5254 if (!$ valid_form )
5355 {
5456 // Throws E_WARNING in PHP 8.0+ and E_USER_WARNING in earlier versions
55- $ exceptionName = version_compare ( PHP_VERSION , ' 8.0 ' , ' < ' ) ? \PHPUnit \Framework \Error \Error::class : \PHPUnit \Framework \Error \Warning::class;
56- $ errno = version_compare ( PHP_VERSION , ' 8.0 ' , ' < ' ) ? E_USER_WARNING : E_WARNING ;
57+ $ exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit \Framework \Error \Error::class : \PHPUnit \Framework \Error \Warning::class;
58+ $ errno = PHP_VERSION_ID < 80000 ? E_USER_WARNING : E_WARNING ;
5759 $ this ->expectException ($ exceptionName );
5860 $ this ->expectExceptionCode ($ errno );
5961 }
6062 else
6163 {
64+ $ valid_prefix = $ prefix !== '' ;
65+ $ this ->request ->expects (static ::once ())
66+ ->method ('variable ' )
67+ ->willReturnMap ([
68+ ['prefix_tag ' , '' , true , \phpbb \request \request_interface::REQUEST , $ prefix ],
69+ ]);
6270 $ this ->manager ->expects (static ::once ())
6371 ->method ('add_prefix ' )
64- ->willReturn (['prefix_tag ' => ' topic_prefix ' ] );
65- $ this ->log ->expects (static ::once ())
72+ ->willReturn ($ valid_prefix ? ['prefix_tag ' => $ prefix ] : false );
73+ $ this ->log ->expects ($ valid_prefix ? static ::once () : static :: never ())
6674 ->method ('add ' )
67- ->with ('admin ' , static ::anything (), static ::anything (), 'ACP_LOG_PREFIX_ADDED ' , static ::anything (), [' topic_prefix ' , 'Test Forum ' ]);
68- $ this ->db ->expects (static ::once ())
75+ ->with ('admin ' , static ::anything (), static ::anything (), 'ACP_LOG_PREFIX_ADDED ' , static ::anything (), [$ prefix , 'Test Forum ' ]);
76+ $ this ->db ->expects ($ valid_prefix ? static ::once () : static :: never ())
6977 ->method ('sql_fetchrow ' )
7078 ->willReturn (['forum_name ' => 'Test Forum ' ]);
7179 }
0 commit comments