|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Concerns\HasFeaturedImage; |
|
6
|
|
|
use Hyde\Framework\Models\FrontMatter; |
|
7
|
|
|
use Hyde\Framework\Models\Image; |
|
8
|
|
|
use Hyde\Testing\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class HasFeaturedImageTest. |
|
12
|
|
|
* |
|
13
|
|
|
* @covers \Hyde\Framework\Concerns\HasFeaturedImage |
|
14
|
|
|
*/ |
|
15
|
|
|
class HasFeaturedImageTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
use HasFeaturedImage; |
|
18
|
|
|
|
|
19
|
|
|
protected FrontMatter $matter; |
|
20
|
|
|
|
|
21
|
|
|
protected function matter(...$args) |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->matter->get(...$args); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function test_it_can_create_a_new_image_instance_from_a_string() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->matter = FrontMatter::fromArray([ |
|
29
|
|
|
'image' => 'https://example.com/image.jpg', |
|
30
|
|
|
]); |
|
31
|
|
|
|
|
32
|
|
|
$this->constructFeaturedImage(); |
|
33
|
|
|
$this->assertInstanceOf(Image::class, $this->image); |
|
34
|
|
|
$this->assertEquals('https://example.com/image.jpg', $this->image->uri); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function test_it_can_create_a_new_image_instance_from_an_array() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->matter = FrontMatter::fromArray([ |
|
40
|
|
|
'image' => [ |
|
41
|
|
|
'uri' => 'https://example.com/image.jpg', |
|
42
|
|
|
], |
|
43
|
|
|
]); |
|
44
|
|
|
|
|
45
|
|
|
$this->constructFeaturedImage(); |
|
46
|
|
|
$this->assertInstanceOf(Image::class, $this->image); |
|
47
|
|
|
$this->assertEquals('https://example.com/image.jpg', $this->image->uri); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function test_construct_base_image_sets_the_source_to_the_image_uri_when_supplied_path_is_an_uri() |
|
51
|
|
|
{ |
|
52
|
|
|
$image = $this->constructBaseImage('https://example.com/image.jpg'); |
|
53
|
|
|
$this->assertEquals('https://example.com/image.jpg', $image->getSource()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function test_construct_base_image_sets_the_source_to_the_image_path_when_supplied_path_is_a_local_path() |
|
57
|
|
|
{ |
|
58
|
|
|
$image = $this->constructBaseImage('/path/to/image.jpg'); |
|
59
|
|
|
$this->assertEquals('/path/to/image.jpg', $image->getSource()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function test_construct_base_image_returns_an_image_instance_created_from_a_string() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->assertInstanceOf(Image::class, $this->constructBaseImage('')); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
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
|
|
|
|