From 499eaf1bcfa79ef66191f287e3a63ea13851e378 Mon Sep 17 00:00:00 2001 From: Michael Lee <38788055+jeawhanlee@users.noreply.github.com> Date: Fri, 8 Jul 2022 19:57:53 +0100 Subject: [PATCH] Add tests for flatsome 3rd party class (#5193) --- inc/ThirdParty/Themes/Flatsome.php | 11 +++--- .../Themes/Flatsome/preservePatterns.php | 34 +++++++++++++++++++ .../Themes/Flatsome/preservePatterns.php | 20 +++++++++++ .../Themes/Flatsome/preservePatterns.php | 27 +++++++++++++++ 4 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 tests/Fixtures/inc/ThirdParty/Themes/Flatsome/preservePatterns.php create mode 100644 tests/Integration/inc/ThirdParty/Themes/Flatsome/preservePatterns.php create mode 100644 tests/Unit/inc/ThirdParty/Themes/Flatsome/preservePatterns.php diff --git a/inc/ThirdParty/Themes/Flatsome.php b/inc/ThirdParty/Themes/Flatsome.php index 20333c7772..ea68bc9824 100644 --- a/inc/ThirdParty/Themes/Flatsome.php +++ b/inc/ThirdParty/Themes/Flatsome.php @@ -12,9 +12,11 @@ class Flatsome implements Subscriber_Interface { * @return array */ public static function get_subscribed_events() { - return [ - 'rocket_rucss_inline_content_exclusions' => 'preserve_patterns', - ]; + if ( ! self::is_flatsome() ) { + return []; + } + + return [ 'rocket_rucss_inline_content_exclusions' => 'preserve_patterns' ]; } /** @@ -27,9 +29,6 @@ public static function get_subscribed_events() { * @return array */ public function preserve_patterns( $patterns ): array { - if ( ! self::is_flatsome() ) { - return $patterns; - } $preserve = [ '#section_', diff --git a/tests/Fixtures/inc/ThirdParty/Themes/Flatsome/preservePatterns.php b/tests/Fixtures/inc/ThirdParty/Themes/Flatsome/preservePatterns.php new file mode 100644 index 0000000000..ecb04926df --- /dev/null +++ b/tests/Fixtures/inc/ThirdParty/Themes/Flatsome/preservePatterns.php @@ -0,0 +1,34 @@ + [ + 'config' => [ + 'excluded' => [] + ], + 'excluded' => [ + '#section_', + '#text-box-', + '#banner-', + '#slider-', + '#gap-', + '#image_', + '#row-', + '#text-', + '#banner-grid-', + '#cats-', + '#col-', + '#gallery-', + '#instagram-', + '#map-', + '#page-header-', + '#pages-', + '#panel-', + '#portfolio-', + '#product-flip-', + '#product-grid-', + '#stack-', + '#timer-', + '#title-', + ] + ] +]; diff --git a/tests/Integration/inc/ThirdParty/Themes/Flatsome/preservePatterns.php b/tests/Integration/inc/ThirdParty/Themes/Flatsome/preservePatterns.php new file mode 100644 index 0000000000..f7f66abf77 --- /dev/null +++ b/tests/Integration/inc/ThirdParty/Themes/Flatsome/preservePatterns.php @@ -0,0 +1,20 @@ +assertSame( $expected, $flatsome->preserve_patterns($config['excluded'] ) ); + } + +} diff --git a/tests/Unit/inc/ThirdParty/Themes/Flatsome/preservePatterns.php b/tests/Unit/inc/ThirdParty/Themes/Flatsome/preservePatterns.php new file mode 100644 index 0000000000..741edb398f --- /dev/null +++ b/tests/Unit/inc/ThirdParty/Themes/Flatsome/preservePatterns.php @@ -0,0 +1,27 @@ +flatsome = new Flatsome(); + } + + /** + * @dataProvider configTestData + */ + public function testShouldReturnAsExpected( $config, $expected ) { + + $this->assertSame( $expected, $this->flatsome->preserve_patterns( $config['excluded'] ) ); + } +}