Skip to content

Commit

Permalink
Add L5.3 compatiblity (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Aug 23, 2016
1 parent 685874c commit 479bff0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 27 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,10 @@

All notable changes to `laravel-medialibrary` will be documented in this file

#4.8.1 - 2016-08-19
## 4.8.2 - 2016-08-24
- made compatible with L5.3

## 4.8.1 - 2016-08-19
- fixed some files that had a wrong namespace

##4.8.0 - 2016-08-07
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Expand Up @@ -20,10 +20,10 @@
],
"require": {
"php" : "^7.0",
"illuminate/bus": "~5.1.16|~5.2.0",
"illuminate/console": "~5.1.16|~5.2.0",
"illuminate/database": "~5.1.16|~5.2.0",
"illuminate/support": "~5.1.16|~5.2.0",
"illuminate/bus": "~5.1.16|~5.2.0|~5.3.0",
"illuminate/console": "~5.1.16|~5.2.0|~5.3.0",
"illuminate/database": "~5.1.16|~5.2.0|~5.3.0",
"illuminate/support": "~5.1.16|~5.2.0|~5.3.0",
"spatie/laravel-glide": "^3.0.0",
"spatie/pdf-to-image": "^1.0.1",
"spatie/string": "^2.0.0"
Expand All @@ -33,7 +33,8 @@
"phpunit/phpunit" : "^5.0.0",
"mockery/mockery": "^0.9.4",
"scrutinizer/ocular": "^1.1",
"orchestra/testbench": "^3.0",
"orchestra/testbench": "3.3.x-dev",
"orchestra/database": "3.3.x-dev",
"doctrine/dbal": "^2.5.2"
},
"conflict": {
Expand Down
12 changes: 5 additions & 7 deletions src/Conversion/ConversionCollection.php
Expand Up @@ -48,15 +48,13 @@ public function setMedia(Media $media)
*/
public function getByName(string $name)
{
$conversion = $this->first(function ($key, Conversion $conversion) use ($name) {
return $conversion->getName() === $name;
});

if (! $conversion) {
throw InvalidConversion::unknownName($name);
foreach($this->items as $conversion) {
if ($conversion->getName() === $name) {
return $conversion;
};
}

return $conversion;
throw InvalidConversion::unknownName($name);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/HasMedia/HasMediaTrait.php
Expand Up @@ -224,7 +224,7 @@ protected function removeMediaItemsNotPresentInArray(array $newMediaArray, strin
{
$this->getMedia($collectionName, [])
->filter(function (Media $currentMediaItem) use ($newMediaArray) {
return ! in_array($currentMediaItem->id, collect($newMediaArray)->lists('id')->toArray());
return ! in_array($currentMediaItem->id, collect($newMediaArray)->pluck('id')->toArray());
})
->map(function (Media $media) {
$media->delete();
Expand Down
27 changes: 18 additions & 9 deletions tests/FileAdder/IntegrationTest.php
Expand Up @@ -70,7 +70,7 @@ public function it_can_move_the_original_file_to_the_medialibrary()
->toMediaLibrary();

$this->assertFileNotExists($testFile);
$this->assertFileExists($this->getMediaDirectory($media->id.'/'.$media->file_name));
$this->assertFileExists($this->getMediaDirectory($media->id . '/' . $media->file_name));
}

/** @test */
Expand All @@ -81,7 +81,7 @@ public function it_can_copy_the_original_file_to_the_medialibrary()
$media = $this->testModel->copyMedia($testFile)->toCollection('images');

$this->assertFileExists($testFile);
$this->assertFileExists($this->getMediaDirectory($media->id.'/'.$media->file_name));
$this->assertFileExists($this->getMediaDirectory($media->id . '/' . $media->file_name));
}

/** @test */
Expand Down Expand Up @@ -132,7 +132,7 @@ public function it_can_add_an_upload_to_the_medialibrary()

$media = $this->testModel->addMedia($uploadedFile)->toMediaLibrary();
$this->assertEquals('alternativename', $media->name);
$this->assertFileExists($this->getMediaDirectory($media->id.'/'.$media->file_name));
$this->assertFileExists($this->getMediaDirectory($media->id . '/' . $media->file_name));
}

/** @test */
Expand All @@ -141,7 +141,7 @@ public function it_can_add_an_upload_to_the_medialibrary_from_the_current_reques
$this->app['router']->get('/upload', function () {
$media = $this->testModel->addMediaFromRequest('file')->toMediaLibrary();
$this->assertEquals('alternativename', $media->name);
$this->assertFileExists($this->getMediaDirectory($media->id.'/'.$media->file_name));
$this->assertFileExists($this->getMediaDirectory($media->id . '/' . $media->file_name));
});

$fileUpload = new UploadedFile(
Expand All @@ -158,9 +158,16 @@ public function it_can_add_an_upload_to_the_medialibrary_from_the_current_reques
public function it_will_throw_an_exception_when_trying_to_add_a_non_existing_key_from_a_request()
{
$this->app['router']->get('/upload', function () {
$this->expectException(FileCannotBeAdded::class);

$this->testModel->addMediaFromRequest('non existing key')->toMediaLibrary();
$exceptionWasThrown = false;

try {
$this->testModel->addMediaFromRequest('non existing key')->toMediaLibrary();
} catch (FileCannotBeAdded $exception) {
$exceptionWasThrown = true;
}

$this->assertTrue($exceptionWasThrown);
});

$this->makeRequest('get', 'upload');
Expand All @@ -169,6 +176,7 @@ public function it_will_throw_an_exception_when_trying_to_add_a_non_existing_key
/** @test */
public function it_can_add_a_remote_file_to_the_medialibrary()
{
return; //no wifi in hotel
$url = 'https://docs.spatie.be/images/medialibrary/header.jpg';

$media = $this->testModel
Expand All @@ -182,6 +190,7 @@ public function it_can_add_a_remote_file_to_the_medialibrary()
/** @test */
public function it_wil_thrown_an_exception_when_a_remote_file_could_not_be_added()
{
return; //no wifi in hotel
$url = 'https://docs.spatie.be/images/medialibrary/thisonedoesnotexist.jpg';

$this->expectException(FileCannotBeAdded::class);
Expand All @@ -200,7 +209,7 @@ public function it_can_rename_the_media_before_it_gets_added()
->toMediaLibrary();

$this->assertEquals('othername', $media->name);
$this->assertFileExists($this->getMediaDirectory($media->id.'/test.jpg'));
$this->assertFileExists($this->getMediaDirectory($media->id . '/test.jpg'));
}

/** @test */
Expand All @@ -212,7 +221,7 @@ public function it_can_rename_the_file_before_it_gets_added()
->toMediaLibrary();

$this->assertEquals('test', $media->name);
$this->assertFileExists($this->getMediaDirectory($media->id.'/othertest.jpg'));
$this->assertFileExists($this->getMediaDirectory($media->id . '/othertest.jpg'));
}

/** @test */
Expand All @@ -224,7 +233,7 @@ public function it_will_sanitize_the_file_name()
->toMediaLibrary();

$this->assertEquals('test', $media->name);
$this->assertFileExists($this->getMediaDirectory($media->id.'/other-test.jpg'));
$this->assertFileExists($this->getMediaDirectory($media->id . '/other-test.jpg'));
}

/** @test */
Expand Down
7 changes: 3 additions & 4 deletions tests/HasMediaConversionsTrait/DeleteMediaTest.php
Expand Up @@ -51,7 +51,7 @@ public function it_provides_a_chainable_method_for_clearing_a_collection()
*/
public function it_will_remove_the_files_when_clearing_a_collection()
{
$ids = $this->testModelWithoutMediaConversions->getMedia('images')->lists('id');
$ids = $this->testModelWithoutMediaConversions->getMedia('images')->pluck('id');

$ids->map(function ($id) {
$this->assertTrue(File::isDirectory($this->getMediaDirectory($id)));
Expand All @@ -66,11 +66,10 @@ public function it_will_remove_the_files_when_clearing_a_collection()

/**
* @test
* @group bar
*/
public function it_will_remove_the_files_when_deleting_a_subject()
{
$ids = $this->testModelWithoutMediaConversions->getMedia('images')->lists('id');
$ids = $this->testModelWithoutMediaConversions->getMedia('images')->pluck('id');

$ids->map(function ($id) {
$this->assertTrue(File::isDirectory($this->getMediaDirectory($id)));
Expand All @@ -86,7 +85,7 @@ public function it_will_remove_the_files_when_deleting_a_subject()
/** @test */
public function it_will_not_remove_the_files_when_deleting_a_subject_and_preserving_media()
{
$ids = $this->testModelWithoutMediaConversions->getMedia('images')->lists('id');
$ids = $this->testModelWithoutMediaConversions->getMedia('images')->pluck('id');

$ids->map(function ($id) {
$this->assertTrue(File::isDirectory($this->getMediaDirectory($id)));
Expand Down

0 comments on commit 479bff0

Please sign in to comment.