chooseVariation() публичный Метод

Choose an image variation based on the transformations and the original size of the image
public chooseVariation ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface The current event
Пример #1
0
 /**
  * @covers Imbo\EventListener\ImageVariations::chooseVariation
  * @covers Imbo\EventListener\ImageVariations::getMaxWidth
  */
 public function testUpdatesResponseAndImageModelOnSuccess()
 {
     $width = 1024;
     $height = 768;
     $transformationWidth = 512;
     $variationWidth = 800;
     $variationHeight = 600;
     $variationBlob = 'blob';
     $lastModified = new DateTime();
     $transformations = [['name' => 'desaturate', 'params' => []], ['name' => 'maxSize', 'params' => ['width' => $transformationWidth]]];
     $this->imageModel->expects($this->once())->method('getWidth')->will($this->returnValue($width));
     $this->imageModel->expects($this->once())->method('getHeight')->will($this->returnValue($height));
     $this->request->expects($this->once())->method('getTransformations')->will($this->returnValue($transformations));
     $this->db->expects($this->once())->method('getBestMatch')->with($this->publicKey, $this->imageIdentifier, $transformationWidth)->will($this->returnValue(['width' => $variationWidth, 'height' => $variationHeight]));
     $this->eventManager->expects($this->at(0))->method('trigger')->with('image.transformations.adjust', ['transformationIndex' => 1, 'ratio' => $width / $variationWidth]);
     $this->storage->expects($this->once())->method('getImageVariation')->with($this->publicKey, $this->imageIdentifier, $variationWidth)->will($this->returnValue($variationBlob));
     $this->imageStorage->expects($this->once())->method('getLastModified')->with($this->publicKey, $this->imageIdentifier)->will($this->returnValue($lastModified));
     $this->response->expects($this->once())->method('setLastModified')->with($lastModified);
     $this->imageModel->expects($this->once())->method('setBlob')->with($variationBlob)->will($this->returnValue($this->imageModel));
     $this->imageModel->expects($this->once())->method('setWidth')->with($variationWidth)->will($this->returnValue($this->imageModel));
     $this->imageModel->expects($this->once())->method('setHeight')->with($variationHeight)->will($this->returnValue($this->imageModel));
     $this->responseHeaders->expects($this->once())->method('set')->with('X-Imbo-ImageVariation', $variationWidth . 'x' . $variationHeight);
     $this->event->expects($this->once())->method('stopPropagation');
     $this->eventManager->expects($this->at(1))->method('trigger')->with('image.loaded');
     $this->listener->chooseVariation($this->event);
 }