Skip to content

Commit

Permalink
Add tests for srcset descriptors and picture markup
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed Mar 2, 2022
1 parent 646ccdf commit a9f1fa4
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions tests/test-picture.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Timmy\Timmy;

/**
* Class TestUpscale
*/
Expand Down Expand Up @@ -53,6 +55,34 @@ public function test_picture_webp_with_small_image_square() {
$this->assertEquals( $expected, $result );
}

public function test_picture_webp_args_array_with_srcset_descriptors() {
$attachment = $this->create_image();
$result = get_timber_picture_responsive( $attachment, [
'resize' => [ 260 ],
'srcset' => [ '1x', '2x' ],
'webp' => true,
] );

$expected = '<source type="image/webp" srcset="' . $this->get_upload_url() . '/test-260x0-c-default.webp 1x, ' . $this->get_upload_url() . '/test-520x0-c-default.webp 2x">' . PHP_EOL . '<source type="image/jpeg" srcset="' . $this->get_upload_url() . '/test-260x0-c-default.jpg 1x, ' . $this->get_upload_url() . '/test-520x0-c-default.jpg 2x">' . PHP_EOL . '<img src="' . $this->get_upload_url() . '/test-260x0-c-default.jpg" width="260" height="173" alt="" loading="lazy">';

$this->assertEquals( $expected, $result );
}

public function test_picture_webp_args_array_with_srcset_descriptors_timmy_image() {
$attachment = $this->create_image();
$image = Timmy::get_image( $attachment, [
'resize' => [ 260 ],
'srcset' => [ '1x', '2x' ],
'webp' => true,
] );

$result = $image->picture_responsive();

$expected = '<source type="image/webp" srcset="' . $this->get_upload_url() . '/test-260x0-c-default.webp 1x, ' . $this->get_upload_url() . '/test-520x0-c-default.webp 2x">' . PHP_EOL . '<source type="image/jpeg" srcset="' . $this->get_upload_url() . '/test-260x0-c-default.jpg 1x, ' . $this->get_upload_url() . '/test-520x0-c-default.jpg 2x">' . PHP_EOL . '<img src="' . $this->get_upload_url() . '/test-260x0-c-default.jpg" width="260" height="173" alt="" loading="lazy">';

$this->assertEquals( $expected, $result );
}

public function test_picture_loading_false() {
$attachment = $this->create_image();
$result = get_timber_picture_responsive( $attachment, 'picture', [ 'loading' => false ] );
Expand All @@ -66,8 +96,8 @@ public function test_picture_loading_false() {
public function test_picture_loading_false_timmy_image() {
$attachment = $this->create_image();

$image = Timmy\Timmy::get_image( $attachment->ID, 'picture' );
$result = $image->picture_responsive( [ 'loading' => false ] );
$image = Timmy::get_image( $attachment->ID, 'picture' );
$result = $image->picture_responsive( [ 'loading' => false ] );

$expected = '<source srcset="' . $this->get_upload_url() . '/test-560x0-c-default.jpg 560w, ' . $this->get_upload_url() . '/test-1400x0-c-default.jpg 1400w" sizes="100vw">' . PHP_EOL .
'<img src="' . $this->get_upload_url() . '/test-1400x0-c-default.jpg" width="1400" height="933" alt="">';
Expand Down

0 comments on commit a9f1fa4

Please sign in to comment.