Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/spatie/laravel-medialibrary…
Browse files Browse the repository at this point in the history
… into bugfix
  • Loading branch information
virtruvio committed Mar 28, 2019
2 parents 883b02f + 6ffb8a4 commit b5fb212
Show file tree
Hide file tree
Showing 29 changed files with 114 additions and 53 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ sudo: required
language: php

php:
- 7.1
- 7.2
- 7.3

Expand All @@ -23,7 +22,7 @@ install:
- sudo apt-get install -y ghostscript

script:
- phpunit
- vendor/bin/phpunit

branches:
only:
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

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

## 7.6.0 - 2019-02-27

- drop support for PHP 7.1

## 7.5.6 - 2019-02-19

- add support for Laravel 5.8

## 7.5.5 - 2019-01-05

- avoid exception when getting a video frame that does not exist

## 7.5.4 - 2019-01-04

- only set `custom_headers` property if explicitly set

## 7.5.3 - 2019-01-03

- use absolute urls for responsive image sources
- fix sortable

## 7.5.2 - 2018-10-19

- fix for issue #1277
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ For the creation of thumbnails of svg's or pdf's you should also install [Imagic
You can install this package via composer using this command:

```bash
composer require spatie/laravel-medialibrary:^7.0.0
composer require "spatie/laravel-medialibrary:^7.0.0"
```

The package will automatically register itself.
Expand Down Expand Up @@ -113,7 +113,7 @@ return [
/*
* The class name of the media model that should be used.
*/
'media_model' => Spatie\MediaLibrary\Media::class,
'media_model' => Spatie\MediaLibrary\Models\Media::class,

/*
* The engine that should perform the image conversions.
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
}
],
"require": {
"php": "^7.1",
"illuminate/bus": "~5.5.0|~5.6.0|~5.7.0",
"illuminate/console": "~5.5.0|~5.6.0|~5.7.0",
"illuminate/database": "~5.5.0|~5.6.0|~5.7.0",
"illuminate/pipeline": "~5.5.0|~5.6.0|~5.7.0",
"illuminate/support": "~5.5.0|~5.6.0|~5.7.0",
"php": "^7.2",
"illuminate/bus": "~5.5.0|~5.6.0|~5.7.0|~5.8.0",
"illuminate/console": "~5.5.0|~5.6.0|~5.7.0|~5.8.0",
"illuminate/database": "~5.5.0|~5.6.0|~5.7.0|~5.8.0",
"illuminate/pipeline": "~5.5.0|~5.6.0|~5.7.0|~5.8.0",
"illuminate/support": "~5.5.0|~5.6.0|~5.7.0|~5.8.0",
"league/flysystem": "^1.0.8",
"maennchen/zipstream-php": "~0.4",
"spatie/image": "^1.4.0",
Expand All @@ -40,9 +40,9 @@
"guzzlehttp/guzzle": "^6.3",
"league/flysystem-aws-s3-v3": "^1.0.13",
"mockery/mockery": "^1.0.0",
"orchestra/testbench": "~3.5.0|~3.6.0|~3.7.0",
"phpunit/phpunit" : "^7.0",
"spatie/phpunit-snapshot-assertions": "^1.2"
"orchestra/testbench": "~3.8.0",
"phpunit/phpunit" : "^8.0",
"spatie/phpunit-snapshot-assertions": "^2.0"
},
"conflict": {
"php-ffmpeg/php-ffmpeg": "<0.6.1"
Expand Down
4 changes: 3 additions & 1 deletion src/FileAdder/FileAdder.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ public function toMediaCollection(string $collectionName = 'default', string $di

$media->manipulations = $this->manipulations;

$media->setCustomHeaders($this->customHeaders);
if (filled($this->customHeaders)) {
$media->setCustomHeaders($this->customHeaders);
}

$media->fill($this->properties);

Expand Down
4 changes: 2 additions & 2 deletions src/HasMedia/HasMediaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function bootHasMediaTrait()
/**
* Set the polymorphic relation.
*
* @return mixed
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function media()
{
Expand Down Expand Up @@ -171,7 +171,7 @@ public function addMediaFromBase64(string $base64data, ...$allowedMimeTypes): Fi
throw InvalidBase64Data::create();
}

// decoding and then reeconding should not change the data
// decoding and then reencoding should not change the data
if (base64_encode(base64_decode($base64data)) !== $base64data) {
throw InvalidBase64Data::create();
}
Expand Down
2 changes: 2 additions & 0 deletions src/ImageGenerators/FileTypes/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public function convert(string $file, Conversion $conversion = null): string
]);

$video = $ffmpeg->open($file);
$duration = $ffmpeg->getDuration();

$seconds = $conversion ? $conversion->getExtractVideoFrameAtSecond() : 0;
$seconds = $duration < $seconds ? 0 : $seconds;

$frame = $video->frame(TimeCode::fromSeconds($seconds));
$frame->save($imageFile);
Expand Down
4 changes: 3 additions & 1 deletion src/MediaObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class MediaObserver
{
public function creating(Media $media)
{
$media->setHighestOrderNumber();
if ($media->shouldSortWhenCreating()) {
$media->setHighestOrderNumber();
}
}

public function updating(Media $media)
Expand Down
2 changes: 1 addition & 1 deletion src/UrlGenerator/LocalUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ protected function makeCompatibleForNonUnixHosts(string $url): string
*/
public function getResponsiveImagesDirectoryUrl(): string
{
return $this->getBaseMediaDirectoryUrl().'/'.$this->pathGenerator->getPathForResponsiveImages($this->media);
return url($this->getBaseMediaDirectoryUrl().'/'.$this->pathGenerator->getPathForResponsiveImages($this->media)).'/';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CleanConversionsTest extends TestCase
/** @var array */
protected $media;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Commands/ClearCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ClearCommandTest extends TestCase
/** @var array */
protected $media;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Events/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class EventTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setup();

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/FileAdder/MediaConversions/AddMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function it_will_not_create_a_derived_version_if_manipulations_did_not_ch

Carbon::setTestNow(Carbon::now()->addMinute());

$media->order_column = $media->order_column + 1;
$media->order_column += 1;
$media->save();

$thumbsCreatedAt = filemtime($this->getMediaDirectory($media->id.'/conversions/test-thumb.jpg'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DeleteMediaTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/FileSystem/FileSystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FileSystemTest extends TestCase
*/
protected $filesystem;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/HasMediaTrait/DeleteMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class DeleteMediaTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/HasMediaTrait/UpdateMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class UpdateMediaTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
35 changes: 35 additions & 0 deletions tests/Feature/Media/CustomHeadersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Spatie\MediaLibrary\Tests\Feature\Media;

use Spatie\MediaLibrary\Tests\TestCase;

class CustomHeadersTest extends TestCase
{
/** @test */
public function it_does_not_set_empty_custom_headers_when_saved()
{
$media = $this->testModel
->addMedia($this->getTestJpg())
->toMediaCollection();

$this->assertFalse($media->hasCustomProperty('custom_headers'));
$this->assertEquals([], $media->getCustomHeaders());
}

/** @test */
public function it_can_set_and_retrieve_custom_headers_when_explicitly_added()
{
$headers = [
'Header' => 'Present',
];

$media = $this->testModel
->addMedia($this->getTestJpg())
->toMediaCollection()
->setCustomHeaders($headers);

$this->assertTrue($media->hasCustomProperty('custom_headers'));
$this->assertEquals($headers, $media->getCustomHeaders());
}
}
2 changes: 1 addition & 1 deletion tests/Feature/Media/CustomPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CustomPropertyTest extends TestCase
/** @var \Spatie\MediaLibrary\Models\Media */
protected $mediaWithoutCustomProperty;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Media/ToHtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ToHtmlTest extends TestCase
{
use MatchesSnapshots;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -102,8 +102,8 @@ public function it_can_render_itself_with_responsive_images_of_a_conversion_and_

$image = $media->refresh()->img('thumb');

$this->assertContains('/media/2/responsive-images/', $image);
$this->assertContains('data:image/svg+xml;base64,', $image);
$this->assertStringContainsString('/media/2/responsive-images/', $image);
$this->assertStringContainsString('data:image/svg+xml;base64,', $image);
}

/** @test */
Expand All @@ -118,6 +118,6 @@ public function it_will_not_rendering_extra_javascript_or_including_base64_svg_w

$imgTag = $media->refresh()->img();

$this->assertEquals('<img srcset="/media/2/responsive-images/test___ml_bri_340_280.jpg 340w, /media/2/responsive-images/test___ml_bri_284_233.jpg 284w, /media/2/responsive-images/test___ml_bri_237_195.jpg 237w" src="/media/2/test.jpg" width="340">', $imgTag);
$this->assertEquals('<img srcset="http://localhost/media/2/responsive-images/test___medialibrary_original_340_280.jpg 340w, http://localhost/media/2/responsive-images/test___medialibrary_original_284_233.jpg 284w, http://localhost/media/2/responsive-images/test___medialibrary_original_237_195.jpg 237w" src="/media/2/test.jpg" width="340">', $imgTag);
}
}
2 changes: 1 addition & 1 deletion tests/Feature/MediaStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class MediaStreamTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
22 changes: 11 additions & 11 deletions tests/Feature/ResponsiveImages/ResponsiveImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public function a_media_instance_can_get_responsive_image_urls()
$media = $this->testModelWithResponsiveImages->getFirstMedia();

$this->assertEquals([
'/media/1/responsive-images/test___ml_bri_340_280.jpg',
'/media/1/responsive-images/test___ml_bri_284_233.jpg',
'/media/1/responsive-images/test___ml_bri_237_195.jpg',
'http://localhost/media/1/responsive-images/test___medialibrary_original_340_280.jpg',
'http://localhost/media/1/responsive-images/test___medialibrary_original_284_233.jpg',
'http://localhost/media/1/responsive-images/test___medialibrary_original_237_195.jpg',
], $media->getResponsiveImageUrls());

$this->assertEquals([
'/media/1/responsive-images/test___thumb_50_41.jpg',
'http://localhost/media/1/responsive-images/test___thumb_50_41.jpg',
], $media->getResponsiveImageUrls('thumb'));

$this->assertEquals([], $media->getResponsiveImageUrls('non-existing-conversion'));
Expand All @@ -39,17 +39,17 @@ public function a_media_instance_can_generate_the_contents_of_scrset()

$media = $this->testModelWithResponsiveImages->getFirstMedia();

$this->assertContains(
'/media/1/responsive-images/test___ml_bri_340_280.jpg 340w, /media/1/responsive-images/test___ml_bri_284_233.jpg 284w, /media/1/responsive-images/test___ml_bri_237_195.jpg 237w',
$this->assertStringContainsString(
'http://localhost/media/1/responsive-images/test___medialibrary_original_340_280.jpg 340w, http://localhost/media/1/responsive-images/test___medialibrary_original_284_233.jpg 284w, http://localhost/media/1/responsive-images/test___medialibrary_original_237_195.jpg 237w',
$media->getSrcset()
);
$this->assertContains('data:image/svg+xml;base64', $media->getSrcset());
$this->assertStringContainsString('data:image/svg+xml;base64', $media->getSrcset());

$this->assertContains(
'/media/1/responsive-images/test___thumb_50_41.jpg 50w',
$this->assertStringContainsString(
'http://localhost/media/1/responsive-images/test___thumb_50_41.jpg 50w',
$media->getSrcset('thumb')
);
$this->assertContains('data:image/svg+xml;base64,', $media->getSrcset('thumb'));
$this->assertStringContainsString('data:image/svg+xml;base64,', $media->getSrcset('thumb'));
}

/** @test */
Expand All @@ -64,7 +64,7 @@ public function a_responsive_image_can_return_some_properties()

$responsiveImage = $media->responsiveImages()->files->first();

$this->assertEquals('ml_bri', $responsiveImage->generatedFor());
$this->assertEquals('medialibrary_original', $responsiveImage->generatedFor());

$this->assertEquals(340, $responsiveImage->width());

Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/S3Integration/S3IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class S3IntegrationTest extends TestCase
/** @var @string */
protected $s3BaseDirectory;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -27,7 +27,7 @@ public function setUp()
$this->app['config']->set('medialibrary.path_generator', S3TestPathGenerator::class);
}

public function tearDown()
public function tearDown(): void
{
$this->cleanUpS3();

Expand Down Expand Up @@ -127,7 +127,7 @@ public function it_retrieves_a_temporary_media_url_from_s3()
->preservingOriginal()
->toMediaCollection('default', 's3_disk');

$this->assertContains(
$this->assertStringContainsString(
"/{$this->s3BaseDirectory}/{$media->id}/test.jpg",
$media->getTemporaryUrl(Carbon::now()->addMinutes(5))
);
Expand Down Expand Up @@ -157,7 +157,7 @@ public function it_retrieves_a_temporary_media_conversion_url_from_s3()
->addMedia($this->getTestJpg())
->toMediaCollection('default', 's3_disk');

$this->assertContains(
$this->assertStringContainsString(
"/{$this->s3BaseDirectory}/{$media->id}/conversions/test-thumb.jpg",
$media->getTemporaryUrl(Carbon::now()->addMinutes(5), 'thumb')
);
Expand Down
Loading

0 comments on commit b5fb212

Please sign in to comment.