Doesn't use DataManager/CacheManager as it's directly bound to IO Repository for convenience.
Inheritance: implements eZ\Publish\SPI\Variation\VariationHandler
 /**
  * Method for parsing ezimage field.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Field $field
  * @param \eZ\Publish\API\Repository\Values\Content\Content $content
  *
  * @return string
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidVariationException
  * @throws \eZ\Publish\Core\MVC\Exception\SourceImageNotFoundException
  */
 public function ezimage(Field $field, Content $content)
 {
     if (!isset($field->value->id)) {
         return '';
     }
     $variations = $this->configResolver->getParameter('image_variations');
     $variation = 'original';
     $requestedVariation = $this->request->getCurrentRequest()->get('image');
     if (null !== $requestedVariation || in_array($requestedVariation, array_keys($variations))) {
         $variation = $requestedVariation;
     }
     try {
         return $this->imageVariationService->getVariation($field, $content->versionInfo, $variation)->uri;
     } catch (SourceImageNotFoundException $exception) {
         return '';
     }
 }
 /**
  * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidVariationException
  */
 public function testGetVariationInvalidVariation()
 {
     $originalPath = 'foo/bar/image.jpg';
     $variationName = 'my_variation';
     $imageId = '123-45';
     $imageValue = new ImageValue(array('id' => $originalPath, 'imageId' => $imageId));
     $field = new Field(array('value' => $imageValue));
     $this->ioResolver->expects($this->once())->method('isStored')->with($originalPath, $variationName)->will($this->returnValue(true));
     $this->logger->expects($this->once())->method('debug');
     $this->dataLoader->expects($this->once())->method('find');
     $this->filterManager->expects($this->never())->method('applyFilter');
     $this->ioResolver->expects($this->never())->method('store');
     $this->ioResolver->expects($this->once())->method('resolve')->with($originalPath, $variationName)->will($this->throwException(new NotResolvableException()));
     $this->aliasGenerator->getVariation($field, new VersionInfo(), $variationName);
 }
Ejemplo n.º 3
0
 public function testGetVariationAlreadyStored()
 {
     $originalPath = 'foo/bar/image.jpg';
     $variationName = 'my_variation';
     $imageId = '123-45';
     $imageValue = new ImageValue(array('id' => $originalPath, 'imageId' => $imageId));
     $field = new Field(array('value' => $imageValue));
     $expectedUrl = "http://localhost/foo/bar/image_{$variationName}.jpg";
     $this->ioResolver->expects($this->once())->method('isStored')->with($originalPath, $variationName)->will($this->returnValue(true));
     $this->logger->expects($this->once())->method('debug');
     $this->dataLoader->expects($this->once())->method('find');
     $this->filterManager->expects($this->never())->method('applyFilter');
     $this->ioResolver->expects($this->never())->method('store');
     $this->ioResolver->expects($this->once())->method('resolve')->with($originalPath, $variationName)->will($this->returnValue($expectedUrl));
     $expected = new ImageVariation(array('name' => $variationName, 'fileName' => "image_{$variationName}.jpg", 'dirPath' => 'http://localhost/foo/bar', 'uri' => $expectedUrl, 'imageId' => $imageId));
     $this->assertEquals($expected, $this->aliasGenerator->getVariation($field, new VersionInfo(), $variationName));
 }