Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Tests for bundle features #140

Merged
merged 24 commits into from
Feb 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3c8c825
AbstractFilesystemResolverTest + CacheManagerTest
havvg Feb 8, 2013
8a0b97f
add WebPathResolverTest testing default settings
havvg Feb 8, 2013
daf167c
add @covers annotation for existing tests
havvg Feb 8, 2013
659dbb7
add CacheManagerTest::testGenerateUrl
havvg Feb 8, 2013
7fe2765
add BasePath/-Url & Rewrite tests for WebResolver
havvg Feb 10, 2013
bff5097
add tests for WebPathResolver::clear
havvg Feb 10, 2013
5c6064e
move CacheManagerAwareInterface out of WebPath
havvg Feb 10, 2013
10ee3bb
fix AmazonS3Resolver::resolve on existing & remove
havvg Feb 12, 2013
d8ac9ca
fix misleading phpDoc for getBrowserPath methods
havvg Feb 12, 2013
d176d53
add test ensuring AmazonS3Resolver does not clear
havvg Feb 12, 2013
2adc28c
update NoCacheResolver::resolve to set base path
havvg Feb 12, 2013
7e1ff1f
test invalid dir in AbstractFilesystemResolver
havvg Feb 12, 2013
0dedc7c
add CacheClearerTest
havvg Feb 12, 2013
56ef9d7
skip CacheClearerTest if interface is missing
havvg Feb 12, 2013
54a6b30
add DataManagerTest
havvg Feb 12, 2013
b6e34d8
add FilterManagerTest
havvg Feb 12, 2013
94150df
add FilterConfigurationTest
havvg Feb 12, 2013
035c97f
add PdfTransformerTest, add TransformerInterface
havvg Feb 12, 2013
fdf66f2
clean up phpDoc and use-statements
havvg Feb 12, 2013
3de7712
add FileSystemLoaderTest
havvg Feb 12, 2013
5bd5d71
add StreamLoaderTest
havvg Feb 12, 2013
0f93e17
add --prefer-source option to composer require
havvg Feb 12, 2013
3764516
add ImagineControllerTest
havvg Feb 12, 2013
aa6c851
remove equality check on file content
havvg Feb 12, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
- SYMFONY_VERSION=dev-master

before_script:
- composer require symfony/framework-bundle:${SYMFONY_VERSION}
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
- composer install --dev --prefer-source

