Skip to content

Commit

Permalink
Fix conflict with Cyr2Lat.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jul 17, 2023
1 parent a40982d commit 9304889
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions .tests/php/unit/Settings/Abstracts/SettingsBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -694,15 +695,19 @@ 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.
* @param bool $expected Expected.
*
* @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 );
Expand All @@ -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;
Expand All @@ -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 ],
];
}

Expand Down

0 comments on commit 9304889

Please sign in to comment.