@@ -58,6 +58,8 @@ protected function setUp(): void
58
58
59
59
Storage::disk ('test ' )->put ('f.jpg ' , '' );
60
60
Facades \Asset::make ()->container ('test ' )->path ('f.jpg ' )->save ();
61
+
62
+ Storage::disk ('test ' )->put ('test-folder/test.jpg ' , '' );
61
63
}
62
64
63
65
#[Test]
@@ -70,7 +72,7 @@ public function it_loads_from_asset_model()
70
72
'basename ' => 'test.jpg ' ,
71
73
'filename ' => 'test ' ,
72
74
'extension ' => 'jpg ' ,
73
- 'meta ' => ['width ' => 100 , 'height ' => 100 , 'data ' => []],
75
+ 'meta ' => ['width ' => 100 , 'height ' => 100 , 'data ' => [' focus ' => ' 50-50-1 ' ]],
74
76
]);
75
77
76
78
$ asset = (new Asset )->fromModel ($ model );
@@ -81,7 +83,33 @@ public function it_loads_from_asset_model()
81
83
$ this ->assertSame ('test.jpg ' , $ asset ->basename ());
82
84
$ this ->assertSame ('test ' , $ asset ->filename ());
83
85
$ this ->assertSame ('jpg ' , $ asset ->extension ());
84
- $ this ->assertSame (['width ' => 100 , 'height ' => 100 , 'data ' => []], $ asset ->meta ());
86
+ $ this ->assertSame (['width ' => 100 , 'height ' => 100 , 'data ' => ['focus ' => '50-50-1 ' ]], $ asset ->meta ());
87
+ }
88
+
89
+ #[Test]
90
+ public function it_loads_from_an_existing_model_outside_the_query_builder ()
91
+ {
92
+ $ model = new AssetModel ([
93
+ 'container ' => 'test ' ,
94
+ 'path ' => 'test-folder/test.jpg ' ,
95
+ 'folder ' => 'test-folder ' ,
96
+ 'basename ' => 'test.jpg ' ,
97
+ 'filename ' => 'test ' ,
98
+ 'extension ' => 'jpg ' ,
99
+ 'meta ' => ['width ' => 100 , 'height ' => 100 , 'data ' => ['focus ' => '50-50-1 ' ]],
100
+ ]);
101
+
102
+ $ model ->save ();
103
+
104
+ $ asset = $ this ->container ->asset ($ model ->path );
105
+
106
+ $ this ->assertSame ($ model ->getKey (), $ asset ->model ()->getKey ());
107
+ $ this ->assertSame ('test-folder/test.jpg ' , $ asset ->path ());
108
+ $ this ->assertSame ('test-folder ' , $ asset ->folder ());
109
+ $ this ->assertSame ('test.jpg ' , $ asset ->basename ());
110
+ $ this ->assertSame ('test ' , $ asset ->filename ());
111
+ $ this ->assertSame ('jpg ' , $ asset ->extension ());
112
+ $ this ->assertSame (['width ' => 100 , 'height ' => 100 , 'data ' => ['focus ' => '50-50-1 ' ]], $ asset ->meta ());
85
113
}
86
114
87
115
#[Test]
@@ -216,11 +244,13 @@ public function can_save_an_asset_made_on_the_container()
216
244
217
245
$ asset = $ this ->container ->makeAsset ('a.jpg ' );
218
246
219
- $ this ->assertNull ($ asset ->model ());
247
+ $ model = $ asset ->model (); // it should find the existing model meta
248
+ $ this ->assertNotNull ($ model );
220
249
221
250
$ asset ->save ();
222
251
223
252
$ this ->assertNotNull ($ asset ->model ());
253
+ $ this ->assertSame ($ model , $ asset ->model ());
224
254
225
255
Event::assertDispatched (AssetSaved::class, fn ($ event ) => $ event ->asset === $ asset );
226
256
0 commit comments