Author: Christer Edvartsen (cogo@starzinger.net)
Inheritance: extends Transformation, implements Imbo\EventListener\ListenerInterface
Esempio n. 1
0
 /**
  * @dataProvider getImageParams
  * @covers Imbo\Image\Transformation\Crop::transform
  */
 public function testUsesAllParamsWithImagick($params, $width, $height, $x = 0, $y = 0, $shouldCrop = true)
 {
     $image = $this->getMock('Imbo\\Model\\Image');
     $imagick = $this->getMock('Imagick');
     $image->expects($this->any())->method('getWidth')->will($this->returnValue($width));
     $image->expects($this->any())->method('getHeight')->will($this->returnValue($height));
     if ($shouldCrop) {
         $image->expects($this->once())->method('setWidth')->with($width)->will($this->returnSelf());
         $image->expects($this->once())->method('setHeight')->with($height)->will($this->returnSelf());
         $imagick->expects($this->once())->method('cropImage')->with($width, $height, $x, $y);
         $imagick->expects($this->once())->method('getImageGeometry')->will($this->returnValue(array('width' => $width, 'height' => $height)));
     } else {
         $imagick->expects($this->never())->method('cropImage');
     }
     $event = $this->getMock('Imbo\\EventManager\\Event');
     $event->expects($this->at(0))->method('getArgument')->with('image')->will($this->returnValue($image));
     $event->expects($this->at(1))->method('getArgument')->with('params')->will($this->returnValue($params));
     $crop = new Crop();
     $crop->setImagick($imagick)->transform($event);
 }
Esempio n. 2
0
 /**
  * @dataProvider getInvalidImageParams
  * @covers Imbo\Image\Transformation\Crop::transform
  */
 public function testThrowsOnInvalidCropParams($params, $originalWidth, $originalHeight, $errRegex)
 {
     $image = $this->getMock('Imbo\\Model\\Image');
     $imagick = $this->getMock('Imagick');
     $image->expects($this->any())->method('getWidth')->will($this->returnValue($originalWidth));
     $image->expects($this->any())->method('getHeight')->will($this->returnValue($originalHeight));
     if ($errRegex) {
         $this->setExpectedExceptionRegExp('Imbo\\Exception\\TransformationException', $errRegex);
         $imagick->expects($this->never())->method('cropImage');
     } else {
         $image->expects($this->once())->method('setWidth')->will($this->returnSelf());
         $image->expects($this->once())->method('setHeight')->will($this->returnSelf());
         $imagick->expects($this->once())->method('cropImage');
     }
     $event = $this->getMock('Imbo\\EventManager\\Event');
     $event->expects($this->at(0))->method('getArgument')->with('image')->will($this->returnValue($image));
     $event->expects($this->at(1))->method('getArgument')->with('params')->will($this->returnValue($params));
     $crop = new Crop();
     $crop->setImagick($imagick)->transform($event);
 }