From 9304889c8339086f4befe50d28811e3a1b906f69 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Mon, 17 Jul 2023 13:29:00 +0300 Subject: [PATCH] Fix conflict with Cyr2Lat. --- .../Settings/Abstracts/SettingsBaseTest.php | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/.tests/php/unit/Settings/Abstracts/SettingsBaseTest.php b/.tests/php/unit/Settings/Abstracts/SettingsBaseTest.php index 094421b5..620f1bbe 100644 --- a/.tests/php/unit/Settings/Abstracts/SettingsBaseTest.php +++ b/.tests/php/unit/Settings/Abstracts/SettingsBaseTest.php @@ -48,8 +48,10 @@ public function test_constructor( $is_tab ) { if ( $is_tab ) { WP_Mock::expectActionNotAdded( 'current_screen', [ $subject, 'setup_tabs_section' ] ); + WP_Mock::expectActionNotAdded( 'admin_menu', [ $subject, 'add_settings_page' ] ); } else { WP_Mock::expectActionAdded( 'current_screen', [ $subject, 'setup_tabs_section' ], 9 ); + WP_Mock::expectActionAdded( 'admin_menu', [ $subject, 'add_settings_page' ] ); } $subject->shouldReceive( 'init' )->once()->with(); @@ -154,7 +156,6 @@ public function test_init_hooks() { [ $subject, 'add_settings_link' ] ); - WP_Mock::expectActionAdded( 'admin_menu', [ $subject, 'add_settings_page' ] ); WP_Mock::expectActionAdded( 'current_screen', [ $subject, 'setup_fields' ] ); WP_Mock::expectActionAdded( 'current_screen', [ $subject, 'setup_sections' ], 11 ); @@ -694,7 +695,8 @@ public function test_tabs_callback() { /** * Test is_tab_active(). * - * @param string|null $input $_GET['tab']. + * @param string|null $on_page $_GET['page'] === own option page. + * @param string|null $input_tab $_GET['tab']. * @param string|null $referer_tab Tab name from referer. * @param bool $is_tab Is tab. * @param string $class_name Class name. @@ -702,7 +704,10 @@ public function test_tabs_callback() { * * @dataProvider dp_test_is_tab_active */ - public function test_is_tab_active( $input, $referer_tab, $is_tab, $class_name, $expected ) { + public function test_is_tab_active( $on_page, $input_tab, $referer_tab, $is_tab, $class_name, $expected ) { + $option_page = 'own-option-page'; + $input_page = $on_page ? $option_page : 'some-page'; + $tab = Mockery::mock( SettingsBase::class )->makePartial(); $tab->shouldAllowMockingProtectedMethods(); $tab->shouldReceive( 'is_tab' )->with()->andReturn( $is_tab ); @@ -711,16 +716,25 @@ public function test_is_tab_active( $input, $referer_tab, $is_tab, $class_name, $subject = Mockery::mock( SettingsBase::class )->makePartial(); $subject->shouldAllowMockingProtectedMethods(); $subject->shouldReceive( 'get_tab_name_from_referer' )->andReturn( $referer_tab ); + $subject->shouldReceive( 'option_page' )->andReturn( $option_page ); FunctionMocker::replace( 'filter_input', - static function ( $type, $name, $filter ) use ( $input ) { + static function ( $type, $name, $filter ) use ( $input_page, $input_tab ) { + if ( + INPUT_GET === $type && + 'page' === $name && + FILTER_SANITIZE_FULL_SPECIAL_CHARS === $filter + ) { + return $input_page; + } + if ( INPUT_GET === $type && 'tab' === $name && FILTER_SANITIZE_FULL_SPECIAL_CHARS === $filter ) { - return $input; + return $input_tab; } return null; @@ -737,12 +751,13 @@ static function ( $type, $name, $filter ) use ( $input ) { */ public function dp_test_is_tab_active() { return [ - 'No input, not a tab' => [ null, null, false, 'any_class_name', true ], - 'No input, tab' => [ null, 'integrations', true, 'any_class_name', false ], - 'Wrong input, not a tab' => [ 'wrong', null, false, 'General', false ], - 'Wrong input, tab' => [ 'wrong', 'integrations', true, 'General', false ], - 'Proper input, not a tab' => [ 'general', null, false, 'General', true ], - 'Proper input, tab' => [ 'general', 'integrations', true, 'General', true ], + 'No input, not on page' => [ false, null, null, false, 'any_class_name', false ], + 'No input, not a tab' => [ true, null, null, false, 'any_class_name', true ], + 'No input, tab' => [ true, null, 'integrations', true, 'any_class_name', false ], + 'Wrong input, not a tab' => [ true, 'wrong', null, false, 'General', false ], + 'Wrong input, tab' => [ true, 'wrong', 'integrations', true, 'General', false ], + 'Proper input, not a tab' => [ true, 'general', null, false, 'General', true ], + 'Proper input, tab' => [ true, 'general', 'integrations', true, 'General', true ], ]; }