Skip to content

Commit

Permalink
[BUGFIX] Allow ItemProcessingService as param in MultipleItemsProcFunc (
Browse files Browse the repository at this point in the history
#2144)

Co-authored-by: Claus Due <claus@namelesscoder.net>
  • Loading branch information
tobiasgraeber and NamelessCoder committed Dec 14, 2023
1 parent 437e4d1 commit 9232d18
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Classes/Integration/MultipleItemsProcFunc.php
Expand Up @@ -10,6 +10,7 @@

use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\DataHandling\ItemProcessingService;

class MultipleItemsProcFunc
{
Expand All @@ -32,7 +33,10 @@ public static function register(string $table, string $field, ?string $additiona
$GLOBALS['TCA'][$table]['columns'][$field]['config']['itemsProcFunc'] = $newFunction;
}

public function execute(array &$parameters, FormDataProviderInterface $formDataProvider): void
/**
* @param ItemProcessingService|FormDataProviderInterface $formDataProvider
*/
public function execute(array &$parameters, $formDataProvider): void
{
$table = $parameters['table'];
$field = $parameters['field'];
Expand Down
23 changes: 20 additions & 3 deletions Tests/Unit/Integration/MultipleItemsProcFuncTest.php
Expand Up @@ -11,6 +11,7 @@
use FluidTYPO3\Flux\Integration\MultipleItemsProcFunc;
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase;
use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
use TYPO3\CMS\Core\DataHandling\ItemProcessingService;

class MultipleItemsProcFuncTest extends AbstractTestCase
{
Expand All @@ -29,12 +30,28 @@ public function testRegistersFunction(): void
);
}

public function testExecutesFunction(): void
public function testExecutesFunctionWithFormDataProvider(): void
{
$provider = $this->getMockBuilder(FormDataProviderInterface::class)->getMockForAbstractClass();
static::$executed = false;
$formDataProviderInterface = $this->getMockBuilder(FormDataProviderInterface::class)->getMockForAbstractClass();
MultipleItemsProcFunc::register('table', 'field', static::class . '->dummyFunction');
$parameters = ['table' => 'table', 'field' => 'field'];
(new MultipleItemsProcFunc())->execute($parameters, $provider);
(new MultipleItemsProcFunc())->execute($parameters, $formDataProviderInterface);

self::assertTrue(static::$executed);
}

public function testExecutesFunctionWithItemProcessingService(): void
{
static::$executed = false;
if (!class_exists(ItemProcessingService::class)) {
$this->markTestSkipped('Skippped, class ' . ItemProcessingService::class . ' does not exist');
}
MultipleItemsProcFunc::register('table', 'field', static::class . '->dummyFunction');
$parameters = ['table' => 'table', 'field' => 'field'];
$itemProcessingServiceProvider = $this->getMockBuilder(ItemProcessingService::class)->getMockForAbstractClass();
(new MultipleItemsProcFunc())->execute($parameters, $itemProcessingServiceProvider);

self::assertTrue(static::$executed);
}

Expand Down

0 comments on commit 9232d18

Please sign in to comment.