-
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.
fix: searching through multiple classes the right way, added tests
- Loading branch information
1 parent
847e90e
commit 4751edb
Showing
2 changed files
with
79 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?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 test 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" src="http://example.org/img.png" alt=""/>; | ||
</div>'; | ||
$replaced_content = Optml_Manager::instance()->process_images_from_content($content); | ||
var_dump($replaced_content); | ||
$this->assertEquals( 3, substr_count( $replaced_content, 'i.optimole.com' ) ); | ||
$this->assertNotContains('data-opt-src', $replaced_content); | ||
|
||
} | ||
} |
4751edb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@preda-bogdan now it works