Skip to content

Commit

Permalink
Merge pull request #179 from kevarch/tests/windows-support
Browse files Browse the repository at this point in the history
fix broken tests on windows
  • Loading branch information
havvg committed May 16, 2013
2 parents 7b2cd5c + 02fd524 commit 9d59494
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Imagine/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,15 @@ public function generateUrl($path, $filter, $absolute = false)

if (isset($config['format'])) {
$pathinfo = pathinfo($path);

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

if ('\\' === $pathinfo['dirname']) {
$pathinfo['dirname'] = '';
}

$path = $pathinfo['dirname'].'/'.$pathinfo['filename'].'.'.$config['format'];
}
}
Expand Down
4 changes: 2 additions & 2 deletions Imagine/Data/Loader/FileSystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public function find($path)

$file = $this->rootPath.'/'.ltrim($path, '/');
$info = $this->getFileInfo($file);
$absolutePath = $info['dirname'].'/'.$info['basename'];
$absolutePath = $info['dirname'].DIRECTORY_SEPARATOR.$info['basename'];

$name = $info['dirname'].'/'.$info['filename'];
$name = $info['dirname'].DIRECTORY_SEPARATOR.$info['filename'];

$targetFormat = null;
// set a format if an extension is found and is allowed
Expand Down
2 changes: 1 addition & 1 deletion Tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function setUp()
{
$this->fixturesDir = __DIR__.'/Fixtures';

$this->tempDir = sys_get_temp_dir().'/liip_imagine_test';
$this->tempDir = str_replace('/', DIRECTORY_SEPARATOR, sys_get_temp_dir().'/liip_imagine_test');

$this->filesystem = new Filesystem();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Imagine/Cache/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CacheManagerTest extends AbstractTest
public function testGetWebRoot()
{
$cacheManager = new CacheManager($this->getMockFilterConfiguration(), $this->getMockRouter(), $this->fixturesDir.'/assets');
$this->assertEquals($this->fixturesDir.'/assets', $cacheManager->getWebRoot());
$this->assertEquals(str_replace('/', DIRECTORY_SEPARATOR, $this->fixturesDir.'/assets'), $cacheManager->getWebRoot());
}

public function testAddCacheManagerAwareResolver()
Expand Down
10 changes: 10 additions & 0 deletions Tests/Imagine/Cache/Resolver/AbstractFilesystemResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ class AbstractFilesystemResolverTest extends AbstractTest
{
public function testStoreCyrillicFilename()
{
if (false !== strpos(strtolower(PHP_OS), 'win')) {
$this->markTestSkipped('file_get_contents can not read files with utf-8 file names on windows');
}

$image = $this->fixturesDir.'/assets/АГГЗ.jpeg';

$data = file_get_contents($image);

$response = new Response($data, 200, array(
'content-type' => 'image/jpeg',
));
Expand All @@ -30,6 +36,10 @@ public function testStoreCyrillicFilename()

public function testStoreInvalidDirectory()
{
if (false !== strpos(strtolower(PHP_OS), 'win')) {
$this->markTestSkipped('mkdir mode is ignored on windows');
}

$resolver = $this->getMockAbstractFilesystemResolver(new Filesystem());

$this->filesystem->mkdir($this->tempDir.'/unwriteable', 0555);
Expand Down
10 changes: 5 additions & 5 deletions Tests/Imagine/Cache/Resolver/WebPathResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testDefaultBehavior()
$this->cacheManager
->expects($this->atLeastOnce())
->method('generateUrl')
->will($this->returnValue('/media/cache/thumbnail/cats.jpeg'))
->will($this->returnValue(str_replace('/', DIRECTORY_SEPARATOR, '/media/cache/thumbnail/cats.jpeg')))
;

$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
Expand All @@ -75,7 +75,7 @@ public function testDefaultBehavior()
// Resolve the requested image for the given filter.
$targetPath = $this->resolver->resolve($request, 'cats.jpeg', 'thumbnail');
// The realpath() is important for filesystems that are virtual in some way (encrypted, different mount options, ..)
$this->assertEquals(realpath($this->cacheDir).'/thumbnail/cats.jpeg', $targetPath,
$this->assertEquals(str_replace('/', DIRECTORY_SEPARATOR, realpath($this->cacheDir).'/thumbnail/cats.jpeg'), $targetPath,
'->resolve() correctly converts the requested file into target path within webRoot.');
$this->assertFalse(file_exists($targetPath),
'->resolve() does not create the file within the target path.');
Expand Down Expand Up @@ -170,20 +170,20 @@ public function testResolveWithBasePath()
$this->cacheManager
->expects($this->atLeastOnce())
->method('generateUrl')
->will($this->returnValue('/sandbox/app_dev.php/media/cache/thumbnail/cats.jpeg'))
->will($this->returnValue(str_replace('/', DIRECTORY_SEPARATOR, '/sandbox/app_dev.php/media/cache/thumbnail/cats.jpeg')))
;

$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request
->expects($this->atLeastOnce())
->method('getBaseUrl')
->will($this->returnValue('/sandbox/app_dev.php'))
->will($this->returnValue(str_replace('/', DIRECTORY_SEPARATOR, '/sandbox/app_dev.php')))
;

// Resolve the requested image for the given filter.
$targetPath = $this->resolver->resolve($request, 'cats.jpeg', 'thumbnail');
// The realpath() is important for filesystems that are virtual in some way (encrypted, different mount options, ..)
$this->assertEquals(realpath($this->cacheDir).'/thumbnail/cats.jpeg', $targetPath,
$this->assertEquals(str_replace('/', DIRECTORY_SEPARATOR, realpath($this->cacheDir).'/thumbnail/cats.jpeg'), $targetPath,
'->resolve() correctly converts the requested file into target path within webRoot.');
$this->assertFalse(file_exists($targetPath),
'->resolve() does not create the file within the target path.');
Expand Down

0 comments on commit 9d59494

Please sign in to comment.