|
@@ 2348-2369 (lines=22) @@
|
| 2345 |
|
* |
| 2346 |
|
* case: background image in a style attribute |
| 2347 |
|
*/ |
| 2348 |
|
public function test_imgopt_bgimg() |
| 2349 |
|
{ |
| 2350 |
|
$urls = $this->get_urls(); |
| 2351 |
|
$siteurl = $urls['siteurl']; |
| 2352 |
|
$imgopthost = $urls['imgopthost']; |
| 2353 |
|
$opts = autoptimizeImages::fetch_options(); |
| 2354 |
|
$opts['autoptimize_imgopt_checkbox_field_1'] = '1'; |
| 2355 |
|
$opts['autoptimize_imgopt_checkbox_field_3'] = '0'; |
| 2356 |
|
|
| 2357 |
|
$markup = <<<MARKUP |
| 2358 |
|
<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> |
| 2359 |
|
MARKUP; |
| 2360 |
|
|
| 2361 |
|
$expected = <<<MARKUP |
| 2362 |
|
<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> |
| 2363 |
|
MARKUP; |
| 2364 |
|
|
| 2365 |
|
$instance = autoptimizeImages::instance(); |
| 2366 |
|
$instance->set_options( $opts ); |
| 2367 |
|
$actual = $instance->filter_optimize_images( $markup ); |
| 2368 |
|
$this->assertEquals( $expected, $actual ); |
| 2369 |
|
} |
| 2370 |
|
|
| 2371 |
|
/** |
| 2372 |
|
* Test lazyloading in autoptimizeImages.php. |
|
@@ 2453-2475 (lines=23) @@
|
| 2450 |
|
/** |
| 2451 |
|
* Test image optimization when image urls have no explict host provided. |
| 2452 |
|
*/ |
| 2453 |
|
public function test_imgopt_url_normalize_root_relative() |
| 2454 |
|
{ |
| 2455 |
|
$urls = $this->get_urls(); |
| 2456 |
|
$siteurl = $urls['siteurl']; |
| 2457 |
|
$imgopthost = $urls['imgopthost']; |
| 2458 |
|
$opts = autoptimizeImages::fetch_options(); |
| 2459 |
|
$opts['autoptimize_imgopt_checkbox_field_1'] = '1'; |
| 2460 |
|
$opts['autoptimize_imgopt_checkbox_field_3'] = '0'; |
| 2461 |
|
|
| 2462 |
|
$markup = <<<MARKUP |
| 2463 |
|
<img src='/wp-content/image.jpg' width='400' height='200' srcset="/wp-content/image-300X150.jpg 300w, /wp-content/image-600X300.jpg 600w" sizes="(max-width: 300px) 100vw, 300px" /> |
| 2464 |
|
MARKUP; |
| 2465 |
|
|
| 2466 |
|
$expected = <<<MARKUP |
| 2467 |
|
<img src='$imgopthost/client/q_glossy,ret_img,w_400,h_200/$siteurl/wp-content/image.jpg' width='400' height='200' srcset="$imgopthost/client/q_glossy,ret_img,w_300/$siteurl/wp-content/image-300X150.jpg 300w, $imgopthost/client/q_glossy,ret_img,w_600/$siteurl/wp-content/image-600X300.jpg 600w" sizes="(max-width: 300px) 100vw, 300px" /> |
| 2468 |
|
MARKUP; |
| 2469 |
|
|
| 2470 |
|
$instance = autoptimizeImages::instance(); |
| 2471 |
|
$instance->set_options( $opts ); |
| 2472 |
|
$actual = $instance->filter_optimize_images( $markup ); |
| 2473 |
|
|
| 2474 |
|
$this->assertEquals( $expected, $actual ); |
| 2475 |
|
} |
| 2476 |
|
|
| 2477 |
|
/** |
| 2478 |
|
* Test image optimization when image urls have a protocol-relative url. |