diff --git a/.gitignore b/.gitignore index 5679a0c..50553fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ composer.lock Tests/cache Tests/log - +Tests/Functional/cache +Tests/Functional/log diff --git a/Tests/Controller/ElFinderControllerTest.php b/Tests/Controller/ElFinderControllerTest.php new file mode 100644 index 0000000..f85e838 --- /dev/null +++ b/Tests/Controller/ElFinderControllerTest.php @@ -0,0 +1,70 @@ +container = static::createClient()->getContainer(); + } + + public function testDispatchedPrePostExecutionEvents() + { + $preExecCount = 0; + $postExecCount = 0; + // storing the real event dispatcher + $eventDispatcher = $this->container->get('event_dispatcher'); + // creating a container with mocked services for this test + $container = $this->getContainer($eventDispatcher); + // adding listeners + $eventDispatcher->addListener(ElFinderEvents::PRE_EXECUTION, $preExecListener = function (ElFinderEvents $e) use (&$preExecCount) { + $preExecCount++; + }); + $eventDispatcher->addListener(ElFinderEvents::POST_EXECUTION, $postExecListener = function (ElFinderEvents $e) use (&$postExecCount) { + $postExecCount++; + }); + + $controller = new ElFinderController(); + $controller->setContainer($container); + $controller->loadAction(new Request(array('cmd' => 'info')), 'default', null); + + $this->assertGreaterThan(0, $preExecCount); + $this->assertGreaterThan(0, $postExecCount); + } + + private function getContainer($eventDispatcher) + { + $container = new Container(); + $container->set('fm_elfinder.loader', $this->getElFinderLoaderMock()); + $container->set('http_kernel', $this->getHttpKernelMock()); + $container->set('event_dispatcher', $eventDispatcher); + return $container; + } + + private function getElFinderLoaderMock() + { + $stub = $this->getMockBuilder('FM\ElfinderBundle\Loader\ElFinderLoader') + ->disableOriginalConstructor() + ->getMock(); + $stub->expects($this->once()) + ->method('load') + ->willReturn(array()); + return $stub; + } + + private function getHttpKernelMock() + { + $stub = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface') + ->disableOriginalConstructor() + ->getMock(); + return $stub; + } +} diff --git a/Tests/Event/ElFinderPostExecutionEventTest.php b/Tests/Event/ElFinderPostExecutionEventTest.php new file mode 100644 index 0000000..7db47f4 --- /dev/null +++ b/Tests/Event/ElFinderPostExecutionEventTest.php @@ -0,0 +1,21 @@ +getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); + $event = new ElFinderPostExecutionEvent($request, $httpKernel, 'testInstance', 'testHomeFolder', array()); + $this->assertEquals(false, $event->hasErrors()); + + $event = new ElFinderPostExecutionEvent($request, $httpKernel, 'testInstance', 'testHomeFolder', array('error' => true)); + $this->assertEquals(true, $event->hasErrors()); + } +} diff --git a/Tests/Event/ElFinderPreExecutionEventTest.php b/Tests/Event/ElFinderPreExecutionEventTest.php new file mode 100644 index 0000000..dabd6e3 --- /dev/null +++ b/Tests/Event/ElFinderPreExecutionEventTest.php @@ -0,0 +1,34 @@ + $command)); + $httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); + $event = new ElFinderPreExecutionEvent($request, $httpKernel, 'testInstance', 'testHomeFolder'); + $this->assertEquals($command, $event->getCommand()); + } + + public function testSubRequest() + { + $request = new Request(array('cmd' => 'info')); + $httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); + $httpKernel + ->expects($this->once()) + ->method('handle'); + $event = new ElFinderPreExecutionEvent($request, $httpKernel, 'testInstance', 'testHomeFolder'); + + $jsonResponse = $event->subRequest(array( + 'instance' => $event->getInstance(), + 'homeFolder' => $event->getHomeFolder() + ), $request->query->all()); + } +} diff --git a/Tests/Functional/AppKernel.php b/Tests/Functional/AppKernel.php new file mode 100644 index 0000000..3694625 --- /dev/null +++ b/Tests/Functional/AppKernel.php @@ -0,0 +1,23 @@ +load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml'); + } +} diff --git a/Tests/Functional/config/config.yml b/Tests/Functional/config/config.yml new file mode 100644 index 0000000..3afa4b2 --- /dev/null +++ b/Tests/Functional/config/config.yml @@ -0,0 +1,39 @@ +framework: + secret: "thisismysecret" + router: + resource: "%kernel.root_dir%/config/routing.yml" + strict_requirements: ~ + form: ~ + csrf_protection: ~ + validation: { enable_annotations: true } + templating: + engines: ['twig'] + default_locale: "en" + trusted_hosts: ~ + trusted_proxies: ~ + session: + # handler_id set to null will use default session handler from php.ini + handler_id: ~ + fragments: ~ + http_method_override: true + + +# ElFinder file manager +fm_elfinder: + instances: + default: + locale: en # defaults to current request locale + editor: custom # other options are tinymce, tinymce4, form, custom and simple, + cors_support: true # full symfony life cycle + fullscreen: true # defaults true, applies to simple and ckeditor editors + include_assets: true # disable if you want to handle loading of the javascript and css assets yourself + connector: + debug: false # defaults to false + roots: # at least one root must be defined + uploads: + show_hidden: false # defaults to false + driver: LocalFileSystem + volume_id: 1 + path: uploads + + diff --git a/Tests/Functional/config/config_test.yml b/Tests/Functional/config/config_test.yml new file mode 100644 index 0000000..fd5cd36 --- /dev/null +++ b/Tests/Functional/config/config_test.yml @@ -0,0 +1,9 @@ +imports: + - { resource: config.yml } + +framework: + test: ~ + session: + storage_id: session.storage.mock_file + profiler: + collect: false diff --git a/Tests/Functional/config/routing.yml b/Tests/Functional/config/routing.yml new file mode 100644 index 0000000..f6f1fda --- /dev/null +++ b/Tests/Functional/config/routing.yml @@ -0,0 +1,4 @@ +# ElFinder file manager +elfinder: + resource: "@FMElfinderBundle/Resources/config/routing.yml" + diff --git a/composer.json b/composer.json index 0067b67..261c667 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ ], "require": { "php": ">=5.3.3", + "symfony/symfony": "~2.4", "symfony/framework-bundle": "~2.4", "symfony/twig-bundle": "~2.4", "helios-ag/fm-elfinder-php-connector": "~2.0",