Skip to content

Commit

Permalink
Merge pull request #26 from jweiland-net/respectColumnsOverride
Browse files Browse the repository at this point in the history
Respect columns override
  • Loading branch information
sfroemkenjw committed Apr 24, 2023
2 parents 4b30132 + ba314c5 commit 8fc2a7c
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 207 deletions.
6 changes: 1 addition & 5 deletions Classes/Helper/TcaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function getTypeOfRecord(array $record, string $table): string

// It also checks, if key "type" is not empty
if (!$this->tableHasTypeConfiguration($tableConfiguration)) {
return '';
return is_array($tableConfiguration['types'] ?? null) ? (string)key($tableConfiguration['types']) : '';
}

$typeColumn = $tableConfiguration['ctrl']['type'];
Expand Down Expand Up @@ -225,10 +225,6 @@ protected function mergeWithTypeSpecificConfig(
return;
}

if (!$this->tableHasTypeConfiguration($tableConfiguration)) {
return;
}

$typeSpecificBaseConfigurationForColumn = $this->getTableTypeBaseConfigurationForColumn(
$column,
$type,
Expand Down
5 changes: 5 additions & 0 deletions Documentation/ChangeLog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
ChangeLog
=========

**Version 2.2.2**

- Bugfix: Respect crop variants of non-types tables in columnsOverride
- Task: Migrate Prophesize in tests to MockObjects

**Version 2.2.1**

- Bugfix: Repair sync for new sys_file_reference records
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

project = sync_crop_areas (Sync Crop Areas)
version = 2.2
release = 2.2.1
release = 2.2.2
t3author = Stefan Froemken
copyright = since 2020 by jweiland.net

Expand Down
131 changes: 70 additions & 61 deletions Tests/Functional/Command/SynchronizeCropVariantsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
use JWeiland\SyncCropAreas\Command\SynchronizeCropVariantsCommand;
use JWeiland\SyncCropAreas\Service\UpdateCropVariantsService;
use Nimut\TestingFramework\TestCase\FunctionalTestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\ConsoleOutput;
Expand All @@ -27,8 +25,6 @@
*/
class SynchronizeCropVariantsCommandTest extends FunctionalTestCase
{
use ProphecyTrait;

/**
* @var array
*/
Expand All @@ -39,33 +35,30 @@ class SynchronizeCropVariantsCommandTest extends FunctionalTestCase
protected SynchronizeCropVariantsCommand $subject;

/**
* @var UpdateCropVariantsService|ObjectProphecy
* @var UpdateCropVariantsService|MockObject
*/
protected $updateCropVariantsServiceProphecy;
protected $updateCropVariantsServiceMock;

/**
* @var InputInterface|ObjectProphecy
* @var InputInterface|MockObject
*/
protected $inputProphecy;
protected $inputMock;

/**
* @var OutputInterface|ObjectProphecy
* @var OutputInterface|MockObject
*/
protected $outputProphecy;
protected $outputMock;

protected function setUp(): void
{
parent::setUp();

$this->updateCropVariantsServiceProphecy = $this->prophesize(UpdateCropVariantsService::class);
$this->inputProphecy = $this->prophesize(StringInput::class);
$this->outputProphecy = $this->prophesize(ConsoleOutput::class);
$this->outputProphecy
->writeln('Start synchronizing crop variants of table sys_file_reference')
->shouldBeCalled();
$this->updateCropVariantsServiceMock = $this->createMock(UpdateCropVariantsService::class);
$this->inputMock = $this->createMock(StringInput::class);
$this->outputMock = $this->createMock(ConsoleOutput::class);

$this->subject = new SynchronizeCropVariantsCommand(
$this->updateCropVariantsServiceProphecy->reveal(),
$this->updateCropVariantsServiceMock,
\JWeiland\SyncCropAreas\Command\SynchronizeCropVariantsCommand::class
);
}
Expand All @@ -74,7 +67,9 @@ protected function tearDown(): void
{
unset(
$this->subject,
$this->updateCropVariantsServiceProphecy
$this->outputMock,
$this->inputMock,
$this->updateCropVariantsServiceMock
);

parent::tearDown();
Expand All @@ -85,13 +80,17 @@ protected function tearDown(): void
*/
public function runWithNoSysFileReferencesDisplaysEmptyStatistic(): void
{
$this->outputProphecy
->writeln('We had 0 sys_file_reference records in total. 0 records were processed successfully and 0 records must be skipped because of invalid values')
->shouldBeCalled();
$this->outputMock
->expects(self::exactly(2))
->method('writeln')
->willReturnOnConsecutiveCalls([
['Start synchronizing crop variants of table sys_file_reference', null],
['We had 0 sys_file_reference records in total. 0 records were processed successfully and 0 records must be skipped because of invalid values', null]
]);

$this->subject->run(
$this->inputProphecy->reveal(),
$this->outputProphecy->reveal()
$this->inputMock,
$this->outputMock
);
}

Expand All @@ -116,16 +115,18 @@ public function runWithEmptyCropColumnWillSkipRecord(): void
]
);

$this->outputProphecy
->writeln('SKIP: Column "crop" of sys_file_reference record with UID 1 is empty')
->shouldBeCalled();
$this->outputProphecy
->writeln('We had 1 sys_file_reference records in total. 0 records were processed successfully and 1 records must be skipped because of invalid values')
->shouldBeCalled();
$this->outputMock
->expects(self::exactly(3))
->method('writeln')
->willReturnOnConsecutiveCalls([
['Start synchronizing crop variants of table sys_file_reference', null],
['SKIP: Column "crop" of sys_file_reference record with UID 1 is empty', null],
['We had 1 sys_file_reference records in total. 0 records were processed successfully and 1 records must be skipped because of invalid values', null]
]);

$this->subject->run(
$this->inputProphecy->reveal(),
$this->outputProphecy->reveal()
$this->inputMock,
$this->outputMock
);
}

