|
@@ 2402-2423 (lines=22) @@
|
| 2399 |
|
* |
| 2400 |
|
* case: background image in a style attribute |
| 2401 |
|
*/ |
| 2402 |
|
public function test_imgopt_bgimg() |
| 2403 |
|
{ |
| 2404 |
|
$urls = $this->get_urls(); |
| 2405 |
|
$siteurl = $urls['siteurl']; |
| 2406 |
|
$imgopthost = $urls['imgopthost']; |
| 2407 |
|
$opts = autoptimizeImages::fetch_options(); |
| 2408 |
|
$opts['autoptimize_imgopt_checkbox_field_1'] = '1'; |
| 2409 |
|
$opts['autoptimize_imgopt_checkbox_field_3'] = '0'; |
| 2410 |
|
|
| 2411 |
|
$markup = <<<MARKUP |
| 2412 |
|
<div class="textwidget custom-html-widget"><div class="et_parallax_bg et_pb_parallax_css" style="height:200px; background-image: url($siteurl/wp-content/uploads/2018/05/DSC_1615-300x201.jpg);"></div> |
| 2413 |
|
MARKUP; |
| 2414 |
|
|
| 2415 |
|
$expected = <<<MARKUP |
| 2416 |
|
<div class="textwidget custom-html-widget"><div class="et_parallax_bg et_pb_parallax_css" style="height:200px; background-image: url($imgopthost/client/q_glossy,ret_img/$siteurl/wp-content/uploads/2018/05/DSC_1615-300x201.jpg);"></div> |
| 2417 |
|
MARKUP; |
| 2418 |
|
|
| 2419 |
|
$instance = autoptimizeImages::instance(); |
| 2420 |
|
$instance->set_options( $opts ); |
| 2421 |
|
$actual = $instance->filter_optimize_images( $markup ); |
| 2422 |
|
$this->assertEquals( $expected, $actual ); |
| 2423 |
|
} |
| 2424 |
|
|
| 2425 |
|
/** |
| 2426 |
|
* Test lazyloading in autoptimizeImages.php. |
|
@@ 2457-2477 (lines=21) @@
|
| 2454 |
|
* |
| 2455 |
|
* case: picture tag |
| 2456 |
|
*/ |
| 2457 |
|
public function test_picture_lazyload() |
| 2458 |
|
{ |
| 2459 |
|
$urls = $this->get_urls(); |
| 2460 |
|
$siteurl = $urls['siteurl']; |
| 2461 |
|
$imgopthost = $urls['imgopthost']; |
| 2462 |
|
$opts = autoptimizeImages::fetch_options(); |
| 2463 |
|
$opts['autoptimize_imgopt_checkbox_field_3'] = '1'; |
| 2464 |
|
|
| 2465 |
|
$markup = <<<MARKUP |
| 2466 |
|
<picture><source srcset="$siteurl/wp-content/image.jpg" media="(min-width: 800px)"><img src="$siteurl/wp-content/image.jpg"/></picture> |
| 2467 |
|
MARKUP; |
| 2468 |
|
|
| 2469 |
|
$expected = <<<MARKUP |
| 2470 |
|
<picture><source data-srcset="$siteurl/wp-content/image.jpg" media="(min-width: 800px)"><noscript><img src="$siteurl/wp-content/image.jpg"/></noscript><img class="lazyload" src='data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20%20%22%3E%3C/svg%3E' data-src="http://example.org/wp-content/image.jpg"/></picture> |
| 2471 |
|
MARKUP; |
| 2472 |
|
|
| 2473 |
|
$instance = autoptimizeImages::instance(); |
| 2474 |
|
$instance->set_options( $opts ); |
| 2475 |
|
$actual = $instance->filter_lazyload_images( $markup ); |
| 2476 |
|
$this->assertEquals( $expected, $actual ); |
| 2477 |
|
} |
| 2478 |
|
|
| 2479 |
|
/** |
| 2480 |
|
* Test image optimization in autoptimizeImages.php. |