public function testApplyFilterSet() { $image = $this->getMockImage(); $thumbConfig = array('size' => array(180, 180), 'mode' => 'outbound'); $config = $this->getMockFilterConfiguration(); $config->expects($this->atLeastOnce())->method('get')->with('thumbnail')->will($this->returnValue(array('filters' => array('thumbnail' => $thumbConfig)))); $loader = $this->getMockLoader(); $loader->expects($this->once())->method('load')->with($image, $thumbConfig)->will($this->returnValue($image)); $filterManager = new FilterManager($config); $filterManager->addLoader('thumbnail', $loader); $this->assertSame($image, $filterManager->applyFilter($image, 'thumbnail')); }
public function testFilterActionLive() { $router = $this->getMockRouter(); $router->expects($this->any())->method('generate')->with('_imagine_thumbnail', array('path' => 'cats.jpeg'), false)->will($this->returnValue('/media/cache/thumbnail/cats.jpeg')); $dataLoader = new FileSystemLoader($this->imagine, array(), $this->dataDir); $dataManager = new DataManager($this->configuration, 'filesystem'); $dataManager->addLoader('filesystem', $dataLoader); $filterLoader = new ThumbnailFilterLoader(); $filterManager = new FilterManager($this->configuration); $filterManager->addLoader('thumbnail', $filterLoader); $webPathResolver = new WebPathResolver($this->filesystem); $cacheManager = new CacheManager($this->configuration, $router, $this->webRoot, 'web_path'); $cacheManager->addResolver('web_path', $webPathResolver); $controller = new ImagineController($dataManager, $filterManager, $cacheManager); $request = Request::create('/media/cache/thumbnail/cats.jpeg'); $response = $controller->filterAction($request, 'cats.jpeg', 'thumbnail'); $targetPath = realpath($this->webRoot) . '/media/cache/thumbnail/cats.jpeg'; $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response); $this->assertEquals(201, $response->getStatusCode()); $this->assertTrue(file_exists($targetPath)); $this->assertNotEmpty(file_get_contents($targetPath)); return $controller; }
public function testThrowsIfNoPostProcessorAddedForFilterOnApplyFilter() { $originalContent = 'aContent'; $binary = new Binary($originalContent, 'image/png', 'png'); $thumbConfig = array('size' => array(180, 180), 'mode' => 'outbound'); $config = $this->createFilterConfigurationMock(); $config->expects($this->atLeastOnce())->method('get')->with('thumbnail')->will($this->returnValue(array('filters' => array('thumbnail' => $thumbConfig), 'post_processors' => array('foo' => array())))); $thumbConfig = array('size' => array(180, 180), 'mode' => 'outbound'); $image = $this->getMockImage(); $image->expects($this->once())->method('get')->will($this->returnValue($originalContent)); $imagineMock = $this->createImagineMock(); $imagineMock->expects($this->once())->method('load')->with($originalContent)->will($this->returnValue($image)); $loader = $this->getMockLoader(); $loader->expects($this->once())->method('load')->with($this->identicalTo($image), $thumbConfig)->will($this->returnArgument(0)); $filterManager = new FilterManager($config, $imagineMock, $this->getMockMimeTypeGuesser()); $filterManager->addLoader('thumbnail', $loader); $this->setExpectedException('InvalidArgumentException', 'Could not find post processor "foo"'); $filterManager->applyFilter($binary, 'thumbnail'); }