script: phpunit --coverage-text
Expand Down
11 changes: 5 additions & 6 deletions Controller/ImagineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Liip\ImagineBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class ImagineController
{
/**
Expand All @@ -26,7 +27,7 @@ class ImagineController
protected $cacheManager;

/**
* Constructor
* Constructor.
*
* @param DataManager $dataManager
* @param FilterManager $filterManager
Expand All @@ -40,9 +41,7 @@ public function __construct(DataManager $dataManager, FilterManager $filterManag
}

/**
* This action applies a given filter to a given image,
* optionally saves the image and
* outputs it to the browser at the same time
* This action applies a given filter to a given image, optionally saves the image and outputs it to the browser at the same time.
*
* @param Request $request
* @param string $path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Liip\ImagineBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface,
Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class CreateCacheDirectoriesCompilerPass implements CompilerPassInterface
{
Expand Down
6 changes: 3 additions & 3 deletions DependencyInjection/Compiler/LoadersCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Liip\ImagineBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface,
Symfony\Component\DependencyInjection\ContainerBuilder,
Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class LoadersCompilerPass implements CompilerPassInterface
{
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Liip\ImagineBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder,
Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
Expand Down
8 changes: 3 additions & 5 deletions DependencyInjection/LiipImagineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
namespace Liip\ImagineBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\DependencyInjection\Definition;

use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Reference;

use Liip\ImagineBundle\LiipImagineBundle;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;

class LiipImagineExtension extends Extension
{
Expand Down
19 changes: 9 additions & 10 deletions Imagine/Cache/CacheClearer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,33 @@

/**
* Clears the Liip Imagine Bundle cache
*
*
* @author Josiah <[email protected]>
*/
class CacheClearer implements CacheClearerInterface
{
/**
* The Cache Manager
*
* @var CacheManager
*/
private $cacheManager;
protected $cacheManager;

/**
* The prefix applied to all cached images
*
* @var string
*/
private $cachePrefix;
protected $cachePrefix;

/**
* Constructor.
*
* @param CacheManager $cacheManager
* @param string $cachePrefix The prefix applied to all cached images.
*/
public function __construct(CacheManager $cacheManager, $cachePrefix)
{
$this->cacheManager = $cacheManager;
$this->cachePrefix = $cachePrefix;
}

/**
* (non-PHPdoc)
* @see Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface::clear()
Expand Down
76 changes: 51 additions & 25 deletions Imagine/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@

namespace Liip\ImagineBundle\Imagine\Cache;

use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface,
Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface;
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;

use Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpFoundation\Response,
Symfony\Component\Routing\RouterInterface,
Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\RouterInterface;

class CacheManager
{
/**
* @var FilterConfiguration
*/
private $filterConfig;
protected $filterConfig;

/**
* @var RouterInterface
*/
private $router;
protected $router;

/**
* @var string
*/
private $webRoot;
protected $webRoot;

/**
* @var string
*/
private $defaultResolver;
protected $defaultResolver;

/**
* @var array
* @var ResolverInterface[]
*/
private $resolvers = array();
protected $resolvers = array();

/**
* Constructs the cache manager to handle Resolvers based on the provided FilterConfiguration.
Expand All @@ -54,6 +54,8 @@ public function __construct(FilterConfiguration $filterConfig, RouterInterface $
}

/**
* Adds a resolver to handle cached images for the given filter.
*
* @param string $filter
* @param ResolverInterface $resolver
*
Expand All @@ -69,6 +71,8 @@ public function addResolver($filter, ResolverInterface $resolver)
}

/**
* Returns the configured web root path.
*
* @return string
*/
public function getWebRoot()
Expand All @@ -77,10 +81,17 @@ public function getWebRoot()
}

/**
* Gets a resolver for the given filter.
*
* In case there is no specific resolver, but a default resolver has been configured, the default will be returned.
*
* @param string $filter
*
* @return ResolverInterface
*
* @throws \InvalidArgumentException If neither a specific nor a default resolver is available.
*/
private function getResolver($filter)
protected function getResolver($filter)
{
$config = $this->filterConfig->get($filter);

Expand All @@ -97,43 +108,45 @@ private function getResolver($filter)
}

/**
* Gets filtered path for rendering in the browser
* Gets filtered path for rendering in the browser.
*
* @param string $path
* @see ResolverInterface::getBrowserPath
*
* @param string $path The path where the resolved file is expected.
* @param string $filter
* @param boolean $absolute
*
* @return string
*/
public function getBrowserPath($targetPath, $filter, $absolute = false)
public function getBrowserPath($path, $filter, $absolute = false)
{
return $this->getResolver($filter)->getBrowserPath($targetPath, $filter, $absolute);
return $this->getResolver($filter)->getBrowserPath($path, $filter, $absolute);
}

/**
* Returns a web accessible URL.
*
* @param string $targetPath The target path provided by the resolve method.
* @param string $path The path where the resolved file is expected.
* @param string $filter The name of the imagine filter in effect.
* @param bool $absolute Whether to generate an absolute URL or a relative path is accepted.
* In case the resolver does not support relative paths, it may ignore this flag.
*
* @return string
*/
public function generateUrl($targetPath, $filter, $absolute = false)
public function generateUrl($path, $filter, $absolute = false)
{
$config = $this->filterConfig->get($filter);

if (isset($config['format'])) {
$pathinfo = pathinfo($targetPath);
$pathinfo = pathinfo($path);
// the extension should be forced and a directory is detected
if ((!isset($pathinfo['extension']) || $pathinfo['extension'] !== $config['format'])
&& isset($pathinfo['dirname'])) {
$targetPath = $pathinfo['dirname'].'/'.$pathinfo['filename'].'.'.$config['format'];
$path = $pathinfo['dirname'].'/'.$pathinfo['filename'].'.'.$config['format'];
}
}

$params = array('path' => ltrim($targetPath, '/'));
$params = array('path' => ltrim($path, '/'));

return str_replace(
urlencode($params['path']),
Expand All @@ -143,7 +156,7 @@ public function generateUrl($targetPath, $filter, $absolute = false)
}

/**
* Resolves filtered path for rendering in the browser
* Resolves filtered path for rendering in the browser.
*
* @param Request $request
* @param string $path
Expand All @@ -154,7 +167,7 @@ public function generateUrl($targetPath, $filter, $absolute = false)
public function resolve(Request $request, $path, $filter)
{
if (false !== strpos($path, '/../') || 0 === strpos($path, '../')) {
throw new NotFoundHttpException(sprintf("Source image was searched with '%s' out side of the defined root path", $path));
throw new NotFoundHttpException(sprintf("Source image was searched with '%s' outside of the defined root path", $path));
}

try {
Expand All @@ -167,7 +180,9 @@ public function resolve(Request $request, $path, $filter)
}

/**
* Store successful responses with the cache resolver
* Store successful responses with the cache resolver.
*
* @see ResolverInterface::store
*
* @param Response $response
* @param string $targetPath
Expand All @@ -187,6 +202,8 @@ public function store(Response $response, $targetPath, $filter)
/**
* Remove a cached image from the storage.
*
* @see ResolverInterface::remove
*
* @param string $targetPath
* @param string $filter
*
Expand All @@ -197,6 +214,15 @@ public function remove($targetPath, $filter)
return $this->getResolver($filter)->remove($targetPath, $filter);
}

/**
* Clear the cache of all resolvers.
*
* @see ResolverInterface::clear
*
* @param string $cachePrefix
*
* @return void
*/
public function clearResolversCache($cachePrefix)
{
foreach ($this->resolvers as $resolver) {
Expand Down
Loading