[BUGFIX] Allow closures in filters methods for directory items 53/37153/6
authorChristoph Dörfel <christoph.doerfel@gmail.com>
Tue, 24 Feb 2015 07:23:28 +0000 (08:23 +0100)
committerNicole Cordes <typo3@cordes.co>
Mon, 11 May 2015 12:30:56 +0000 (14:30 +0200)
Instead of checking if a given filter is callable a is_array check
is done. But the filter can also be a closure and a is_array would
fail then.

This patch changes the is_array check to is_callable.

Resolves: #65244
Releases: master, 6.2
Change-Id: I1a1e9ce0e789bd36a4fa36e91389e8b62c50116e
Reviewed-on: http://review.typo3.org/37153
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php

index 6ee7aa7..1ce9aea 100644 (file)
@@ -410,7 +410,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
         */
        protected function applyFilterMethodsToDirectoryItem(array $filterMethods, $itemName, $itemIdentifier, $parentIdentifier) {
                foreach ($filterMethods as $filter) {
-                       if (is_array($filter)) {
+                       if (is_callable($filter)) {
                                $result = call_user_func($filter, $itemName, $itemIdentifier, $parentIdentifier, array(), $this);
                                // We have to use -1 as the „don't include“ return value, as call_user_func() will return FALSE
                                // If calling the method succeeded and thus we can't use that as a return value.
index 23ee16b..aadc569 100644 (file)
@@ -1545,4 +1545,40 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
                $this->createDriver()->sanitizeFileName('');
        }
 
+       /**
+        * @test
+        */
+       public function applyFilterMethodsToDirectoryItemCallsFilterMethodIfClosure() {
+               $this->setExpectedException('Exception', 'I was called!');
+               $closure = function() {
+                       throw new \Exception('I was called!');
+               };
+
+               $filterMethods = array(
+                       $closure,
+               );
+
+               $this->createDriver()->_call('applyFilterMethodsToDirectoryItem', $filterMethods, '', '', '');
+       }
+
+       /**
+        * @test
+        */
+       public function applyFilterMethodsToDirectoryItemCallsFilterMethodIfName() {
+               $dummyObject = $this
+                       ->getMockBuilder('\TYPO3\CMS\Core\Resource\Driver\LocalDriver')
+                       ->setMethods(array('dummy'))
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $method = array(
+                       $dummyObject,
+                       'dummy',
+               );
+               $dummyObject->expects($this->once())->method('dummy');
+               $filterMethods = array(
+                       $method,
+               );
+               $this->createDriver()->_call('applyFilterMethodsToDirectoryItem', $filterMethods, '', '', '');
+       }
+
 }