Skip to content

Commit

Permalink
Merge pull request #178 from helios-ag/phpunit
Browse files Browse the repository at this point in the history
increased number of tests
  • Loading branch information
helios-ag committed Nov 9, 2015
2 parents b584435 + d8633fd commit 0147ea0
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ php:
- 7.0
- hhvm

sudo: false

matrix:
allow_failures:
- php:
Expand Down
4 changes: 2 additions & 2 deletions Configuration/ElFinderConfigurationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function getConfiguration($instance)
$options = array();
$options['corsSupport'] = $parameters['cors_support'];
$options['debug'] = $parameters['connector']['debug'];
$options['bind'] = $parameters['connector']['binds'];
$options['plugins'] = $parameters['connector']['plugins'];
$options['bind'] = $parameters['connector']['binds'];
$options['plugins'] = $parameters['connector']['plugins'];
$options['roots'] = array();

foreach ($parameters['connector']['roots'] as $parameter) {
Expand Down
11 changes: 6 additions & 5 deletions Loader/ElFinderLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace FM\ElfinderBundle\Loader;

use Exception;
use FM\ElFinderPHP\Connector\ElFinderConnector;
use FM\ElfinderBundle\Bridge\ElFinderBridge;
use FM\ElfinderBundle\Model\ElFinderConfigurationProviderInterface;
use Symfony\Component\HttpFoundation\Request;

/**
* Class ElFinderLoader.
* Class ElFinderLoader
* @package FM\ElfinderBundle\Loader
*/
class ElFinderLoader
{
Expand Down Expand Up @@ -51,7 +51,7 @@ public function configure()
{
$configurator = $this->configurator;
if (!($configurator instanceof ElFinderConfigurationProviderInterface)) {
throw new Exception('Configurator class must implement ElFinderConfigurationProviderInterface');
throw new \Exception('Configurator class must implement ElFinderConfigurationProviderInterface');
}
$parameters = $configurator->getConfiguration($this->instance);

Expand All @@ -67,13 +67,14 @@ public function initBridge($instance)
{
$this->setInstance($instance);
$this->config = $this->configure();
$this->bridge = new ElFinderBridge($config);
$this->bridge = new ElFinderBridge($this->config);
}

/**
* Starts ElFinder.
*
* @var Request
* @return void|array
*/
public function load(Request $request)
{
Expand All @@ -97,7 +98,7 @@ public function setInstance($instance)
/**
* @param \FM\ElfinderBundle\Model\ElFinderConfigurationProviderInterface $configurator
*/
public function setConfigurator($configurator)
public function setConfigurator(ElFinderConfigurationProviderInterface $configurator)
{
$this->configurator = $configurator;
}
Expand Down
143 changes: 143 additions & 0 deletions Tests/Configuration/ElFinderConfigurationReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,155 @@

namespace FM\ElfinderBundle\Tests\Configuration;

use FM\ElfinderBundle\Configuration\ElFinderConfigurationReader;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class ElFinderConfigurationReaderTest
* @package FM\ElfinderBundle\Tests\Configuration
*/
class ElFinderConfigurationReaderTest extends \PHPUnit_Framework_TestCase
{

/**
* @var ElFinderConfigurationReader
*/
protected $reader;

/**
* @var \FM\ElFinderPHP\Driver\ElFinderVolumeLocalFileSystem
*/
protected $elFinderVolumeMock;


protected function setUp()
{
/** @var \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit_Framework_MockObject_MockObject */
$containerMock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');

$this->elFinderVolumeMock = $this->getMock('FM\ElFinderPHP\Driver\ElFinderVolumeLocalFileSystem');

$containerMock
->expects($this->any())
->method('has')
->will($this->returnValueMap(array(
array(
'elfinder.driver.local',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->elFinderVolumeMock,
)
)));

/** @var \Symfony\Component\HttpFoundation\RequestStack $requestStack|\PHPUnit_Framework_MockObject_MockObject */
$requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
/** @var \Symfony\Component\HttpFoundation\Request $requestObject */
$requestObject = $this->getMock('Symfony\Component\HttpFoundation\Request');

$requestObject
->expects($this->any())
->method('get')
->will($this->returnValue(''));

/** @var \Symfony\Component\HttpFoundation\ParameterBag $attributesObject */
$attributesObject = $this->getMock('\Symfony\Component\HttpFoundation\ParameterBag');
$attributesObject
->expects($this->any())
->method('get')
->will($this->returnValue(''));

$requestObject->attributes = $attributesObject;

$requestStack
->expects($this->any())
->method('getCurrentRequest')
->will($this->returnValue($requestObject));

$params = array(
'instances' => array(
'default' => array(
'cors_support' => '',
'connector' => array(
'debug' => '', 'binds' => '', 'plugins'=> '',
'roots' => array(
'uploads' => array(
'flysystem' => array('enabled'=>false),
'volume_id' => 0,
'show_hidden' => false,
'path' => '',
'driver' => 'LocalFileSystem',
'glide_url' => '',
'glide_key' => '',
'plugins' => '',
'start_path' => '',
'alias' => '',
'mime_detect' => '',
'mimefile' => '',
'img_lib' => '',
'tmb_path' => '',
'tmb_path_mode' => '',
'tmb_url' => '',
'tmb_size' => '',
'tmb_crop' => '',
'tmb_bg_color' => '',
'copy_overwrite' => '',
'copy_join' => '',
'copy_from' => '',
'copy_to' => '',
'upload_overwrite' => '',
'upload_allow' => '',
'upload_deny' => '',
'upload_max_size' => '',
'defaults' => '',
'attributes' => '',
'accepted_name' => '',
'disabled_commands' => '',
'tree_deep' => '',
'check_subfolders' => '',
'separator' => '',
'time_format' => '',
'archive_mimes' => '',
'archivers' => ''
)
),
)
)
)
);

$this->reader = new ElFinderConfigurationReader($params, $requestStack, $containerMock);
}

protected function tearDown()
{
unset($this->reader);
}

public function testConfiguration()
{
$configuration = $this->reader->getConfiguration('default');
$this->assertArrayHasKey('roots', $configuration);
$this->assertArrayHasKey('corsSupport', $configuration);
$this->assertSame('LocalFileSystem', $configuration['roots'][0]['driver']);
}

public function testSubClassOfHelper()
{
$rc = new \ReflectionClass('FM\ElfinderBundle\Configuration\ElFinderConfigurationReader');

$this->assertTrue($rc->isSubclassOf('FM\ElfinderBundle\Model\ElFinderConfigurationProviderInterface'));
}

public function testAccessHidden()
{
$hiddenPath = '.hiddenPath';
$this->assertFalse($this->reader->access('read',$hiddenPath, 'dummy', 'dummy'));
$this->assertFalse($this->reader->access('write',$hiddenPath, 'dummy', 'dummy'));
}

public function testAccessVisible()
{
$visiblePath = 'hiddenPath';
$this->assertNull($this->reader->access('read',$visiblePath, 'dummy', 'dummy'));
$this->assertNull($this->reader->access('write',$visiblePath, 'dummy', 'dummy'));
}
}
26 changes: 26 additions & 0 deletions Tests/DependencyInjection/Compiler/TwigFormPassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace FM\ElfinderBundle\Tests\DependencyInjection\Compiler;

use FM\ElfinderBundle\DependencyInjection\Compiler\TwigFormPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Class TwigFormPassTest.
*/
class TwigFormPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$pass = new TwigFormPass();
$pass->process($container);
$this->assertFalse($container->hasParameter('twig.form.resources'));
$container = new ContainerBuilder();
$container->setParameter('twig.form.resources', array());
$pass->process($container);
$this->assertEquals(array(
'FMElfinderBundle:Form:elfinder_widget.html.twig',
), $container->getParameter('twig.form.resources'));
}
}
4 changes: 4 additions & 0 deletions Tests/DependencyInjection/FMElfinderExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Yaml\Parser;

/**
* Class FMElfinderExtensionTest
* @package FM\ElfinderBundle\Tests\DependencyInjection
*/
class FMElfinderExtensionTest extends AbstractExtensionTestCase
{
protected function getContainerExtensions()
Expand Down
4 changes: 4 additions & 0 deletions Tests/Event/ElFinderPostExecutionEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
use Symfony\Component\HttpFoundation\Request;
use FM\ElfinderBundle\Event\ElFinderPostExecutionEvent;

/**
* Class ElFinderPostExecutionEventTest
* @package FM\ElfinderBundle\Tests\Event
*/
class ElFinderPostExecutionEventTest extends TestCase
{
public function testHasErrors()
Expand Down
5 changes: 5 additions & 0 deletions Tests/Event/ElFinderPreExecutionEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
use Symfony\Component\HttpFoundation\Request;
use FM\ElfinderBundle\Event\ElFinderPreExecutionEvent;

/**
* Class ElFinderPreExecutionEventTest
* @package FM\ElfinderBundle\Tests\Event
*/
class ElFinderPreExecutionEventTest extends TestCase
{
public function testGetCommand()
Expand All @@ -30,5 +34,6 @@ public function testSubRequest()
'instance' => $event->getInstance(),
'homeFolder' => $event->getHomeFolder(),
), $request->query->all());

}
}
50 changes: 50 additions & 0 deletions Tests/Form/Type/ElFinderTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace FM\ElfinderBundle\Tests\Form\Type;

use FM\ElfinderBundle\Form\Type\ElFinderType;
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\Test\TypeTestCase;

/**
* Class ElFinderTypeTest
* @package FM\ElfinderBundle\Tests
*/
class ElFinderTypeTest extends TypeTestCase
{

public function setUp()
{
parent::setUp();

$elfinderType = new ElFinderType();
$this->factory = Forms::createFormFactoryBuilder()
->addType($elfinderType)
->getFormFactory();
}

public function testDefaults()
{
$form = $this->factory->create('elfinder');
$view = $form->createView();

$this->assertTrue($view->vars['enable']);
}

public function testDefaultInstance()
{
$form = $this->factory->create('elfinder');
$view = $form->createView();

$this->assertSame('', $view->vars['instance']);
}

public function testDefaultHomeFolder()
{
$form = $this->factory->create('elfinder');
$view = $form->createView();

$this->assertSame('', $view->vars['homeFolder']);
}

}

0 comments on commit 0147ea0

Please sign in to comment.