File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -92,16 +92,17 @@ protected function fillFields(Post $attachment)
92
92
93
93
/**
94
94
* @param string $size
95
+ * @param bool $useOriginalFallback
95
96
*
96
97
* @return Image
97
98
*/
98
- public function size ($ size )
99
+ public function size ($ size, $ useOriginalFallback = false )
99
100
{
100
101
if (isset ($ this ->sizes [$ size ])) {
101
102
return $ this ->fillThumbnailFields ($ this ->sizes [$ size ]);
102
103
}
103
104
104
- return $ this ->fillThumbnailFields ($ this ->sizes ['thumbnail ' ]);
105
+ return $ useOriginalFallback ? $ this : $ this ->fillThumbnailFields ($ this ->sizes ['thumbnail ' ]);
105
106
}
106
107
107
108
/**
@@ -117,6 +118,9 @@ protected function fillThumbnailFields(array $data)
117
118
$ size ->height = $ data ['height ' ];
118
119
$ size ->mime_type = $ data ['mime-type ' ];
119
120
121
+ $ urlPath = dirname ($ this ->url );
122
+ $ size ->url = sprintf ('%s/%s ' , $ urlPath , $ size ->filename );
123
+
120
124
return $ size ;
121
125
}
122
126
Original file line number Diff line number Diff line change @@ -53,7 +53,20 @@ public function testImageFieldValue()
53
53
$ this ->assertEquals ('1920 ' , $ image ->width );
54
54
$ this ->assertEquals ('1080 ' , $ image ->height );
55
55
$ this ->assertEquals ('maxresdefault-1.jpg ' , $ image ->filename );
56
+
57
+ // Test existing image size
56
58
$ this ->assertEquals ('1024 ' , $ image ->size ('large ' )->width );
59
+ $ this ->assertNotEmpty ($ image ->size ('large ' )->url );
60
+
61
+ // Test non existing image size with thumbnail as fallback
62
+ $ this ->assertEquals ('150 ' , $ image ->size ('fake_size ' )->width );
63
+ $ this ->assertNotEmpty ($ image ->size ('fake_size ' )->url );
64
+
65
+ // Test non existing image size with original as fallback
66
+ $ this ->assertEquals ($ image ->width , $ image ->size ('fake_size ' , true )->width );
67
+ $ this ->assertEquals ($ image ->height , $ image ->size ('fake_size ' , true )->height );
68
+ $ this ->assertNotEmpty ($ image ->size ('fake_size ' , true )->url );
69
+
57
70
$ this ->assertEquals ('image/jpeg ' , $ image ->mime_type );
58
71
$ this ->assertEquals ('This is a caption ' , $ image ->description );
59
72
}
You can’t perform that action at this time.
0 commit comments