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

fix broken tests on windows #179

Merged
merged 2 commits into from
May 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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']) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's \\ - a special directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On windows, pathinfo seems to return " \ " as the dirname which causes the if statement to be true.. when it should not be, to ensure the correct behavior based on the existing tests.

$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