-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds exclude by class filter for lazyload mechanism
- Loading branch information
Showing
7 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* WordPress unit test plugin. | ||
* | ||
* @package Optimole-WP | ||
* @subpackage Tests | ||
* @copyright Copyright (c) 2017, ThemeIsle | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License | ||
*/ | ||
|
||
/** | ||
* Class Test_Generic. | ||
*/ | ||
class Test_Lazyload_Class_Exclusion extends WP_UnitTestCase | ||
{ | ||
|
||
public static $sample_attachement; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$settings = new Optml_Settings(); | ||
$settings->update('service_data', [ | ||
'cdn_key' => 'test123', | ||
'cdn_secret' => '12345', | ||
'whitelist' => ['example.com'], | ||
]); | ||
|
||
$settings->update('lazyload', 'enabled'); | ||
$settings->update('filters', array( | ||
Optml_Settings::FILTER_TYPE_LAZYLOAD => array ( | ||
Optml_Settings::FILTER_CLASS => array ( | ||
'test' => true, | ||
'whatever' => true, | ||
'testing' => true, | ||
) | ||
))); | ||
Optml_Url_Replacer::instance()->init(); | ||
Optml_Tag_Replacer::instance()->init(); | ||
Optml_Lazyload_Replacer::instance()->init(); | ||
Optml_Manager::instance()->init(); | ||
|
||
self::$sample_attachement = self::factory()->attachment->create_upload_object(OPTML_PATH . 'assets/img/logo.png'); | ||
} | ||
|
||
public function test_class_exclusions() | ||
{ | ||
$content = '<div> | ||
<img class="something another whatever" src="http://example.org/wp-content/uploads/2019/09/Screenshot.png" alt=""/>; | ||
<img class="test" src="http://example.org/wp-content/uploads/2019/09/img.jpg" alt=""/>; | ||
<img class="testing class" src="http://example.org/img.png" alt=""/>; | ||
</div>'; | ||
$replaced_content = Optml_Manager::instance()->process_images_from_content($content); | ||
$this->assertEquals( 3, substr_count( $replaced_content, 'i.optimole.com' ) ); | ||
$this->assertNotContains('data-opt-src', $replaced_content); | ||
} | ||
public function test_class_exclusions_does_not_affect_regular_replacement() | ||
{ | ||
$content = '<div> | ||
<img class="something another code" src="http://example.org/wp-content/uploads/2019/09/Screenshot.png" alt=""/>; | ||
<img class="whatever_code_test" src="http://example.org/img.jpg" alt=""/>; | ||
</div>'; | ||
$replaced_content = Optml_Manager::instance()->process_images_from_content($content); | ||
|
||
$this->assertEquals( 4, substr_count( $replaced_content, 'i.optimole.com' ) ); | ||
$this->assertEquals( 1, substr_count( $replaced_content, 'data-opt-src' ) ); | ||
$this->assertEquals( 1, substr_count( $replaced_content, '<noscript>' ) ); | ||
} | ||
} |