public function testAddFilter()
 {
     $moduleOptions = new ModuleOptions();
     $moduleOptions->addFilter('foo_and_crop', ['foo' => 'crop']);
     $this->assertCount(1, $moduleOptions->getFilters());
     $this->assertEquals(['foo' => 'crop'], $moduleOptions->getFilters()['foo_and_crop']);
 }
 public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $options = new ModuleOptions();
     $options->setImageResolvers([1000 => 'image_map']);
     $serviceManager->setService('HtImg\\ModuleOptions', $options);
     $resolverManager = $this->getMock('HtImgModule\\Imagine\\Resolver\\ResolverManager');
     $resolverManager->expects($this->once())->method('get')->will($this->returnValue($this->getMock('Zend\\View\\Resolver\\ResolverInterface')));
     $serviceManager->setService('HtImgModule\\Imagine\\Resolver\\ResolverManager', $resolverManager);
     $factory = new RelativePathResolverFactory();
     $this->assertInstanceOf('HtImgModule\\Imagine\\Resolver\\AggregateResolver', $factory->createService($serviceManager));
 }
 /**
  * @covers HtImgModule\Service\CacheManager::cacheExists
  */
 public function testCacheExists()
 {
     $options = new ModuleOptions();
     $cacheManager = new CacheManager($options);
     $imagine = new Imagine();
     $image = $imagine->open(RESOURCES_DIR . '/Archos.jpg');
     $options->setWebRoot(RESOURCES_DIR);
     $options->setCachePath('.');
     $cacheManager->createCache('awesome/archos-crop.jpg', 'crop', $image);
     $cacheFile = RESOURCES_DIR . '/crop/awesome/archos-crop.jpg';
     $this->assertTrue($cacheManager->cacheExists('awesome/archos-crop.jpg', 'crop'));
     $this->assertFalse($cacheManager->cacheExists('awesome/random-crop.jpg', 'crop'));
 }
 /**
  * @covers HtImgModule\Imagine\Filter\FilterManager::applyFilter
  */
 public function testApplyFilter()
 {
     $options = new ModuleOptions();
     $filterLoaders = new ServiceManager();
     $loader = $this->getMock('HtImgModule\\Imagine\\Filter\\Loader\\LoaderInterface');
     $filter = $this->getMock('Imagine\\Filter\\FilterInterface');
     $image = $this->getMock('Imagine\\Image\\ImageInterface');
     $filteredImage = $this->getMock('Imagine\\Image\\ImageInterface');
     $loader->expects($this->any())->method('load')->will($this->returnValue($filter));
     $filter->expects($this->once())->method('apply')->will($this->returnValue($filteredImage));
     $filterLoaders->setService('bar_filter', $loader);
     $filterManager = new FilterManager($options, $filterLoaders);
     $options->addFilter('bar_filter', ['type' => 'bar_filter', 'options' => ['key' => 'value']]);
     $this->assertEquals($filteredImage, $filterManager->applyFilter($image, 'bar_filter'));
 }
Exemple #5
0
 public function testGetImageFromCacheWithFullUrl()
 {
     $options = new ModuleOptions();
     $options->setCacheUrl('http://static.example.com');
     $cacheManager = $this->getMock('HtImgModule\\Service\\CacheManagerInterface', array('cacheExists', 'getCacheUrl', 'getCachePath', 'createCache', 'deleteCache', 'isCachingEnabled', 'useCacheUrl'), array($options));
     $cacheManager->expects($this->once())->method('cacheExists')->with('path/to/some/random/image/', 'foo_view_filter', 'jpeg')->will($this->returnValue(true));
     $cacheManager->expects($this->once())->method('useCacheUrl')->will($this->returnValue(true));
     $cacheManager->expects($this->once())->method('getCacheUrl')->with('path/to/some/random/image/', 'foo_view_filter', 'jpeg', true)->will($this->returnValue('http://static.example.com/foo_view_filter/path/to/some/random/image/flowers.jpg'));
     $loaderManager = $this->getMock('HtImgModule\\Imagine\\Loader\\LoaderManagerInterface');
     $filterManager = $this->getMock('HtImgModule\\Imagine\\Filter\\FilterManagerInterface');
     $filterOptions = ['format' => 'jpeg'];
     $filterManager->expects($this->once())->method('getFilterOptions')->with('foo_view_filter')->will($this->returnValue($filterOptions));
     $cacheManager->expects($this->once())->method('isCachingEnabled')->with('foo_view_filter', $filterOptions)->will($this->returnValue(true));
     $helper = new ImgUrl($cacheManager, $filterManager, $loaderManager);
     $renderer = $this->getMock('Zend\\View\\Renderer\\PhpRenderer');
     $helper->setView($renderer);
     $this->assertEquals('http://static.example.com/foo_view_filter/path/to/some/random/image/flowers.jpg', $helper('path/to/some/random/image/', 'foo_view_filter'));
 }