Skip to content

Commit

Permalink
[TEST] Fix Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoffmann1979 committed May 2, 2024
1 parent 8357381 commit 38b76e7
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public function testProcessingResultIsImcompatibleIfThereAreForbiddenKeysInTca()

$processingResult = $abstractProcessor->process('tableNameFoo', 'fieldNameBar', $tca);
$this->assertFalse($processingResult->isCompatible());
$reason = $processingResult->getValue()[0];
$reason = $processingResult->getValue();
$this->assertSame('first_reason', $reason);

$tca = ['type' => 'inline', 'forbidden_key_2' => 'foo'];
$processingResult = $abstractProcessor->process('tableNameFoo', 'fieldNameBar', $tca);
$reason = $processingResult->getValue()[0];
$reason = $processingResult->getValue();
$this->assertFalse($processingResult->isCompatible());
$this->assertSame('second_reason', $reason);
}
Expand All @@ -67,13 +67,13 @@ public function testProcessingResultIsIncompatibleIfRequiredFieldIsMissing(): vo
$tca = ['type' => 'inline', 'key_1' => 'foo'];
$processingResult = $abstractProcessor->process('tableNameFoo', 'fieldNameBar', $tca);
$this->assertFalse($processingResult->isCompatible());
$reason = $processingResult->getValue()[0];
$reason = $processingResult->getValue();
$this->assertSame('Key 2 is required', $reason);

$tca = ['type' => 'inline', 'key_2' => 'foo'];
$processingResult = $abstractProcessor->process('tableNameFoo', 'fieldNameBar', $tca);
$this->assertFalse($processingResult->isCompatible());
$reason = $processingResult->getValue()[0];
$reason = $processingResult->getValue();
$this->assertSame('Key 1 is required', $reason);
}

Expand Down Expand Up @@ -105,7 +105,7 @@ public function testProcessingResultIsIncompatibleIfNoResolverIsFound(): void

