From 6bcede6d4d5d1038d27da62dcb8a7352bc6a1beb Mon Sep 17 00:00:00 2001 From: KAGG Design Date: Tue, 7 Sep 2021 19:14:28 +0300 Subject: [PATCH 1/7] Allow working on frontend. Do not add get_terms_args filter on frontend. --- src/php/class-main.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/php/class-main.php b/src/php/class-main.php index db3a499..8a36642 100644 --- a/src/php/class-main.php +++ b/src/php/class-main.php @@ -112,12 +112,7 @@ class Main { * Main constructor. */ public function __construct() { - $this->request = new Request(); - - if ( ! $this->request->is_allowed() ) { - return; - } - + $this->request = new Request(); $this->settings = new Settings(); $this->admin_notices = new Admin_Notices(); $requirements = new Requirements( $this->settings, $this->admin_notices ); @@ -149,10 +144,6 @@ public function __construct() { * @noinspection PhpUndefinedClassInspection */ public function init() { - if ( ! $this->request->is_allowed() ) { - return; - } - if ( $this->request->is_cli() ) { try { /** @@ -177,7 +168,10 @@ public function init_hooks() { add_filter( 'sanitize_file_name', [ $this, 'sanitize_filename' ], 10, 2 ); add_filter( 'wp_insert_post_data', [ $this, 'sanitize_post_name' ], 10, 2 ); add_filter( 'pre_insert_term', [ $this, 'pre_insert_term_filter' ], PHP_INT_MAX, 2 ); - add_filter( 'get_terms_args', [ $this, 'get_terms_args_filter' ], PHP_INT_MAX, 2 ); + + if ( ! $this->request->is_frontend() ) { + add_filter( 'get_terms_args', [ $this, 'get_terms_args_filter' ], PHP_INT_MAX, 2 ); + } if ( class_exists( Polylang::class ) ) { add_filter( 'locale', [ $this, 'pll_locale_filter' ] ); From f07f1c63d9b85c0c86591f607a996695c7f9dcd3 Mon Sep 17 00:00:00 2001 From: KAGG Design Date: Tue, 7 Sep 2021 19:51:42 +0300 Subject: [PATCH 2/7] Update tests for Main class. --- tests/phpunit/tests/class-test-main.php | 79 +++++++------------------ 1 file changed, 23 insertions(+), 56 deletions(-) diff --git a/tests/phpunit/tests/class-test-main.php b/tests/phpunit/tests/class-test-main.php index 01fb9be..0319b99 100644 --- a/tests/phpunit/tests/class-test-main.php +++ b/tests/phpunit/tests/class-test-main.php @@ -60,16 +60,10 @@ public function tearDown(): void { public function test_constructor() { $classname = Main::class; - // Test when requirements are met and allowed request. + // Test when requirements are met. $requirements_met = true; - $is_allowed = true; $request = Mockery::mock( 'overload:' . Request::class ); - $request->shouldReceive( 'is_allowed' )->with()->andReturnUsing( - function () use ( &$is_allowed ) { - return $is_allowed; - } - ); $request->shouldReceive( 'is_cli' )->with()->andReturn( true ); Mockery::mock( 'overload:' . Settings::class ); @@ -124,26 +118,6 @@ function () use ( &$requirements_met ) { self::assertNull( $this->get_protected_property( $mock, 'converter' ) ); self::assertNull( $this->get_protected_property( $mock, 'cli' ) ); self::assertNull( $this->get_protected_property( $mock, 'acf' ) ); - - // Test on not allowed request. - $is_allowed = false; - - // Get mock, without the constructor being called. - $mock = $this->getMockBuilder( $classname )->disableOriginalConstructor()->getMock(); - - // Now call the constructor. - $reflected_class = new ReflectionClass( $classname ); - $constructor = $reflected_class->getConstructor(); - $constructor->invoke( $mock ); - - self::assertInstanceOf( Request::class, $this->get_protected_property( $mock, 'request' ) ); - self::assertNull( $this->get_protected_property( $mock, 'settings' ) ); - self::assertNull( $this->get_protected_property( $mock, 'admin_notices' ) ); - self::assertNull( $this->get_protected_property( $mock, 'process_all_posts' ) ); - self::assertNull( $this->get_protected_property( $mock, 'process_all_terms' ) ); - self::assertNull( $this->get_protected_property( $mock, 'converter' ) ); - self::assertNull( $this->get_protected_property( $mock, 'cli' ) ); - self::assertNull( $this->get_protected_property( $mock, 'acf' ) ); } /** @@ -153,7 +127,6 @@ function () use ( &$requirements_met ) { */ public function test_init() { $request = Mockery::mock( Request::class ); - $request->shouldReceive( 'is_allowed' )->andReturn( true ); $request->shouldReceive( 'is_cli' )->andReturn( false ); $subject = Mockery::mock( Main::class )->makePartial(); @@ -163,22 +136,6 @@ public function test_init() { $subject->init(); } - /** - * Test init() on allowed request. - * - * @throws ReflectionException ReflectionException. - */ - public function test_init_on_allowed_request() { - $request = Mockery::mock( Request::class ); - $request->shouldReceive( 'is_allowed' )->andReturn( false ); - - $subject = Mockery::mock( Main::class )->makePartial(); - $this->set_protected_property( $subject, 'request', $request ); - $subject->shouldReceive( 'init_hooks' )->never(); - - $subject->init(); - } - /** * Test init() with CLI when CLI throws an Exception * @@ -186,7 +143,6 @@ public function test_init_on_allowed_request() { */ public function test_init_with_cli_error() { $request = Mockery::mock( Request::class ); - $request->shouldReceive( 'is_allowed' )->andReturn( true ); $request->shouldReceive( 'is_cli' )->andReturn( true ); $subject = Mockery::mock( Main::class )->makePartial(); @@ -213,7 +169,6 @@ function () { */ public function test_init_with_cli() { $request = Mockery::mock( Request::class ); - $request->shouldReceive( 'is_allowed' )->andReturn( true ); $request->shouldReceive( 'is_cli' )->andReturn( true ); $subject = Mockery::mock( Main::class )->makePartial(); @@ -235,20 +190,25 @@ public function test_init_with_cli() { * * @param boolean $polylang Polylang is active. * @param boolean $sitepress WPML is active. + * @param boolean $frontend It is frontend. * * @dataProvider dp_test_init_hooks * @throws ReflectionException ReflectionException. */ - public function test_init_hooks( $polylang, $sitepress ) { + public function test_init_hooks( $polylang, $sitepress, $frontend ) { $wpml_locale = 'en_US'; + $request = Mockery::mock( Request::class ); + $subject = Mockery::mock( Main::class )->makePartial()->shouldAllowMockingProtectedMethods(); + $request->shouldReceive( 'is_frontend' )->andReturn( $frontend ); + + $this->set_protected_property( $subject, 'request', $request ); WP_Mock::expectFilterAdded( 'sanitize_title', [ $subject, 'sanitize_title' ], 9, 3 ); WP_Mock::expectFilterAdded( 'sanitize_file_name', [ $subject, 'sanitize_filename' ], 10, 2 ); WP_Mock::expectFilterAdded( 'wp_insert_post_data', [ $subject, 'sanitize_post_name' ], 10, 2 ); WP_Mock::expectFilterAdded( 'pre_insert_term', [ $subject, 'pre_insert_term_filter' ], PHP_INT_MAX, 2 ); - WP_Mock::expectFilterAdded( 'get_terms_args', [ $subject, 'get_terms_args_filter' ], PHP_INT_MAX, 2 ); FunctionMocker::replace( 'class_exists', @@ -265,6 +225,12 @@ function ( $class ) use ( $polylang, $sitepress ) { } ); + if ( $frontend ) { + WP_Mock::expectFilterNotAdded( 'get_terms_args', [ $subject, 'get_terms_args_filter' ] ); + } else { + WP_Mock::expectFilterAdded( 'get_terms_args', [ $subject, 'get_terms_args_filter' ], PHP_INT_MAX, 2 ); + } + if ( $polylang ) { WP_Mock::expectFilterAdded( 'locale', [ $subject, 'pll_locale_filter' ] ); } else { @@ -299,10 +265,14 @@ function ( $class ) use ( $polylang, $sitepress ) { */ public function dp_test_init_hooks() { return [ - [ false, false ], - [ true, false ], - [ false, true ], - [ true, true ], + [ false, false, false ], + [ false, false, true ], + [ false, true, false ], + [ false, true, true ], + [ true, false, false ], + [ true, false, true ], + [ true, true, false ], + [ true, true, true ], ]; } @@ -943,8 +913,6 @@ public function dp_test_sanitize_post_name() { /** * Test pll_locale_filter() with REST. - * - * @throws ReflectionException ReflectionException. */ public function test_pll_locale_filter_with_rest() { $locale = 'en_US'; @@ -992,11 +960,10 @@ function () use ( &$data ) { * * @throws ReflectionException ReflectionException. */ - public function test_pll_locale_filter_on_allowed_request() { + public function test_pll_locale_filter_on_frontend() { $locale = 'en_US'; $request = Mockery::mock( Request::class ); - $request->shouldReceive( 'is_rest' )->andReturn( false ); $subject = Mockery::mock( Main::class )->makePartial(); $this->set_protected_property( $subject, 'request', $request ); From 0a1884bd594d23247d9fa1c36281dfbf78eb7da7 Mon Sep 17 00:00:00 2001 From: KAGG Design Date: Tue, 7 Sep 2021 19:53:22 +0300 Subject: [PATCH 3/7] Remove unused code in Request class and update tests. --- src/php/class-request.php | 23 ----------- tests/phpunit/tests/class-test-request.php | 48 ---------------------- 2 files changed, 71 deletions(-) diff --git a/src/php/class-request.php b/src/php/class-request.php index 4f83ff8..af47113 100644 --- a/src/php/class-request.php +++ b/src/php/class-request.php @@ -14,15 +14,6 @@ */ class Request { - /** - * Is allowed request for plugin to work. - * - * @return bool - */ - public function is_allowed() { - return ! $this->is_frontend() || ( $this->is_frontend() && $this->is_post() ); - } - /** * Is frontend. * @@ -97,18 +88,4 @@ protected function get_rest_route() { return $is_rest ? substr( $current_path, strlen( $rest_path ) ) : ''; } - - /** - * If current request is POST. - * - * @return bool - */ - public function is_post() { - $request_method = filter_var( - isset( $_SERVER['REQUEST_METHOD'] ) ? wp_unslash( $_SERVER['REQUEST_METHOD'] ) : '', - FILTER_SANITIZE_STRING - ); - - return 'POST' === $request_method; - } } diff --git a/tests/phpunit/tests/class-test-request.php b/tests/phpunit/tests/class-test-request.php index 28a43ff..0f67f5b 100644 --- a/tests/phpunit/tests/class-test-request.php +++ b/tests/phpunit/tests/class-test-request.php @@ -33,38 +33,6 @@ public function tearDown(): void { parent::tearDown(); } - /** - * Test is_allowed(). - * - * @param bool $frontend Is frontend. - * @param bool $post Is POST. - * @param bool $expected Expected. - * - * @dataProvider dp_test_is_allowed - * @noinspection PhpUndefinedMethodInspection - */ - public function test_is_allowed( $frontend, $post, $expected ) { - $subject = Mockery::mock( Request::class )->makePartial()->shouldAllowMockingProtectedMethods(); - $subject->shouldReceive( 'is_frontend' )->with()->andReturn( $frontend ); - $subject->shouldReceive( 'is_post' )->with()->andReturn( $post ); - - self::assertSame( $expected, $subject->is_allowed() ); - } - - /** - * Data provider for test_is_allowed(). - * - * @return array - */ - public function dp_test_is_allowed() { - return [ - [ false, false, true ], - [ false, true, true ], - [ true, false, false ], - [ true, true, true ], - ]; - } - /** * Test is_frontend(). * @@ -271,20 +239,4 @@ public function dp_test_get_rest_route() { 'some request' => [ '/some-request', '' ], ]; } - - /** - * Test is_post(). - */ - public function test_is_post() { - WP_Mock::passthruFunction( 'wp_unslash' ); - - $subject = new Request(); - self::assertFalse( $subject->is_post() ); - - $_SERVER['REQUEST_METHOD'] = 'some'; - self::assertFalse( $subject->is_post() ); - - $_SERVER['REQUEST_METHOD'] = 'POST'; - self::assertTrue( $subject->is_post() ); - } } From 4ffafe6859723be293b98a4ecd9c4629da300a83 Mon Sep 17 00:00:00 2001 From: KAGG Design Date: Tue, 7 Sep 2021 20:35:42 +0300 Subject: [PATCH 4/7] Fix endless loop with Elementor and WPML in wpml_language_has_switched filter. --- src/php/class-main.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/php/class-main.php b/src/php/class-main.php index 8a36642..2d17ea4 100644 --- a/src/php/class-main.php +++ b/src/php/class-main.php @@ -108,6 +108,13 @@ class Main { */ protected $wpml_locale; + /** + * WPML languages. + * + * @var array + */ + protected $wpml_languages; + /** * Main constructor. */ @@ -627,10 +634,14 @@ public function wpml_locale_filter( $locale ) { * @return string|null */ protected function get_wpml_locale() { - $language_code = wpml_get_current_language(); - $languages = apply_filters( 'wpml_active_languages', null ); + $language_code = wpml_get_current_language(); + $this->wpml_languages = (array) apply_filters( 'wpml_active_languages', [] ); - return isset( $languages[ $language_code ] ) ? $languages[ $language_code ]['default_locale'] : null; + return ( + isset( $this->wpml_languages[ $language_code ] ) ? + $this->wpml_languages[ $language_code ]['default_locale'] : + null + ); } /** @@ -643,9 +654,12 @@ protected function get_wpml_locale() { * @noinspection PhpUnusedParameterInspection */ public function wpml_language_has_switched( $language_code, $cookie_lang, $original_language ) { - $languages = apply_filters( 'wpml_active_languages', null ); + $language_code = (string) $language_code; - $this->wpml_locale = isset( $languages[ $language_code ] ) ? $languages[ $language_code ]['default_locale'] : null; + $this->wpml_locale = + isset( $this->wpml_languages[ $language_code ] ) ? + $this->wpml_languages[ $language_code ]['default_locale'] : + null; } /** From 52911972e1c47bb39c7bdbc90c9143cc5090e793 Mon Sep 17 00:00:00 2001 From: KAGG Design Date: Tue, 7 Sep 2021 20:50:06 +0300 Subject: [PATCH 5/7] Add tests for Elementor + WPML issue. --- tests/phpunit/tests/class-test-main.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/class-test-main.php b/tests/phpunit/tests/class-test-main.php index 0319b99..71d0c13 100644 --- a/tests/phpunit/tests/class-test-main.php +++ b/tests/phpunit/tests/class-test-main.php @@ -1183,6 +1183,7 @@ public function test_wpml_locale_filter() { * @param string $expected Expected. * * @dataProvider dp_test_wpml_locale_filter + * @throws ReflectionException ReflectionException. */ public function test_get_wpml_locale( $locale, $language_code, $expected ) { $languages = [ @@ -1241,11 +1242,15 @@ public function test_get_wpml_locale( $locale, $language_code, $expected ) { ]; WP_Mock::userFunction( 'wpml_get_current_language' )->times( 1 )->with()->andReturn( $language_code ); - WP_Mock::onFilter( 'wpml_active_languages' )->with( null )->reply( $languages ); + WP_Mock::onFilter( 'wpml_active_languages' )->with( [] )->reply( $languages ); $subject = Mockery::mock( Main::class )->makePartial(); + self::assertNull( $this->get_protected_property( $subject, 'wpml_languages' ) ); + self::assertSame( $expected, $subject->get_wpml_locale( $locale ) ); + + self::assertSame( $languages, $this->get_protected_property( $subject, 'wpml_languages' ) ); } /** @@ -1325,9 +1330,8 @@ public function test_wpml_language_has_switched( $language_code, $expected ) { ], ]; - WP_Mock::onFilter( 'wpml_active_languages' )->with( null )->reply( $languages ); - $subject = Mockery::mock( Main::class )->makePartial(); + $this->set_protected_property( $subject, 'wpml_languages', $languages ); $subject->wpml_language_has_switched( $language_code, 'some cookie', 'en_US' ); self::assertSame( $expected, $this->get_protected_property( $subject, 'wpml_locale' ) ); From 4453a6ce412865e7ef5c34619b7dc0a43aea0534 Mon Sep 17 00:00:00 2001 From: KAGG Design Date: Tue, 7 Sep 2021 20:54:16 +0300 Subject: [PATCH 6/7] Bump up version to 5.2.4. --- cyr-to-lat.php | 4 ++-- readme.txt | 6 +++++- tests/phpunit/bootstrap.php | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cyr-to-lat.php b/cyr-to-lat.php index e331bee..115e957 100644 --- a/cyr-to-lat.php +++ b/cyr-to-lat.php @@ -10,7 +10,7 @@ * Plugin Name: Cyr-To-Lat * Plugin URI: https://wordpress.org/plugins/cyr2lat/ * Description: Convert Non-Latin characters in post and term slugs to Latin characters. Useful for creating human-readable URLs. Based on the original plugin by Anton Skorobogatov. - * Version: 5.2.3 + * Version: 5.2.4 * Requires at least: 5.1 * Requires PHP: 5.6.20 * Author: Sergey Biryukov, Mikhail Kobzarev, Igor Gergel @@ -36,7 +36,7 @@ /** * Plugin version. */ -define( 'CYR_TO_LAT_VERSION', '5.2.3' ); +define( 'CYR_TO_LAT_VERSION', '5.2.4' ); /** * Path to the plugin dir. diff --git a/readme.txt b/readme.txt index 194fb48..5708963 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: SergeyBiryukov, mihdan, karevn, webvitaly, kaggdesign Tags: cyrillic, belorussian, ukrainian, bulgarian, macedonian, georgian, kazakh, latin, l10n, russian, cyr-to-lat, cyr2lat, rustolat, slugs, translations, transliteration Requires at least: 5.1 Tested up to: 5.8 -Stable tag: 5.2.3 +Stable tag: 5.2.4 Requires PHP: 5.6.20 Convert Non-Latin characters in post, page and term slugs to Latin characters. @@ -188,6 +188,10 @@ Yes you can! == Changelog == += 5.2.4 (07.09.2021) = +* Fix issue with not showing WooCommerce variable product attributes. +* Fix issue with Elementor and WPML, endless loop. + = 5.2.3 (07.09.2021) = * Fix issue with WP Foro plugin - transliterate topic slug when created on frontend. * Fix bug with Polylang on REST request. diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index 08d8f45..c1e0a98 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -42,7 +42,7 @@ /** * Plugin version. */ -const CYR_TO_LAT_TEST_VERSION = '5.2.3'; +const CYR_TO_LAT_TEST_VERSION = '5.2.4'; /** * Path to the plugin dir. From e159f75137c14048e71a897ea8808be1ebe3e876 Mon Sep 17 00:00:00 2001 From: KAGG Design Date: Tue, 7 Sep 2021 21:09:53 +0300 Subject: [PATCH 7/7] Polishing of WPCS. --- src/php/class-main.php | 2 -- .../Settings/Abstracts/SettingsBaseTest.php | 7 +++--- tests/phpunit/Settings/ConverterTest.php | 2 -- tests/phpunit/Settings/SettingsTest.php | 1 - tests/phpunit/Settings/TablesTest.php | 2 -- tests/phpunit/bootstrap.php | 23 ++++++++----------- .../classes/class-cyr-to-lat-testcase.php | 6 +++++ .../class-test-post-conversion-process.php | 3 +++ .../class-test-term-conversion-process.php | 3 +++ .../tests/class-test-admin-notices.php | 2 +- tests/phpunit/tests/class-test-converter.php | 3 +++ .../phpunit/tests/class-test-plugin-file.php | 4 +++- .../phpunit/tests/class-test-requirements.php | 9 ++------ 13 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/php/class-main.php b/src/php/class-main.php index 2d17ea4..e5dfd04 100644 --- a/src/php/class-main.php +++ b/src/php/class-main.php @@ -373,8 +373,6 @@ public function transliterate( $string ) { * @link https://kagg.eu/how-to-catch-gutenberg/ * * @return bool - * - * @noinspection PhpIncludeInspection */ private function is_classic_editor_plugin_active() { // @codeCoverageIgnoreStart diff --git a/tests/phpunit/Settings/Abstracts/SettingsBaseTest.php b/tests/phpunit/Settings/Abstracts/SettingsBaseTest.php index af47fe0..95effe1 100644 --- a/tests/phpunit/Settings/Abstracts/SettingsBaseTest.php +++ b/tests/phpunit/Settings/Abstracts/SettingsBaseTest.php @@ -199,6 +199,7 @@ public function test_tab_name() { * Test get_class_name(). * * @throws ReflectionException ReflectionException. + * @noinspection PhpParamsInspection */ public function test_get_class_name() { $subject = Mockery::mock( SettingsBase::class )->makePartial(); @@ -463,7 +464,6 @@ public function test_base_admin_enqueue_scripts() { * * @dataProvider dp_test_setup_sections * @throws ReflectionException ReflectionException. - * @noinspection NullCoalescingOperatorCanBeUsedInspection */ public function test_setup_sections( $tabs ) { $tab_option_page = 'cyr-to-lat'; @@ -664,7 +664,6 @@ public function test_get_tabs() { * Test get_active_tab(). * * @throws ReflectionException ReflectionException. - * @noinspection JsonEncodingApiUsageInspection */ public function test_get_active_tab() { $tab = Mockery::mock( SettingsBase::class )->makePartial()->shouldAllowMockingProtectedMethods(); @@ -1624,7 +1623,7 @@ public function test_load_plugin_text_domain() { * Test is_options_screen(). * * @param mixed $current_screen Current admin screen. - * @param boolean $is_main_menu_page It it the main menu page. + * @param boolean $is_main_menu_page It is the main menu page. * @param boolean $expected Expected result. * * @dataProvider dp_test_is_options_screen @@ -1648,7 +1647,7 @@ public function test_is_options_screen( $current_screen, $is_main_menu_page, $ex } /** - * Data provider for test_is_options_screen(0. + * Data provider for test_is_options_screen(). * * @return array */ diff --git a/tests/phpunit/Settings/ConverterTest.php b/tests/phpunit/Settings/ConverterTest.php index 34f9426..97df24a 100644 --- a/tests/phpunit/Settings/ConverterTest.php +++ b/tests/phpunit/Settings/ConverterTest.php @@ -12,11 +12,9 @@ namespace Cyr_To_Lat\Tests\Settings; -use Cyr_To_Lat\Settings\Abstracts\SettingsBase; use Cyr_To_Lat\Settings\Converter; use Cyr_To_Lat\Cyr_To_Lat_TestCase; use Mockery; -use ReflectionClass; use ReflectionException; use tad\FunctionMocker\FunctionMocker; use WP_Mock; diff --git a/tests/phpunit/Settings/SettingsTest.php b/tests/phpunit/Settings/SettingsTest.php index 13e7f26..317f8e9 100644 --- a/tests/phpunit/Settings/SettingsTest.php +++ b/tests/phpunit/Settings/SettingsTest.php @@ -55,7 +55,6 @@ public function test_constructor() { * @preserveGlobalState disabled * * @throws ReflectionException ReflectionException. - * @noinspection JsonEncodingApiUsageInspection */ public function test_init_and_screen_ids() { $subject = Mockery::mock( Settings::class )->makePartial()->shouldAllowMockingProtectedMethods(); diff --git a/tests/phpunit/Settings/TablesTest.php b/tests/phpunit/Settings/TablesTest.php index ab6b993..d4be45b 100644 --- a/tests/phpunit/Settings/TablesTest.php +++ b/tests/phpunit/Settings/TablesTest.php @@ -160,8 +160,6 @@ public function test_init_locales() { /** * Test init_form_fields() * - * @noinspection PhpSwitchCanBeReplacedWithMatchExpressionInspection - * * @throws ReflectionException ReflectionException. */ public function test_init_form_fields() { diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index c1e0a98..879dbb2 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -10,11 +10,6 @@ use tad\FunctionMocker\FunctionMocker; -/** - * Plugin test dir. - */ -define( 'PLUGIN_TESTS_DIR', __DIR__ ); - /** * Plugin main file. */ @@ -28,7 +23,7 @@ /** * Kilobytes in bytes. */ -define( 'KB_IN_BYTES', 1024 ); +const KB_IN_BYTES = 1024; require_once PLUGIN_PATH . '/vendor/autoload.php'; @@ -47,42 +42,42 @@ /** * Path to the plugin dir. */ -define( 'CYR_TO_LAT_TEST_PATH', PLUGIN_PATH ); +const CYR_TO_LAT_TEST_PATH = PLUGIN_PATH; /** * Plugin dir url. */ -define( 'CYR_TO_LAT_TEST_URL', 'http://site.org/wp-content/plugins/cyr2lat' ); +const CYR_TO_LAT_TEST_URL = 'https://site.org/wp-content/plugins/cyr2lat'; /** * Main plugin file. */ -define( 'CYR_TO_LAT_TEST_FILE', PLUGIN_MAIN_FILE ); +const CYR_TO_LAT_TEST_FILE = PLUGIN_MAIN_FILE; /** * Plugin prefix. */ -define( 'CYR_TO_LAT_TEST_PREFIX', 'cyr_to_lat' ); +const CYR_TO_LAT_TEST_PREFIX = 'cyr_to_lat'; /** * Post conversion action. */ -define( 'CYR_TO_LAT_TEST_POST_CONVERSION_ACTION', 'post_conversion_action' ); +const CYR_TO_LAT_TEST_POST_CONVERSION_ACTION = 'post_conversion_action'; /** * Term conversion action. */ -define( 'CYR_TO_LAT_TEST_TERM_CONVERSION_ACTION', 'term_conversion_action' ); +const CYR_TO_LAT_TEST_TERM_CONVERSION_ACTION = 'term_conversion_action'; /** * Minimum required php version. */ -define( 'CYR_TO_LAT_TEST_MINIMUM_PHP_REQUIRED_VERSION', '5.6' ); +const CYR_TO_LAT_TEST_MINIMUM_PHP_REQUIRED_VERSION = '5.6'; /** * Minimum required max_input_vars value. */ -define( 'CYR_TO_LAT_TEST_REQUIRED_MAX_INPUT_VARS', 1000 ); +const CYR_TO_LAT_TEST_REQUIRED_MAX_INPUT_VARS = 1000; FunctionMocker::init( [ diff --git a/tests/phpunit/classes/class-cyr-to-lat-testcase.php b/tests/phpunit/classes/class-cyr-to-lat-testcase.php index df995af..d500143 100644 --- a/tests/phpunit/classes/class-cyr-to-lat-testcase.php +++ b/tests/phpunit/classes/class-cyr-to-lat-testcase.php @@ -88,6 +88,9 @@ abstract class Cyr_To_Lat_TestCase extends TestCase { /** * Setup test + * + * @noinspection PhpLanguageLevelInspection + * @noinspection PhpUndefinedClassInspection */ public function setUp(): void { FunctionMocker::setUp(); @@ -131,6 +134,9 @@ function ( $name ) { /** * End test + * + * @noinspection PhpLanguageLevelInspection + * @noinspection PhpUndefinedClassInspection */ public function tearDown(): void { WP_Mock::tearDown(); diff --git a/tests/phpunit/tests/background-processes/class-test-post-conversion-process.php b/tests/phpunit/tests/background-processes/class-test-post-conversion-process.php index 63b5e54..ad8460a 100644 --- a/tests/phpunit/tests/background-processes/class-test-post-conversion-process.php +++ b/tests/phpunit/tests/background-processes/class-test-post-conversion-process.php @@ -29,6 +29,9 @@ class Test_Post_Conversion_Process extends Cyr_To_Lat_TestCase { /** * End test + * + * @noinspection PhpLanguageLevelInspection + * @noinspection PhpUndefinedClassInspection */ public function tearDown(): void { unset( $GLOBALS['wpdb'] ); diff --git a/tests/phpunit/tests/background-processes/class-test-term-conversion-process.php b/tests/phpunit/tests/background-processes/class-test-term-conversion-process.php index 0797e9c..bad5810 100644 --- a/tests/phpunit/tests/background-processes/class-test-term-conversion-process.php +++ b/tests/phpunit/tests/background-processes/class-test-term-conversion-process.php @@ -28,6 +28,9 @@ class Test_Term_Conversion_Process extends Cyr_To_Lat_TestCase { /** * End test + * + * @noinspection PhpLanguageLevelInspection + * @noinspection PhpUndefinedClassInspection */ public function tearDown(): void { unset( $GLOBALS['wpdb'] ); diff --git a/tests/phpunit/tests/class-test-admin-notices.php b/tests/phpunit/tests/class-test-admin-notices.php index fe53dc1..fd901e0 100644 --- a/tests/phpunit/tests/class-test-admin-notices.php +++ b/tests/phpunit/tests/class-test-admin-notices.php @@ -25,7 +25,7 @@ class Test_Admin_Notices extends Cyr_To_Lat_TestCase { * @noinspection NullPointerExceptionInspection */ public function test_constructor() { - $classname = __NAMESPACE__ . '\Admin_Notices'; + $classname = Admin_Notices::class; // Get mock, without the constructor being called. $mock = $this->getMockBuilder( $classname )->disableOriginalConstructor()->getMock(); diff --git a/tests/phpunit/tests/class-test-converter.php b/tests/phpunit/tests/class-test-converter.php index 7bc9fe7..92c7336 100644 --- a/tests/phpunit/tests/class-test-converter.php +++ b/tests/phpunit/tests/class-test-converter.php @@ -30,6 +30,9 @@ class Test_Converter extends Cyr_To_Lat_TestCase { /** * End test + * + * @noinspection PhpLanguageLevelInspection + * @noinspection PhpUndefinedClassInspection */ public function tearDown(): void { // phpcs:disable WordPress.Security.NonceVerification.Recommended diff --git a/tests/phpunit/tests/class-test-plugin-file.php b/tests/phpunit/tests/class-test-plugin-file.php index d6fb22b..cbc3f45 100644 --- a/tests/phpunit/tests/class-test-plugin-file.php +++ b/tests/phpunit/tests/class-test-plugin-file.php @@ -22,6 +22,9 @@ class Test_Cyr_To_Lat_Plugin_File extends Cyr_To_Lat_TestCase { /** * Tear down. + * + * @noinspection PhpLanguageLevelInspection + * @noinspection PhpUndefinedClassInspection */ public function tearDown(): void { unset( $GLOBALS['cyr_to_lat_plugin'] ); @@ -38,7 +41,6 @@ public function tearDown(): void { * * @runInSeparateProcess * @preserveGlobalState disabled - * @noinspection PhpIncludeInspection */ public function test_main_plugin_file() { $plugin_dir_url = 'http://test.test/wp-content/plugins/cyr2lat/'; diff --git a/tests/phpunit/tests/class-test-requirements.php b/tests/phpunit/tests/class-test-requirements.php index 20c17ab..3f613f0 100644 --- a/tests/phpunit/tests/class-test-requirements.php +++ b/tests/phpunit/tests/class-test-requirements.php @@ -31,6 +31,8 @@ class Test_Requirements extends Cyr_To_Lat_TestCase { /** * Tear down. + * + * @noinspection PhpLanguageLevelInspection */ public function tearDown(): void { // phpcs:ignore WordPress.Security.NonceVerification.Recommended @@ -133,8 +135,6 @@ function ( $arg ) { /** * Test if are_requirements_met() returns true when requirements met. - * - * @noinspection PhpSwitchCanBeReplacedWithMatchExpressionInspection */ public function test_requirements_met() { $settings = Mockery::mock( Settings::class ); @@ -180,8 +180,6 @@ function ( $arg ) { /** * Test if are_requirements_met() returns false when php requirements not met. - * - * @noinspection PhpSwitchCanBeReplacedWithMatchExpressionInspection */ public function test_php_requirements_not_met() { $settings = Mockery::mock( Settings::class ); @@ -249,7 +247,6 @@ function ( $arg ) { * * @dataProvider dp_test_vars_requirements_not_met * @throws ReflectionException ReflectionException. - * @noinspection PhpSwitchCanBeReplacedWithMatchExpressionInspection */ public function test_vars_requirements_not_met( $within_timeout, $content, $expected ) { $max_input_vars = $this->cyr_to_lat_required_max_input_vars - 1; @@ -382,8 +379,6 @@ public function dp_test_vars_requirements_not_met() { /** * Test are_requirements_met() when max_input_vars requirements not met and filesystem not available. * - * @noinspection PhpSwitchCanBeReplacedWithMatchExpressionInspection - * * @throws ReflectionException ReflectionException. */ public function test_vars_requirements_not_met_and_filesystem_not_available() {