diff --git a/Classes/Domain/Model/Backend/ImportLog.php b/Classes/Domain/Model/Backend/ImportLog.php index 569239d..c5b36a1 100644 --- a/Classes/Domain/Model/Backend/ImportLog.php +++ b/Classes/Domain/Model/Backend/ImportLog.php @@ -34,9 +34,9 @@ class ImportLog extends Typo3AbstractEntity protected $logEntries; /** - * @var ImportConfiguration + * @var ImportConfiguration|null */ - protected $configuration; + protected $configuration = null; /** * @var \DateTimeImmutable|null @@ -44,7 +44,7 @@ class ImportLog extends Typo3AbstractEntity protected $crdate; public function __construct( - ImportConfiguration $configuration + ?ImportConfiguration $configuration = null ) { $this->logEntries = new ObjectStorage(); $this->configuration = $configuration; @@ -55,11 +55,20 @@ class ImportLog extends Typo3AbstractEntity $this->logEntries->attach($entry); } - public function getConfiguration(): ImportConfiguration + public function getConfiguration(): ?ImportConfiguration { return $this->configuration; } + public function getConfigurationUid(): int + { + if ($this->configuration instanceof ImportConfiguration) { + $uid = $this->configuration->getUid(); + } + + return $uid ?? 0; + } + /** * @return ObjectStorage */ diff --git a/Classes/Domain/Repository/Backend/ImportLogRepository.php b/Classes/Domain/Repository/Backend/ImportLogRepository.php index f738072..0651540 100644 --- a/Classes/Domain/Repository/Backend/ImportLogRepository.php +++ b/Classes/Domain/Repository/Backend/ImportLogRepository.php @@ -61,7 +61,7 @@ class ImportLogRepository extends Repository 'tx_thuecat_import_log' => [ 'NEW0' => [ 'pid' => 0, - 'configuration' => $log->getConfiguration()->getUid(), + 'configuration' => $log->getConfigurationUid(), ], ], 'tx_thuecat_import_log_entry' => $this->getLogEntries($log), diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 9eacac1..661b64b 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -81,6 +81,9 @@ Summary + + Not available + Organisation diff --git a/Resources/Private/Templates/Backend/Import/Index.html b/Resources/Private/Templates/Backend/Import/Index.html index 31f6617..29dfb60 100644 --- a/Resources/Private/Templates/Backend/Import/Index.html +++ b/Resources/Private/Templates/Backend/Import/Index.html @@ -41,7 +41,16 @@ {import.created -> f:format.date(format: 'd.m.Y H:i:s')} - {import.configuration.title} + + + + {import.configuration.title} + + + {f:translate(id: 'module.imports.configuration.notAvailable')} + + + {import.entries -> f:count()} {f:translate(id: 'module.imports.summary.tableName.{tableName}')} {amount}
diff --git a/Tests/Unit/Domain/Model/Backend/ImportLogTest.php b/Tests/Unit/Domain/Model/Backend/ImportLogTest.php new file mode 100644 index 0000000..db96950 --- /dev/null +++ b/Tests/Unit/Domain/Model/Backend/ImportLogTest.php @@ -0,0 +1,90 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use Prophecy\PhpUnit\ProphecyTrait; +use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration; +use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportLog; +use PHPUnit\Framework\TestCase; + +/** + * @covers \WerkraumMedia\ThueCat\Domain\Model\Backend\ImportLog + */ +class ImportLogTest extends TestCase +{ + use ProphecyTrait; + + /** + * @test + */ + public function canBeCreated(): void + { + $subject = new ImportLog(); + + self::assertInstanceOf(ImportLog::class, $subject); + } + + /** + * @test + */ + public function returnsConfigurationIfSet(): void + { + $configuration = $this->prophesize(ImportConfiguration::class); + $subject = new ImportLog($configuration->reveal()); + + self::assertSame($configuration->reveal(), $subject->getConfiguration()); + } + + /** + * @test + */ + public function returnsNullForConfigurationIfNotSet(): void + { + $subject = new ImportLog(); + + self::assertNull($subject->getConfiguration()); + } + + /** + * @test + */ + public function returnsConfigurationUidIfSet(): void + { + $configuration = $this->prophesize(ImportConfiguration::class); + $configuration->getUid()->willReturn(10); + $subject = new ImportLog($configuration->reveal()); + + self::assertSame(10, $subject->getConfigurationUid()); + } + + /** + * @test + */ + public function returnsZeroForConfigurationIfNotSet(): void + { + $subject = new ImportLog(); + + self::assertSame(0, $subject->getConfigurationUid()); + } +}