$tca = ['type' => 'inline'];
$result = $abstractProcessor->process('tableNameFoo', 'fieldNameBar', $tca);
$reason = $result->getValue()[0];
$reason = $result->getValue();
$this->assertFalse($result->isCompatible());
$this->assertSame(
'The processor did not return a valid resolver. The target table might be excluded or empty.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use In2code\In2publishCore\Component\Core\PreProcessing\PreProcessor\CategoryProcessor;
use In2code\In2publishCore\Component\Core\PreProcessing\Service\TcaEscapingMarkerService;
use In2code\In2publishCore\Component\Core\Resolver\SelectMmResolver;
use In2code\In2publishCore\Component\Core\Service\Config\ExcludedTablesService;
use In2code\In2publishCore\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\Container;
use TYPO3\CMS\Core\Database\Connection;
Expand Down Expand Up @@ -42,6 +43,10 @@ public function testProcessResultIsCompatibleForAnyTca(): void

$categoryProcessor->injectTcaEscapingMarkerService($tcaEscapingMarkerService);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$categoryProcessor->injectExcludedTablesService($excludedTablesService);

$resolver = $this->createMock(SelectMmResolver::class);
$resolver->expects($this->once())->method('configure')->with(
$additionalWhereAfter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use In2code\In2publishCore\Component\Core\PreProcessing\PreProcessor\ExtNewsRelatedProcessor;
use In2code\In2publishCore\Component\Core\Resolver\StaticJoinResolver;
use In2code\In2publishCore\Component\Core\Service\Config\ExcludedTablesService;
use In2code\In2publishCore\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -35,6 +36,10 @@ public function testExtRelatedNewsProcessReturnsStaticJoinResolver(): void
$container->expects($this->once())->method('get')->willReturn($staticJoinResolver);
$extRelatedProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$extRelatedProcessor->injectExcludedTablesService($excludedTablesService);

$result = $extRelatedProcessor->process('table_foo', 'field_foo', $tca);
$this->assertTrue($result->isCompatible());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use In2code\In2publishCore\Component\Core\Resolver\GroupMultiTableResolver;
use In2code\In2publishCore\Component\Core\Resolver\GroupSingleTableResolver;
use In2code\In2publishCore\Component\Core\Resolver\StaticJoinResolver;
use In2code\In2publishCore\Component\Core\Service\Config\ExcludedTablesService;
use In2code\In2publishCore\Tests\UnitTestCase;
use ReflectionMethod;
use Symfony\Component\DependencyInjection\Container;
Expand Down Expand Up @@ -73,9 +74,14 @@ public function testProcessInternalTypeMustBeDb(): void
->willReturn($groupResolver);
$groupProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$excludedTablesService->method('removeExcludedTables')->willReturnArgument(0);
$groupProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $groupProcessor->process('table_foo', 'field_foo', $tca);
$this->assertFalse($processingResult->isCompatible());
$reason = $processingResult->getValue()[0];
$reason = $processingResult->getValue();
$this->assertSame('The internal type "file" is not supported', $reason);

$tca = ['type' => 'group', 'allowed' => 'table_foo', 'internal_type' => 'db'];
Expand All @@ -102,9 +108,14 @@ public function testProcessAllowedTableMustBeInTca(): void
$container = $this->createMock(Container::class);
$groupProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$excludedTablesService->method('removeExcludedTables')->willReturnArgument(0);
$groupProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $groupProcessor->process('table_foo', 'field_foo', $tca);
$this->assertFalse($processingResult->isCompatible());
$reason = $processingResult->getValue()[0];
$reason = $processingResult->getValue();
$expectedMessage = 'Can not reference the table "table_bar" from "allowed. It is not present in the TCA';
$this->assertSame($expectedMessage, $reason);

Expand All @@ -130,6 +141,10 @@ public function testTcaMustNotContainMmOppositeField(): void
$container = $this->createMock(Container::class);
$groupProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$groupProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $groupProcessor->process('table_foo', 'field_bar', $tca);
$this->assertFalse($processingResult->isCompatible());
$reason = $processingResult->getValue()[0];
Expand Down Expand Up @@ -163,6 +178,11 @@ public function testProcessingForSingleTableRelations(): void
->willReturn($groupResolver);
$groupProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$excludedTablesService->method('removeExcludedTables')->willReturnArgument(0);
$groupProcessor->injectExcludedTablesService($excludedTablesService);

$singleTableTca = ['type' => 'group', 'allowed' => 'table_foo'];
$processingResult = $groupProcessor->process('table_foo', 'field_bar', $singleTableTca);
$resolver = $processingResult->getValue()['resolver'];
Expand Down Expand Up @@ -197,6 +217,11 @@ public function testProcessingForMultipleTablesRelations(): void
->willReturn($groupResolver);
$groupProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$excludedTablesService->method('removeExcludedTables')->willReturnArgument(0);
$groupProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $groupProcessor->process('table_bar', 'field_bar', $multiTableTca);
$resolver = $processingResult->getValue()['resolver'];
$this->assertTrue($processingResult->isCompatible());
Expand All @@ -220,8 +245,15 @@ public function testProcessingForAllTablesRelations(): void
$groupProcessor = new GroupProcessor();
$tcaMarkerService = $this->createMock(TcaEscapingMarkerService::class);
$groupProcessor->injectTcaEscapingMarkerService($tcaMarkerService);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$excludedTablesService->method('removeExcludedTables')->willReturnArgument(0);
$excludedTablesService->method('getAllNonExcludedTcaTables')->willReturn(['table_foo', 'table_bar', 'table_baz', 'pages']);
$groupProcessor->injectExcludedTablesService($excludedTablesService);

$groupResolver = $this->createMock(GroupMultiTableResolver::class);
$groupResolver->expects($this->once())->method('configure')->with(['*'], 'field_bar');
$groupResolver->expects($this->once())->method('configure')->with(['table_foo', 'table_bar', 'table_baz'], 'field_bar');

$container = $this->createMock(Container::class);
$container->expects($this->once())
Expand All @@ -230,6 +262,7 @@ public function testProcessingForAllTablesRelations(): void
->willReturn($groupResolver);
$groupProcessor->injectContainer($container);


$processingResult = $groupProcessor->process('table_bar', 'field_bar', $allTableTca);
$resolver = $processingResult->getValue()['resolver'];
$this->assertTrue($processingResult->isCompatible());
Expand Down Expand Up @@ -289,6 +322,11 @@ public function testProcessingResultForMmTableRelations(): void
);
$groupProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$excludedTablesService->method('removeExcludedTables')->willReturnArgument(0);
$groupProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult1 = $groupProcessor->process('table_bar', 'field_bar', $mmTableTcaMultipleTable);
$this->assertTrue($processingResult1->isCompatible());
$resolver = $processingResult1->getValue()['resolver'];
Expand Down Expand Up @@ -347,6 +385,11 @@ public function testProcessingResultForMmTableRelationsWithStringMatchFields():
->willReturn($groupResolver);
$groupProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$excludedTablesService->method('removeExcludedTables')->willReturnArgument(0);
$groupProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $groupProcessor->process('table_bar', 'field_bar', $mmTableTcaWithStringValues);
$this->assertTrue($processingResult->isCompatible());
$this->assertInstanceOf(GroupMmMultiTableResolver::class, $groupResolver);
Expand Down Expand Up @@ -401,6 +444,11 @@ public function testProcessingResultForMmTableRelationsWithIntegerMatchFields():
->willReturn($groupResolver);
$groupProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$excludedTablesService->method('removeExcludedTables')->willReturnArgument(0);
$groupProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $groupProcessor->process('table_bar', 'field_bar', $mmTableTcaWithIntegerValues);
$this->assertTrue($processingResult->isCompatible());
$this->assertInstanceOf(GroupMmMultiTableResolver::class, $groupResolver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use In2code\In2publishCore\Component\Core\Resolver\InlineMultiValueResolver;
use In2code\In2publishCore\Component\Core\Resolver\InlineSelectResolver;
use In2code\In2publishCore\Component\Core\Resolver\StaticJoinResolver;
use In2code\In2publishCore\Component\Core\Service\Config\ExcludedTablesService;
use In2code\In2publishCore\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\Container;

Expand All @@ -33,9 +34,13 @@ public function testTcaMustNotContainSymmetricField(): void
$container->method('get')->willReturn($inlineResolver);
$inlineProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$inlineProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $inlineProcessor->process('table_bar', 'field_bar', $tca);
$this->assertFalse($processingResult->isCompatible());
$reason = $processingResult->getValue()[0];
$reason = $processingResult->getValue();
$this->assertSame(
'symmetric_field is set on the foreign side of relations, which must not be resolved',
$reason,
Expand All @@ -60,7 +65,7 @@ public function testTcaMustContainForeignTable(): void

$processingResult = $inlineProcessor->process('table_bar', 'field_bar', $tca);
$this->assertFalse($processingResult->isCompatible());
$reason = $processingResult->getValue()[0];
$reason = $processingResult->getValue();
$this->assertSame('Must be set, there is no type "inline" without a foreign table', $reason);
}

Expand All @@ -85,6 +90,10 @@ public function testInlineSelectResolver(): void
$container->method('get')->willReturn($inlineResolver);
$inlineProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$inlineProcessor->injectExcludedTablesService($excludedTablesService);

$inlineResolver->expects($this->once())
->method('configure')
->with(
Expand Down Expand Up @@ -142,6 +151,10 @@ public function testInlineMultiValueResolver(): void
$container->method('get')->willReturn($inlineResolver);
$inlineProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$inlineProcessor->injectExcludedTablesService($excludedTablesService);

$inlineResolver->expects($this->exactly(3))->method('configure');

$processingResult1 = $inlineProcessor->process('table_bar', 'field_bar', $tca1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testInputProcessorIgnoresFieldsWithoutSupportedSoftref(): void
);
$this->assertFalse($processingResult->isCompatible());
$this->assertSame(
['An input field must either have renderType="inputLink" or softref="typolink" or softref="typolink_tag"'],
'An input field must either have renderType="inputLink" or softref="typolink" or softref="typolink_tag"',
$processingResult->getValue(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use In2code\In2publishCore\Component\Core\Resolver\Resolver;
use In2code\In2publishCore\Component\Core\Resolver\SelectMmResolver;
use In2code\In2publishCore\Component\Core\Resolver\SelectResolver;
use In2code\In2publishCore\Component\Core\Service\Config\ExcludedTablesService;
use In2code\In2publishCore\Service\ReplaceMarkersService;
use In2code\In2publishCore\Tests\UnitTestCase;
use ReflectionMethod;
Expand All @@ -35,6 +36,11 @@ public function testSelectProcessorReturnsCompatibleResultForCompatibleColumn():
$selectProcessor = new SelectProcessor();
$selectProcessor->injectContainer($container);
$selectProcessor->injectTcaEscapingMarkerService($tcaEscapingMarkerService);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$selectProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $selectProcessor->process('tableNameFoo', 'fieldNameBar', [
'type' => 'select',
'foreign_table' => 'tableNameBeng',
Expand Down Expand Up @@ -65,6 +71,11 @@ public function testSelectProcessorFlagsColumnsWithForbiddenTcaAsIncompatible(ar

$selectProcessor = new SelectProcessor();
$selectProcessor->injectContainer($container);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$selectProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $selectProcessor->process('tableNameFoo', 'fieldNameBar', $tca);
$this->assertFalse($processingResult->isCompatible());
}
Expand Down Expand Up @@ -105,6 +116,11 @@ public function testSelectProcessorFiltersTca(): void
$selectProcessor = new SelectProcessor();
$selectProcessor->injectContainer($container);
$selectProcessor->injectTcaEscapingMarkerService($tcaEscapingMarkerService);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$selectProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $selectProcessor->process('tableNameFoo', 'fieldNameBar', $tca);
$this->assertSame($processorTca, $processingResult->getValue()['tca']);
}
Expand Down Expand Up @@ -135,6 +151,10 @@ public function testSelectProcessorCreatesDemandForSimpleRelation(): void
$selectProcessor->injectContainer($container);
$selectProcessor->injectTcaEscapingMarkerService($tcaEscapingMarkerService);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$selectProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $selectProcessor->process('tableNameFoo', 'fieldNameBar', $tca);

/** @var Resolver $resolver */
Expand Down Expand Up @@ -173,6 +193,10 @@ public function testSelectProcessorCreatesDemandForMMRelation(): void
$selectProcessor->injectContainer($container);
$selectProcessor->injectTcaEscapingMarkerService($tcaEscapingMarkerService);

$excludedTablesService = $this->createMock(ExcludedTablesService::class);
$excludedTablesService->method('isExcludedTable')->willReturn(false);
$selectProcessor->injectExcludedTablesService($excludedTablesService);

$processingResult = $selectProcessor->process('tableNameFoo', 'fieldNameBar', $tca);

/** @var Resolver $resolver */
Expand Down
Loading

0 comments on commit 38b76e7

Please sign in to comment.