Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leonidasmi committed Sep 12, 2024
1 parent 94496bd commit 55aa767
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/Unit/Helpers/Schema/Image_Helper_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,32 @@ public function test_generate_from_url_with_found_attachment_id() {
);
}

/**
* Tests generating the schema from url with a found attachment id.
*
* @covers ::generate_from_url
*
* @return void
*/
public function test_generate_from_resized_url_with_found_attachment_id() {
$this->image
->expects( 'get_attachment_by_url' )
->once()
->with( 'https://example.org/image-300x300.jpg', true )
->andReturn( 1337 );

$this->instance
->expects( 'generate_from_resized_url' )
->once()
->with( '#schema-image-ABC', 1337, '', false, 'https://example.org/image-300x300.jpg' )
->andReturn( [] );

$this->assertEquals(
[],
$this->instance->generate_from_url( '#schema-image-ABC', 'https://example.org/image-300x300.jpg', '', false, true, true )
);
}

/**
* Tests generating the schema from url no found attachment id.
*
Expand Down Expand Up @@ -168,6 +194,53 @@ public function test_generate_from_attachment_id_with_caption_and_image_dimensio
);
}

/**
* Tests the generate_from_resized_url method.
*
* @covers ::generate_from_resized_url
* @covers ::generate_object
* @covers ::add_image_size
* @covers ::add_caption
*
* @return void
*/
public function test_generate_from_resized_url() {
$this->image
->expects( 'get_attachment_image_url' )
->never();

$this->image
->expects( 'get_metadata' )
->never();

$this->language
->expects( 'add_piece_language' )
->once()
->andReturnUsing( [ $this, 'set_language' ] );

$expected = [
'@type' => 'ImageObject',
'@id' => 'https://example.com/#/schema/logo/image/',
'url' => 'https://example.com/logo-300x300.jpg',
'contentUrl' => 'https://example.com/logo-300x300.jpg',
'width' => 300,
'height' => 300,
'caption' => 'Caption',
'inLanguage' => 'language',
];

$this->assertEquals(
$expected,
$this->instance->generate_from_resized_url(
'https://example.com/#/schema/logo/image/',
1337,
'Caption',
false,
'https://example.com/logo-300x300.jpg'
)
);
}

/**
* Tests the generate_from_attachment_id method.
*
Expand Down

0 comments on commit 55aa767

Please sign in to comment.