Skip to content

Commit

Permalink
Add tests for flatsome 3rd party class (#5193)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeawhanlee authored Jul 8, 2022
1 parent 25f4208 commit 499eaf1
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
11 changes: 5 additions & 6 deletions inc/ThirdParty/Themes/Flatsome.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ];
}

/**
Expand All @@ -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_',
Expand Down
34 changes: 34 additions & 0 deletions tests/Fixtures/inc/ThirdParty/Themes/Flatsome/preservePatterns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

return [
'shouldExcludeInlineContentFromRUCSS' => [
'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-',
]
]
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace WP_Rocket\Tests\Integration\inc\ThirdParty\Themes\Flatsome;

use WP_Rocket\Tests\Integration\TestCase;
use WP_Rocket\ThirdParty\Themes\Flatsome;

/**
* @covers \WP_Rocket\ThirdParty\Themes\Flatsome::preserve_patterns
*/
class Test_PreservePatterns extends TestCase {

/**
* @dataProvider configTestData
*/
public function testShouldReturnExpected( $config, $expected ) {
$flatsome = new Flatsome();
$this->assertSame( $expected, $flatsome->preserve_patterns($config['excluded'] ) );
}

}
27 changes: 27 additions & 0 deletions tests/Unit/inc/ThirdParty/Themes/Flatsome/preservePatterns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace WP_Rocket\Tests\Unit\inc\ThirdParty\Themes\Flatsome;

use WP_Rocket\Tests\Unit\TestCase;
use WP_Rocket\ThirdParty\Themes\Flatsome;

/**
* @covers \WP_Rocket\ThirdParty\Themes\Flatsome::preserve_patterns
* @group ThirdParty
*/
class Test_PreservePatterns extends TestCase {
protected $flatsome;

protected function setUp(): void
{
parent::setUp();
$this->flatsome = new Flatsome();
}

/**
* @dataProvider configTestData
*/
public function testShouldReturnAsExpected( $config, $expected ) {

$this->assertSame( $expected, $this->flatsome->preserve_patterns( $config['excluded'] ) );
}
}

0 comments on commit 499eaf1

Please sign in to comment.