From 455d554ace6ed31630c69620934d5c4cc9409b46 Mon Sep 17 00:00:00 2001 From: Sebastian De Deyne Date: Tue, 22 Sep 2015 10:43:34 +0200 Subject: [PATCH] Allow 0 for and parameters in --- CHANGELOG.md | 3 +++ src/Conversion/Conversion.php | 10 ++++++++-- tests/Conversion/ConversionTest.php | 14 +++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47b4b89e9..943a5736f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All Notable changes to `laravel-medialibrary` will be documented in this file +##3.2.5 +- Allow 0 for `x` and `y` parameters in `setRectangle` + ##3.2.4 - Removed dependency on spatie/eloquent-sortable diff --git a/src/Conversion/Conversion.php b/src/Conversion/Conversion.php index e76c215b4..e130c7c29 100644 --- a/src/Conversion/Conversion.php +++ b/src/Conversion/Conversion.php @@ -301,8 +301,14 @@ public function setFit($fit) public function setRectangle($width, $height, $x, $y) { foreach (compact('width', 'height', 'x', 'y') as $name => $value) { - if (!is_numeric($value) || $value < 1) { - throw new InvalidConversionParameter($name.' should be numeric and greater than 1'); + if (! is_numeric($value)) { + throw new InvalidConversionParameter($name.' should be numeric'); + } + } + + foreach (compact('width', 'height') as $name => $value) { + if ($value < 1) { + throw new InvalidConversionParameter($name.' should be greater than 1'); } } diff --git a/tests/Conversion/ConversionTest.php b/tests/Conversion/ConversionTest.php index a1e02aa7c..88cd72ed1 100644 --- a/tests/Conversion/ConversionTest.php +++ b/tests/Conversion/ConversionTest.php @@ -231,7 +231,19 @@ public function it_can_add_rectangle_to_a_manipulation() /** * @test */ - public function it_throw_an_exception_for_an_invalid_rectangle() + public function it_allows_zero_x_y_coordinates_in_rectangle_manipulations() + { + $conversion = $this->conversion->setRectangle(100, 200, 0, 0); + + $this->arrayHasKey('rect', $this->conversion->getManipulations()[0]); + $this->assertEquals('100,200,0,0', $this->conversion->getManipulations()[0]['rect']); + $this->assertInstanceOf(\Spatie\MediaLibrary\Conversion\Conversion::class, $conversion); + } + + /** + * @test + */ + public function it_throws_an_exception_for_an_invalid_rectangle() { $this->setExpectedException(\Spatie\MediaLibrary\Exceptions\InvalidConversionParameter::class); $this->conversion->setRectangle('blabla', 200, 300, 400);