Skip to content

Commit e3c9210

Browse files
committed
Add the test tracked in hydephp/framework/issues/156
1 parent 48f18e8 commit e3c9210

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

tests/Unit/HasFeaturedImageTest.php

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use Hyde\Framework\Models\HasFeaturedImage;
6+
use Hyde\Framework\Models\Image;
7+
use Tests\TestCase;
8+
9+
/**
10+
* Class HasFeaturedImageTest.
11+
*
12+
* @covers \Hyde\Framework\Models\HasFeaturedImage
13+
*/
14+
class HasFeaturedImageTest extends TestCase
15+
{
16+
use HasFeaturedImage;
17+
18+
protected array $matter;
19+
20+
// Test it can create a new Image instance from a string
21+
public function test_it_can_create_a_new_image_instance_from_a_string()
22+
{
23+
$this->matter = [
24+
'image' => 'https://example.com/image.jpg',
25+
];
26+
27+
$this->constructFeaturedImage();
28+
$this->assertInstanceOf(Image::class, $this->image);
29+
$this->assertEquals('https://example.com/image.jpg', $this->image->uri);
30+
}
31+
32+
// Test it can create a new Image instance from an array
33+
public function test_it_can_create_a_new_image_instance_from_an_array()
34+
{
35+
$this->matter = [
36+
'image' => [
37+
'uri' => 'https://example.com/image.jpg',
38+
],
39+
];
40+
41+
$this->constructFeaturedImage();
42+
$this->assertInstanceOf(Image::class, $this->image);
43+
$this->assertEquals('https://example.com/image.jpg', $this->image->uri);
44+
}
45+
46+
// Test constructBaseImage() sets the source to the image's uri when supplied path is an uri
47+
public function test_construct_base_image_sets_the_source_to_the_image_uri_when_supplied_path_is_an_uri()
48+
{
49+
$image = $this->constructBaseImage('https://example.com/image.jpg');
50+
$this->assertEquals('https://example.com/image.jpg', $image->getSource());
51+
}
52+
53+
// Test constructBaseImage() sets the source to the image's path when supplied path is a local path
54+
public function test_construct_base_image_sets_the_source_to_the_image_path_when_supplied_path_is_a_local_path()
55+
{
56+
$image = $this->constructBaseImage('/path/to/image.jpg');
57+
$this->assertEquals('/path/to/image.jpg', $image->getSource());
58+
}
59+
60+
// Test constructBaseImage() returns an Image instance created from a string
61+
public function test_construct_base_image_returns_an_image_instance_created_from_a_string()
62+
{
63+
$this->assertInstanceOf(Image::class, $this->constructBaseImage(''));
64+
}
65+
66+
// Test constructFullImage() returns an Image instance created from an array
67+
public function test_construct_full_image_returns_an_image_instance_created_from_an_array()
68+
{
69+
$this->assertInstanceOf(Image::class, $this->constructFullImage([]));
70+
}
71+
72+
}

0 commit comments

Comments
 (0)