-
Notifications
You must be signed in to change notification settings - Fork 71
/
DetachMediaTest.php
67 lines (49 loc) · 1.43 KB
/
DetachMediaTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
use Orchestra\Testbench\TestCase;
use Illuminate\Http\UploadedFile;
use Illuminate\Database\Eloquent\Model;
use CloudinaryLabs\CloudinaryLaravel\MediaAlly;
/**
*
*/
class DetachMediaTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
// and other test setup steps you need to perform
}
protected function getPackageProviders($app)
{
return ['CloudinaryLabs\CloudinaryLaravel\CloudinaryServiceProvider'];
}
public function test_can_detach_one_media_or_all()
{
$this->artisan('migrate')->run();
$model = MyModel::create([]);
for ($i = 0; $i < 10; $i++) {
$model->attachMedia(UploadedFile::fake()->image('file.jpg'));
}
$this->assertCount(10, $model->fetchAllMedia());
// Delete one
$media1 = $model->fetchAllMedia()->first();
$model->detachMedia($media1);
$this->assertCount(9, $model->fetchAllMedia());
// Delete multiple
$multiple_media = $model->fetchAllMedia()->slice(0, 4);
$model->detachMedia($multiple_media);
$this->assertCount(5, $model->fetchAllMedia());
// Delete all
$model->detachMedia();
$this->assertCount(0, $model->fetchAllMedia());
}
}
/**
*
*/
class MyModel extends Model
{
protected $table = 'model';
use MediaAlly;
}