diff --git a/Tests/Functional/Controller/ImagineControllerTest.php b/Tests/Functional/Controller/ImagineControllerTest.php new file mode 100644 index 000000000..0369b6fcf --- /dev/null +++ b/Tests/Functional/Controller/ImagineControllerTest.php @@ -0,0 +1,19 @@ +createClient(); + + $controller = self::$kernel->getContainer()->get('liip_imagine.controller'); + + $this->assertInstanceOf('Liip\ImagineBundle\Controller\ImagineController', $controller); + } +} diff --git a/Tests/Routing/ImagineLoaderTest.php b/Tests/Routing/ImagineLoaderTest.php new file mode 100644 index 000000000..c6092a83e --- /dev/null +++ b/Tests/Routing/ImagineLoaderTest.php @@ -0,0 +1,52 @@ +assertTrue($rc->isSubclassOf('Symfony\Component\Config\Loader\Loader')); + } + + public function testReturnTrueIfResourceTypeImagineOnSupports() + { + $loader = new ImagineLoader('anAction', '', array()); + + $this->assertTrue($loader->supports('aResource', 'imagine')); + } + + public function testReturnFalseIfResourceTypeNotImagineOnSupports() + { + $loader = new ImagineLoader('anAction', '', array()); + + $this->assertFalse($loader->supports('aResource', 'notImagine')); + } + + public function testReturnCollectionWithOneRouterIfOneFilterPassedOnLoad() + { + $loader = new ImagineLoader('liip_imagine.controller:filterAction', '/media/cache', array( + 'thumbnail' => array('filter_config_here') + )); + + $result = $loader->load('aResource', 'aType'); + + $this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $result); + $this->assertCount(1, $result); + + $route = $result->get('_imagine_thumbnail'); + $this->assertEquals( + array( + '_controller' => 'liip_imagine.controller:filterAction', + 'filter' => 'thumbnail', + ), + $route->getDefaults() + ); + } +} diff --git a/Tests/Templating/Helper/ImagineHelperTest.php b/Tests/Templating/Helper/ImagineHelperTest.php new file mode 100644 index 000000000..9c1c814a3 --- /dev/null +++ b/Tests/Templating/Helper/ImagineHelperTest.php @@ -0,0 +1,58 @@ +assertTrue($rc->isSubclassOf('Symfony\Component\Templating\Helper\Helper')); + } + + public function testCouldBeConstructedWithCacheManagerAsArgument() + { + new ImagineHelper($this->createCacheManagerMock()); + } + + public function testAllowGetName() + { + $helper = new ImagineHelper($this->createCacheManagerMock()); + + $this->assertEquals('liip_imagine', $helper->getName()); + } + + public function testProxyCallToCacheManagerOnFilter() + { + $expectedPath = 'thePathToTheImage'; + $expectedFilter = 'thumbnail'; + $expectedCachePath = 'thePathToTheCachedImage'; + + $cacheManager = $this->createCacheManagerMock(); + $cacheManager + ->expects($this->once()) + ->method('getBrowserPath') + ->with($expectedPath, $expectedFilter) + ->will($this->returnValue($expectedCachePath)) + ; + + $helper = new ImagineHelper($cacheManager); + + $this->assertEquals($expectedCachePath, $helper->filter($expectedPath, $expectedFilter)); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|CacheManager + */ + protected function createCacheManagerMock() + { + return $this->getMock('Liip\ImagineBundle\Imagine\Cache\CacheManager', array(), array(), '', false); + } +} diff --git a/Tests/Templating/ImagineExtensionTest.php b/Tests/Templating/ImagineExtensionTest.php new file mode 100644 index 000000000..1d32c8d70 --- /dev/null +++ b/Tests/Templating/ImagineExtensionTest.php @@ -0,0 +1,69 @@ +assertTrue($rc->isSubclassOf('Twig_Extension')); + } + + public function testCouldBeConstructedWithCacheManagerAsArgument() + { + new ImagineExtension($this->createCacheManagerMock()); + } + + public function testAllowGetName() + { + $extension = new ImagineExtension($this->createCacheManagerMock()); + + $this->assertEquals('liip_imagine', $extension->getName()); + } + + public function testProxyCallToCacheManagerOnFilter() + { + $expectedPath = 'thePathToTheImage'; + $expectedFilter = 'thumbnail'; + $expectedCachePath = 'thePathToTheCachedImage'; + + $cacheManager = $this->createCacheManagerMock(); + $cacheManager + ->expects($this->once()) + ->method('getBrowserPath') + ->with($expectedPath, $expectedFilter) + ->will($this->returnValue($expectedCachePath)) + ; + + $extension = new ImagineExtension($cacheManager); + + $this->assertEquals($expectedCachePath, $extension->filter($expectedPath, $expectedFilter)); + } + + public function testAddsFilterMethodToFiltersList() + { + $extension = new ImagineExtension($this->createCacheManagerMock()); + + $filters = $extension->getFilters(); + + $this->assertInternalType('array', $filters); + $this->assertCount(1, $filters); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|CacheManager + */ + protected function createCacheManagerMock() + { + return $this->getMock('Liip\ImagineBundle\Imagine\Cache\CacheManager', array(), array(), '', false); + } +} + diff --git a/composer.json b/composer.json index 231c31cfb..3b9a58ef1 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "require-dev": { "symfony/browser-kit": "~2.3", "symfony/yaml": "~2.3", + "twig/twig": "~1.0", "doctrine/cache": "~1.1", "aws/aws-sdk-php": "~2.4", "amazonwebservices/aws-sdk-for-php": "~1.0"