Expand All @@ -150,16 +151,18 @@ public function runWithEmptyPidColumnWillSkipRecord(): void
]
);

$this->outputProphecy
->writeln('SKIP: Column "pid" of sys_file_reference record with UID 1 is empty')
->shouldBeCalled();
$this->outputProphecy
->writeln('We had 1 sys_file_reference records in total. 0 records were processed successfully and 1 records must be skipped because of invalid values')
->shouldBeCalled();
$this->outputMock
->expects(self::exactly(3))
->method('writeln')
->willReturnOnConsecutiveCalls([
['Start synchronizing crop variants of table sys_file_reference', null],
['SKIP: Column "pid" of sys_file_reference record with UID 1 is empty', null],
['We had 1 sys_file_reference records in total. 0 records were processed successfully and 1 records must be skipped because of invalid values', null]
]);

$this->subject->run(
$this->inputProphecy->reveal(),
$this->outputProphecy->reveal()
$this->inputMock,
$this->outputMock
);
}

Expand All @@ -183,21 +186,23 @@ public function runWithUnchangedCropWillSkipRecord(): void

$this->getDatabaseConnection()->insertArray('sys_file_reference', $sysFileReferenceRecord);

$this->outputProphecy
->writeln('SKIP: Column "crop" of table "sys_file_reference" with UID 1 because it is unchanged, empty or invalid JSON')
->shouldBeCalled();
$this->outputProphecy
->writeln('We had 1 sys_file_reference records in total. 0 records were processed successfully and 1 records must be skipped because of invalid values')
->shouldBeCalled();

$this->updateCropVariantsServiceProphecy
->synchronizeCropVariants(Argument::cetera())
->shouldBeCalled()
$this->outputMock
->expects(self::exactly(3))
->method('writeln')
->willReturnOnConsecutiveCalls([
['Start synchronizing crop variants of table sys_file_reference', null],
['SKIP: Column "crop" of table "sys_file_reference" with UID 1 because it is unchanged, empty or invalid JSON', null],
['We had 1 sys_file_reference records in total. 0 records were processed successfully and 1 records must be skipped because of invalid values', null]
]);

$this->updateCropVariantsServiceMock
->expects(self::atLeastOnce())
->method('synchronizeCropVariants')
->willReturn($sysFileReferenceRecord);

$this->subject->run(
$this->inputProphecy->reveal(),
$this->outputProphecy->reveal()
$this->inputMock,
$this->outputMock
);
}

Expand All @@ -209,18 +214,22 @@ public function runWithChangedCropWillUpdateRecord(): void
$this->importDataSet(__DIR__ . '/../Fixtures/tt_content.xml');
$this->importDataSet(__DIR__ . '/../Fixtures/sys_file_reference.xml');

$this->outputProphecy
->writeln('We had 3 sys_file_reference records in total. 3 records were processed successfully and 0 records must be skipped because of invalid values')
->shouldBeCalled();

$this->updateCropVariantsServiceProphecy
->synchronizeCropVariants(Argument::cetera())
->shouldBeCalled()
$this->outputMock
->expects(self::exactly(2))
->method('writeln')
->willReturnOnConsecutiveCalls([
['Start synchronizing crop variants of table sys_file_reference', null],
['We had 3 sys_file_reference records in total. 3 records were processed successfully and 0 records must be skipped because of invalid values', null]
]);

$this->updateCropVariantsServiceMock
->expects(self::atLeastOnce())
->method('synchronizeCropVariants')
->willReturn(['crop' => '{foo: "bar"}']);

$this->subject->run(
$this->inputProphecy->reveal(),
$this->outputProphecy->reveal()
$this->inputMock,
$this->outputMock
);

$statement = $this->getDatabaseConnection()->select('*', 'sys_file_reference', '1=1');
Expand Down

0 comments on commit 8fc2a7c

Please sign in to comment.