|
@@ 2377-2397 (lines=21) @@
|
| 2374 |
|
* |
| 2375 |
|
* case: picture tag |
| 2376 |
|
*/ |
| 2377 |
|
public function test_imgopt_picture() |
| 2378 |
|
{ |
| 2379 |
|
$urls = $this->get_urls(); |
| 2380 |
|
$siteurl = $urls['siteurl']; |
| 2381 |
|
$imgopthost = $urls['imgopthost']; |
| 2382 |
|
$opts = autoptimizeImages::fetch_options(); |
| 2383 |
|
$opts['autoptimize_imgopt_checkbox_field_1'] = '1'; |
| 2384 |
|
$opts['autoptimize_imgopt_checkbox_field_3'] = '0'; |
| 2385 |
|
|
| 2386 |
|
$markup = <<<MARKUP |
| 2387 |
|
<picture><source srcset="$siteurl/wp-content/image.jpg" media="(min-width: 800px)"><img src="$siteurl/wp-content/image.jpg"/></picture> |
| 2388 |
|
MARKUP; |
| 2389 |
|
|
| 2390 |
|
$expected = <<<MARKUP |
| 2391 |
|
<picture><source srcset="$imgopthost/client/q_glossy,ret_img/$siteurl/wp-content/image.jpg" media="(min-width: 800px)"><img src="$imgopthost/client/q_glossy,ret_img/$siteurl/wp-content/image.jpg"/></picture> |
| 2392 |
|
MARKUP; |
| 2393 |
|
$instance = autoptimizeImages::instance(); |
| 2394 |
|
$instance->set_options( $opts ); |
| 2395 |
|
$actual = $instance->filter_optimize_images( $markup ); |
| 2396 |
|
$this->assertEquals( $expected, $actual ); |
| 2397 |
|
} |
| 2398 |
|
|
| 2399 |
|
/** |
| 2400 |
|
* Test image optimization & lazyload in autoptimizeImages.php. |
|
@@ 2459-2480 (lines=22) @@
|
| 2456 |
|
* |
| 2457 |
|
* case: background image in a style attribute |
| 2458 |
|
*/ |
| 2459 |
|
public function test_imgopt_bgimg() |
| 2460 |
|
{ |
| 2461 |
|
$urls = $this->get_urls(); |
| 2462 |
|
$siteurl = $urls['siteurl']; |
| 2463 |
|
$imgopthost = $urls['imgopthost']; |
| 2464 |
|
$opts = autoptimizeImages::fetch_options(); |
| 2465 |
|
$opts['autoptimize_imgopt_checkbox_field_1'] = '1'; |
| 2466 |
|
$opts['autoptimize_imgopt_checkbox_field_3'] = '0'; |
| 2467 |
|
|
| 2468 |
|
$markup = <<<MARKUP |
| 2469 |
|
<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> |
| 2470 |
|
MARKUP; |
| 2471 |
|
|
| 2472 |
|
$expected = <<<MARKUP |
| 2473 |
|
<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> |
| 2474 |
|
MARKUP; |
| 2475 |
|
|
| 2476 |
|
$instance = autoptimizeImages::instance(); |
| 2477 |
|
$instance->set_options( $opts ); |
| 2478 |
|
$actual = $instance->filter_optimize_images( $markup ); |
| 2479 |
|
$this->assertEquals( $expected, $actual ); |
| 2480 |
|
} |
| 2481 |
|
|
| 2482 |
|
/** |
| 2483 |
|
* Test lazyloading in autoptimizeImages.php. |
|
@@ 2514-2534 (lines=21) @@
|
| 2511 |
|
* |
| 2512 |
|
* case: picture tag |
| 2513 |
|
*/ |
| 2514 |
|
public function test_picture_lazyload() |
| 2515 |
|
{ |
| 2516 |
|
$urls = $this->get_urls(); |
| 2517 |
|
$siteurl = $urls['siteurl']; |
| 2518 |
|
$imgopthost = $urls['imgopthost']; |
| 2519 |
|
$opts = autoptimizeImages::fetch_options(); |
| 2520 |
|
$opts['autoptimize_imgopt_checkbox_field_3'] = '1'; |
| 2521 |
|
|
| 2522 |
|
$markup = <<<MARKUP |
| 2523 |
|
<picture><source srcset="$siteurl/wp-content/image.jpg" media="(min-width: 800px)"><img src="$siteurl/wp-content/image.jpg"/></picture> |
| 2524 |
|
MARKUP; |
| 2525 |
|
|
| 2526 |
|
$expected = <<<MARKUP |
| 2527 |
|
<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%20210%20140%22%3E%3C/svg%3E' data-src="$siteurl/wp-content/image.jpg"/></picture> |
| 2528 |
|
MARKUP; |
| 2529 |
|
|
| 2530 |
|
$instance = autoptimizeImages::instance(); |
| 2531 |
|
$instance->set_options( $opts ); |
| 2532 |
|
$actual = $instance->filter_lazyload_images( $markup ); |
| 2533 |
|
$this->assertEquals( $expected, $actual ); |
| 2534 |
|
} |
| 2535 |
|
|
| 2536 |
|
/** |
| 2537 |
|
* Test lazyload in autoptimizeImages.php. |