Skip to content

Commit

Permalink
Allow 0 for and parameters in
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiandedeyne committed Sep 22, 2015
1 parent dc5a0da commit 455d554
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions src/Conversion/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down
14 changes: 13 additions & 1 deletion tests/Conversion/ConversionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 455d554

Please sign in to comment.