2012-09-04 13:18:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Knp\Bundle\GaufretteBundle\Tests\Functional;
|
|
|
|
|
2012-09-06 15:02:21 +00:00
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
2012-10-10 15:32:37 +00:00
|
|
|
use Gaufrette\StreamWrapper;
|
2012-09-04 13:18:10 +00:00
|
|
|
|
|
|
|
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
private $cacheDir;
|
2012-09-05 18:29:39 +00:00
|
|
|
private $kernel;
|
2012-09-04 13:18:10 +00:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->cacheDir = __DIR__.'/Resources/cache';
|
|
|
|
if (file_exists($this->cacheDir)) {
|
|
|
|
$filesystem = new Filesystem();
|
|
|
|
$filesystem->remove($this->cacheDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
mkdir($this->cacheDir, 0777, true);
|
2012-09-05 18:29:39 +00:00
|
|
|
|
|
|
|
$this->kernel = new TestKernel('test', false);
|
|
|
|
$this->kernel->boot();
|
2012-09-04 13:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
if (file_exists($this->cacheDir)) {
|
|
|
|
$filesystem = new Filesystem();
|
|
|
|
$filesystem->remove($this->cacheDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldAllowForFilesystemAlias()
|
|
|
|
{
|
2012-09-05 18:29:39 +00:00
|
|
|
$this->assertInstanceOf('Gaufrette\Filesystem', $this->kernel->getContainer()->get('foo_filesystem'));
|
2012-09-04 13:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldWorkForOtherEnv()
|
|
|
|
{
|
|
|
|
$kernel = new TestKernel('dev', false);
|
|
|
|
$kernel->boot();
|
|
|
|
|
|
|
|
$container = $kernel->getContainer();
|
|
|
|
$this->assertInstanceOf('Gaufrette\Filesystem', $container->get('foo_filesystem'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldAllowAccessToAllPublicServices()
|
|
|
|
{
|
2012-09-05 18:29:39 +00:00
|
|
|
$this->assertInstanceOf('Knp\Bundle\GaufretteBundle\FilesystemMap', $this->kernel->getContainer()->get('knp_gaufrette.filesystem_map'));
|
2012-09-04 13:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldAllowAccessToFilesystemThoughFilesystemMap()
|
|
|
|
{
|
2012-09-05 18:29:39 +00:00
|
|
|
$this->assertInstanceOf('Gaufrette\Filesystem', $this->kernel->getContainer()->get('knp_gaufrette.filesystem_map')->get('foo'));
|
|
|
|
}
|
2012-09-04 13:18:10 +00:00
|
|
|
|
2012-09-05 18:29:39 +00:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldAllowAccessToLocalFilesystem()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf('Gaufrette\Adapter\Local', $this->kernel->getContainer()->get('foo_filesystem')->getAdapter());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldAllowAccessToCacheFilesystem()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf('Gaufrette\Adapter\Cache', $this->kernel->getContainer()->get('cache_filesystem')->getAdapter());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldAllowAccessToFtpFilesystem()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf('Gaufrette\Adapter\Ftp', $this->kernel->getContainer()->get('ftp_filesystem')->getAdapter());
|
2012-09-04 13:18:10 +00:00
|
|
|
}
|
2012-10-10 15:32:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldAllowToNotConfigureStreamWrapper()
|
|
|
|
{
|
|
|
|
$this->assertFalse($this->kernel->getContainer()->hasParameter('knp_gaufrette.stream_wrapper.protocol'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldConfigureStreamWrapperWithDefaultValues()
|
|
|
|
{
|
|
|
|
$kernel = new TestKernel('wrapper_1', false);
|
|
|
|
$kernel->boot();
|
|
|
|
$container = $kernel->getContainer();
|
|
|
|
|
|
|
|
$this->assertTrue($container->hasParameter('knp_gaufrette.stream_wrapper.protocol'));
|
|
|
|
$this->assertEquals('gaufrette', $container->getParameter('knp_gaufrette.stream_wrapper.protocol'));
|
|
|
|
|
|
|
|
$wrapperFsMap = StreamWrapper::getFilesystemMap();
|
|
|
|
|
2012-10-30 14:07:34 +00:00
|
|
|
$expectedDomains = array(
|
|
|
|
'foo',
|
|
|
|
'cache',
|
|
|
|
'ftp',
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($expectedDomains as $eachExpectedDomain) {
|
|
|
|
$this->assertTrue($wrapperFsMap->has($eachExpectedDomain));
|
2012-10-10 15:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldAllowToDefineProtocolOfStreamWrapper()
|
|
|
|
{
|
|
|
|
$kernel = new TestKernel('wrapper_2', false);
|
|
|
|
$kernel->boot();
|
|
|
|
$container = $kernel->getContainer();
|
|
|
|
|
|
|
|
$this->assertTrue($container->hasParameter('knp_gaufrette.stream_wrapper.protocol'));
|
|
|
|
$this->assertEquals('tada', $container->getParameter('knp_gaufrette.stream_wrapper.protocol'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldAllowToDefineWhichFileSystemsShouldBeAddToStreamWrapper()
|
|
|
|
{
|
|
|
|
$kernel = new TestKernel('wrapper_2', false);
|
|
|
|
$kernel->boot();
|
|
|
|
$container = $kernel->getContainer();
|
|
|
|
$fileSystems = $container->getParameter('knp_gaufrette.stream_wrapper.filesystems');
|
|
|
|
|
|
|
|
$this->assertEquals(array('pictures' => 'cache', 'text' => 'ftp'), $fileSystems);
|
|
|
|
|
|
|
|
$wrapperFsMap = StreamWrapper::getFilesystemMap();
|
|
|
|
|
|
|
|
foreach($fileSystems as $key => $fs) {
|
|
|
|
$this->assertTrue($wrapperFsMap->has($key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldAllowToDefineFileSystemsWithoutDomain()
|
|
|
|
{
|
|
|
|
$kernel = new TestKernel('wrapper_3', false);
|
|
|
|
$kernel->boot();
|
|
|
|
$container = $kernel->getContainer();
|
|
|
|
$fileSystems = $container->getParameter('knp_gaufrette.stream_wrapper.filesystems');
|
|
|
|
|
|
|
|
$this->assertTrue($container->hasParameter('knp_gaufrette.stream_wrapper.protocol'));
|
|
|
|
$this->assertEquals('tada', $container->getParameter('knp_gaufrette.stream_wrapper.protocol'));
|
|
|
|
$this->assertEquals(array('cache' => 'cache', 'ftp' => 'ftp'), $fileSystems);
|
|
|
|
|
|
|
|
$wrapperFsMap = StreamWrapper::getFilesystemMap();
|
|
|
|
|
|
|
|
foreach($fileSystems as $key => $fs) {
|
|
|
|
$this->assertTrue($wrapperFsMap->has($key));
|
|
|
|
}
|
|
|
|
}
|
2012-09-04 13:18:10 +00:00
|
|
|
}
|