-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly remove media folders after removing all media files (#3688)
* Typo fix * Moved removing media files after removing conversions and responsive files. * Removed unused import from test.
- Loading branch information
Showing
3 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
tests/Feature/FileAdder/MediaConversions/DeleteMediaFolderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\File; | ||
|
||
beforeEach(function () { | ||
foreach (range(1, 3) as $index) { | ||
$this->testModelWithoutMediaConversions | ||
->addMedia($this->getTestJpg()) | ||
->preservingOriginal() | ||
->toMediaCollection(); | ||
|
||
$this->testModelWithMultipleConversions | ||
->addMedia($this->getTestJpg()) | ||
->preservingOriginal() | ||
->toMediaCollection(); | ||
|
||
$this->testModelWithResponsiveImages | ||
->addMedia($this->getTestJpg()) | ||
->preservingOriginal() | ||
->toMediaCollection(); | ||
} | ||
}); | ||
|
||
it('will remove the media folder when deleting a media model without conversions', function () { | ||
$ids = $this->testModelWithoutMediaConversions->getMedia()->pluck('id'); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); | ||
}); | ||
|
||
$this->testModelWithoutMediaConversions->clearMediaCollection(); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); | ||
}); | ||
}); | ||
|
||
it('will remove the media folder when deleting a subject without media conversions', function () { | ||
$ids = $this->testModelWithoutMediaConversions->getMedia()->pluck('id'); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); | ||
}); | ||
|
||
$this->testModelWithoutMediaConversions->delete(); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); | ||
}); | ||
}); | ||
|
||
it('will remove the media folder when deleting a media model with conversions', function () { | ||
$ids = $this->testModelWithMultipleConversions->getMedia()->pluck('id'); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); | ||
}); | ||
|
||
$this->testModelWithMultipleConversions->clearMediaCollection(); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); | ||
}); | ||
}); | ||
|
||
it('will remove the media folder when deleting a subject with media conversions', function () { | ||
$ids = $this->testModelWithMultipleConversions->getMedia()->pluck('id'); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); | ||
}); | ||
|
||
$this->testModelWithMultipleConversions->delete(); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); | ||
}); | ||
}); | ||
|
||
it('will remove the media folder when deleting a media model with conversions and responsive images', function () { | ||
$ids = $this->testModelWithResponsiveImages->getMedia()->pluck('id'); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); | ||
}); | ||
|
||
$this->testModelWithResponsiveImages->clearMediaCollection(); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); | ||
}); | ||
}); | ||
|
||
it('will remove the media folder when deleting a subject with media conversions and responsive images', function () { | ||
$ids = $this->testModelWithResponsiveImages->getMedia()->pluck('id'); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); | ||
}); | ||
|
||
$this->testModelWithResponsiveImages->delete(); | ||
|
||
$ids->map(function ($id) { | ||
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters