|
@@ 2331-2351 (lines=21) @@
|
| 2328 |
|
* |
| 2329 |
|
* case: picture tag |
| 2330 |
|
*/ |
| 2331 |
|
public function test_imgopt_picture() |
| 2332 |
|
{ |
| 2333 |
|
$urls = $this->get_urls(); |
| 2334 |
|
$siteurl = $urls['siteurl']; |
| 2335 |
|
$imgopthost = $urls['imgopthost']; |
| 2336 |
|
$opts = autoptimizeImages::fetch_options(); |
| 2337 |
|
$opts['autoptimize_imgopt_checkbox_field_1'] = '1'; |
| 2338 |
|
$opts['autoptimize_imgopt_checkbox_field_3'] = '0'; |
| 2339 |
|
|
| 2340 |
|
$markup = <<<MARKUP |
| 2341 |
|
<picture><source srcset="$siteurl/wp-content/image.jpg" media="(min-width: 800px)"><img src="$siteurl/wp-content/image.jpg"/></picture> |
| 2342 |
|
MARKUP; |
| 2343 |
|
|
| 2344 |
|
$expected = <<<MARKUP |
| 2345 |
|
<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> |
| 2346 |
|
MARKUP; |
| 2347 |
|
$instance = autoptimizeImages::instance(); |
| 2348 |
|
$instance->set_options( $opts ); |
| 2349 |
|
$actual = $instance->filter_optimize_images( $markup ); |
| 2350 |
|
$this->assertEquals( $expected, $actual ); |
| 2351 |
|
} |
| 2352 |
|
|
| 2353 |
|
/** |
| 2354 |
|
* Test image optimization & lazyload in autoptimizeImages.php. |
|
@@ 2413-2434 (lines=22) @@
|
| 2410 |
|
* |
| 2411 |
|
* case: background image in a style attribute |
| 2412 |
|
*/ |
| 2413 |
|
public function test_imgopt_bgimg() |
| 2414 |
|
{ |
| 2415 |
|
$urls = $this->get_urls(); |
| 2416 |
|
$siteurl = $urls['siteurl']; |
| 2417 |
|
$imgopthost = $urls['imgopthost']; |
| 2418 |
|
$opts = autoptimizeImages::fetch_options(); |
| 2419 |
|
$opts['autoptimize_imgopt_checkbox_field_1'] = '1'; |
| 2420 |
|
$opts['autoptimize_imgopt_checkbox_field_3'] = '0'; |
| 2421 |
|
|
| 2422 |
|
$markup = <<<MARKUP |
| 2423 |
|
<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> |
| 2424 |
|
MARKUP; |
| 2425 |
|
|
| 2426 |
|
$expected = <<<MARKUP |
| 2427 |
|
<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> |
| 2428 |
|
MARKUP; |
| 2429 |
|
|
| 2430 |
|
$instance = autoptimizeImages::instance(); |
| 2431 |
|
$instance->set_options( $opts ); |
| 2432 |
|
$actual = $instance->filter_optimize_images( $markup ); |
| 2433 |
|
$this->assertEquals( $expected, $actual ); |
| 2434 |
|
} |
| 2435 |
|
|
| 2436 |
|
/** |
| 2437 |
|
* Test lazyloading in autoptimizeImages.php. |
|
@@ 2468-2488 (lines=21) @@
|
| 2465 |
|
* |
| 2466 |
|
* case: picture tag |
| 2467 |
|
*/ |
| 2468 |
|
public function test_picture_lazyload() |
| 2469 |
|
{ |
| 2470 |
|
$urls = $this->get_urls(); |
| 2471 |
|
$siteurl = $urls['siteurl']; |
| 2472 |
|
$imgopthost = $urls['imgopthost']; |
| 2473 |
|
$opts = autoptimizeImages::fetch_options(); |
| 2474 |
|
$opts['autoptimize_imgopt_checkbox_field_3'] = '1'; |
| 2475 |
|
|
| 2476 |
|
$markup = <<<MARKUP |
| 2477 |
|
<picture><source srcset="$siteurl/wp-content/image.jpg" media="(min-width: 800px)"><img src="$siteurl/wp-content/image.jpg"/></picture> |
| 2478 |
|
MARKUP; |
| 2479 |
|
|
| 2480 |
|
$expected = <<<MARKUP |
| 2481 |
|
<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="$siteurl/wp-content/image.jpg"/></picture> |
| 2482 |
|
MARKUP; |
| 2483 |
|
|
| 2484 |
|
$instance = autoptimizeImages::instance(); |
| 2485 |
|
$instance->set_options( $opts ); |
| 2486 |
|
$actual = $instance->filter_lazyload_images( $markup ); |
| 2487 |
|
$this->assertEquals( $expected, $actual ); |
| 2488 |
|
} |
| 2489 |
|
|
| 2490 |
|
/** |
| 2491 |
|
* Test lazyload in autoptimizeImages.php. |