8
0
Dieser Commit ist enthalten in:
2025-05-19 23:56:02 +02:00
Ursprung 81d7eebefb
Commit 247218a609
9 geänderte Dateien mit 451 neuen und 65 gelöschten Zeilen

Datei anzeigen

@ -45,6 +45,9 @@ class registryOrdermanagerActions extends registryAbstract implements registryOr
$this->addGenerator(deliverynotewithoutlogoPdf::class);
}
/**
* @codeCoverageIgnore
*/
public function getRequiredGeneratorInterfaceClassName(): string
{
return pdfdocumentsOrderInterface::class;

Datei anzeigen

@ -25,10 +25,14 @@ use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderInterface;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class registryOrderoverview extends registryAbstract implements registryOrderoverviewInterface
{
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws wrongPdfGeneratorInterface
*/
public function __construct()
@ -36,7 +40,7 @@ class registryOrderoverview extends registryAbstract implements registryOrderove
/** @var ModuleSettingService $settingsService */
$settingsService = ContainerFactory::getInstance()->getContainer()->get(ModuleSettingServiceInterface::class);
if ($settingsService->getBoolean('d3PdfDocumentsDocInvoice', Constants::OXID_MODULE_ID))
$this->addGenerator( invoicePdf::class );
$this->addGenerator(invoicePdf::class);
if ($settingsService->getBoolean('d3PdfDocumentsDocDeliveryNote', Constants::OXID_MODULE_ID))
$this->addGenerator(deliverynotePdf::class);
if ($settingsService->getBoolean('d3PdfDocumentsDocInvoiceNoLogo', Constants::OXID_MODULE_ID))
@ -45,6 +49,9 @@ class registryOrderoverview extends registryAbstract implements registryOrderove
$this->addGenerator(deliverynotewithoutlogoPdf::class);
}
/**
* @codeCoverageIgnore
*/
public function getRequiredGeneratorInterfaceClassName(): string
{
return pdfdocumentsOrderInterface::class;

Datei anzeigen

@ -23,9 +23,9 @@ $basicAuthHelp = <<<HELP
return [
'charset' => 'utf-8',
'SHOP_MODULE_GROUP_'. Constants::OXID_MODULE_ID.'main' => 'Grundeinstellungen',
'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'bDev' => 'Entwicklermodus',
'HELP_SHOP_MODULE_'. Constants::OXID_MODULE_ID.'bDev' => 'Mit aktiviertem Entwicklermodus kann das Dokument im '.
'SHOP_MODULE_GROUP_'. Constants::OXID_MODULE_ID.'main' => 'Grundeinstellungen',
'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'bDev' => 'Entwicklermodus',
'HELP_SHOP_MODULE_'. Constants::OXID_MODULE_ID.'bDev' => 'Mit aktiviertem Entwicklermodus kann das Dokument im '.
'SGML-Format ausgegeben werden. Inhaltliche Fehler können so besser nachvollzogen werden.',
'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'basicAuthUserName' => 'BasicAuth des Shops - Benutzername (optional)',
'HELP_SHOP_MODULE_'. Constants::OXID_MODULE_ID.'basicAuthUserName' => $basicAuthHelp,
@ -53,7 +53,7 @@ return [
'D3_PDFDOCUMENTS_PDF_TYPE' => 'Dokument',
'D3_PDFDOCUMENTS_LANGUAGE' => 'Sprache',
'D3_PDFDOCUMENTS_SGML_GENERATE' => 'SGML erstellen',
'D3_PDFDOCUMENTS_SGML_GENERATE' => 'Markup erstellen',
'D3_PDFDOCUMENTS_PDF_GENERATE' => 'Dokument erstellen',
];
// @codeCoverageIgnoreEnd

Datei anzeigen

@ -53,7 +53,7 @@ return [
'D3_PDFDOCUMENTS_PDF_TYPE' => 'Document',
'D3_PDFDOCUMENTS_LANGUAGE' => 'Language',
'D3_PDFDOCUMENTS_SGML_GENERATE' => 'Create SGML',
'D3_PDFDOCUMENTS_SGML_GENERATE' => 'Create markup',
'D3_PDFDOCUMENTS_PDF_GENERATE' => 'Create Document',
];
// @codeCoverageIgnoreEnd

Datei anzeigen

@ -0,0 +1,195 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
namespace D3\PdfDocuments\Tests\Unit\Application\Model\Registries;
use D3\PdfDocuments\Application\Model\Exceptions\wrongPdfGeneratorInterface;
use D3\PdfDocuments\Application\Model\Registries\registryOrderoverview;
use D3\PdfDocuments\Tests\Unit\Helpers\nonOrderDocument;
use D3\PdfDocuments\Tests\Unit\Helpers\orderDocument;
use D3\TestingTools\Development\CanAccessRestricted;
use Exception;
use Generator;
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
use PHPUnit\Framework\TestCase;
use ReflectionException;
abstract class registryAbstract extends TestCase
{
use CanAccessRestricted;
/**
* @test
* @throws ReflectionException
* @covers \D3\PdfDocuments\Application\Model\Registries\registryAbstract::addGenerator
* @dataProvider addGeneratorDataProvider
*/
public function testAddGenerator(bool $exist, InvocationOrder $addInvocation, bool $expectException): void
{
$sut = $this->getMockBuilder(registryOrderoverview::class)
->onlyMethods(['hasGenerator', 'addItem'])
->getMock();
$sut->method('hasGenerator')->willReturn($exist);
$sut->expects($addInvocation)->method('addItem');
if ($expectException) {
$this->expectException(Exception::class);
}
$this->callMethod(
$sut,
'addGenerator',
[orderDocument::class]
);
}
public static function addGeneratorDataProvider(): Generator
{
yield 'not added' => [false, self::once(), false];
yield 'already added' => [true, self::never(), true];
}
/**
* @test
* @throws ReflectionException
* @covers \D3\PdfDocuments\Application\Model\Registries\registryAbstract::addItem
* @dataProvider addItemDataProvider
*/
public function testAddItem(string $fqcn, bool $expectException): void
{
$sut = $this->getMockBuilder(registryOrderoverview::class)
->disableOriginalConstructor()
->onlyMethods(['addGenerator'])
->getMock();
$this->assertArrayNotHasKey($fqcn, $this->getValue($sut, 'registry'));
if ($expectException) {
$this->expectException(Exception::class);
}
$this->callMethod(
$sut,
'addItem',
[oxNew($fqcn)]
);
if ($expectException) {
$this->assertArrayNotHasKey($fqcn, $this->getValue($sut, 'registry'));
} else {
$this->assertArrayHasKey($fqcn, $this->getValue($sut, 'registry'));
}
}
public static function addItemDataProvider(): Generator
{
yield 'right interface passed' => [orderDocument::class, false];
yield 'wrong interface' => [nonOrderDocument::class, true];
}
/**
* @test
* @throws ReflectionException
* @covers \D3\PdfDocuments\Application\Model\Registries\registryAbstract::removeGenerator
* @dataProvider removeGeneratorDataProvider
*/
public function testRemoveGenerator(bool $exist, bool $removed): void
{
$sut = $this->getMockBuilder(registryOrderoverview::class)
->disableOriginalConstructor()
->onlyMethods(['hasGenerator'])
->getMock();
$sut->method('hasGenerator')->willReturn($exist);
$this->setValue(
$sut,
'registry',
array_merge(
$this->getValue(
$sut,
'registry',
),
[orderDocument::class => oxNew(orderDocument::class)]
)
);
$this->assertArrayHasKey(orderDocument::class, $this->getValue($sut, 'registry'));
$this->callMethod(
$sut,
'removeGenerator',
[orderDocument::class]
);
if ($removed) {
$this->assertArrayNotHasKey( orderDocument::class, $this->getValue( $sut, 'registry' ) );
} else {
$this->assertArrayHasKey( orderDocument::class, $this->getValue( $sut, 'registry' ) );
}
}
public static function removeGeneratorDataProvider(): Generator
{
yield 'generator exists' => [true, true];
yield 'generator does not exist' => [false, false];
}
/**
* @test
* @throws wrongPdfGeneratorInterface
* @covers \D3\PdfDocuments\Application\Model\Registries\registryAbstract::hasGenerator
*/
public function testHasGenerator(): void
{
$sut = oxNew(registryOrderoverview::class);
$this->assertFalse($sut->hasGenerator(orderDocument::class));
$sut->addGenerator(orderDocument::class);
$this->assertTrue($sut->hasGenerator(orderDocument::class));
$sut->removeGenerator(orderDocument::class);
$this->assertFalse($sut->hasGenerator(orderDocument::class));
}
/**
* @test
* @throws wrongPdfGeneratorInterface
* @covers \D3\PdfDocuments\Application\Model\Registries\registryAbstract::getList
*/
public function testGetList(): void
{
$sut = oxNew(registryOrderoverview::class);
$list = $sut->getList();
$this->assertIsIterable($list);
$startCount = count($list);
$sut->addGenerator(orderDocument::class);
$this->assertCount($startCount + 1, $sut->getList());
$sut->removeGenerator(orderDocument::class);
$this->assertCount($startCount, $sut->getList());
}
/**
* @test
* @throws wrongPdfGeneratorInterface
* @covers \D3\PdfDocuments\Application\Model\Registries\registryAbstract::clearList
*/
public function testClearList(): void
{
$sut = oxNew(registryOrderoverview::class);
$sut->addGenerator(orderDocument::class);
$sut->clearList();
$this->assertCount(0, $sut->getList());
}
}

Datei anzeigen

@ -13,89 +13,89 @@
namespace D3\PdfDocuments\Tests\Unit\Application\Model\Registries;
use D3\PdfDocuments\Application\Model\Constants;
use D3\PdfDocuments\Application\Model\Documents\invoicePdf;
use D3\PdfDocuments\Application\Model\Exceptions\wrongPdfGeneratorInterface;
use D3\PdfDocuments\Application\Model\Registries\registryOrderoverview;
use D3\PdfDocuments\Tests\Unit\Helpers\nonOrderDocument;
use D3\PdfDocuments\Tests\Unit\Helpers\orderDocument;
use D3\TestingTools\Development\CanAccessRestricted;
use Exception;
use Generator;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
use PHPUnit\Framework\TestCase;
use ReflectionException;
class registryOrderOverviewTest extends TestCase
class registryOrderOverviewTest extends registryAbstract
{
use CanAccessRestricted;
/**
* @test
* @throws ReflectionException
* @covers \D3\PdfDocuments\Application\Model\Registries\registryAbstract::addGenerator
* @dataProvider addGeneratorDataProvider
* @covers \D3\PdfDocuments\Application\Model\Registries\registryOrderoverview::__construct
* @dataProvider constructDataProvider
*/
public function testAddGenerator(bool $exist, InvocationOrder $addInvocation, bool $expectException): void
public function testConstructor(bool $inv, bool $deln, bool $invNL, bool $delnNL, int $expectedCount): void
{
$sut = $this->getMockBuilder(registryOrderoverview::class)
->onlyMethods(['hasGenerator', 'addItem'])
->getMock();
$sut->method('hasGenerator')->willReturn($exist);
$sut->expects($addInvocation)->method('addItem');
if ($expectException) {
$this->expectException(Exception::class);
}
$this->callMethod(
$sut,
'addGenerator',
[invoicePdf::class]
);
}
public static function addGeneratorDataProvider(): Generator
{
yield 'not added' => [false, self::once(), false];
yield 'already added' => [true, self::never(), true];
}
/**
* @test
* @throws ReflectionException
* @covers \D3\PdfDocuments\Application\Model\Registries\registryAbstract::addItem
* @dataProvider addItemDataProvider
*/
public function testAddItem(string $fqcn, bool $expectException): void
{
$sut = $this->getMockBuilder(registryOrderoverview::class)
$settingService = $this->getMockBuilder(ModuleSettingService::class)
->onlyMethods(['getBoolean'])
->disableOriginalConstructor()
->onlyMethods(['addGenerator'])
->getMock();
$settingService->method('getBoolean')->willReturnMap([
['d3PdfDocumentsDocInvoice', Constants::OXID_MODULE_ID, $inv],
['d3PdfDocumentsDocDeliveryNote', Constants::OXID_MODULE_ID, $deln],
['d3PdfDocumentsDocInvoiceNoLogo', Constants::OXID_MODULE_ID, $invNL],
['d3PdfDocumentsDocDeliveryNoteNoLogo', Constants::OXID_MODULE_ID, $delnNL]
]);
$this->assertArrayNotHasKey($fqcn, $this->getValue($sut, 'registry'));
try {
$this->addServiceMocks([ModuleSettingServiceInterface::class => $settingService]);
if ($expectException) {
$this->expectException(Exception::class);
}
$sut = $this->getMockBuilder(registryOrderoverview::class)
->disableOriginalConstructor()
->onlyMethods(['addGenerator'])
->getMock();
$sut->expects($this->exactly($expectedCount))->method('addGenerator');
$this->callMethod(
$sut,
'addItem',
[oxNew($fqcn)]
);
if ($expectException) {
$this->assertArrayNotHasKey($fqcn, $this->getValue($sut, 'registry'));
} else {
$this->assertArrayHasKey($fqcn, $this->getValue($sut, 'registry'));
$this->callMethod(
$sut,
'__construct'
);
} finally {
ContainerFactory::resetContainer();
}
}
public static function addItemDataProvider(): Generator
public static function constructDataProvider(): Generator
{
dumpvar(__LINE__);
yield 'right interface passed' => [invoicePdf::class, false];
dumpvar(__LINE__);
yield 'wrong interface' => [nonOrderDocument::class, true];
dumpvar(__LINE__);
yield 'nothing' => [false, false, false, false, 0];
yield 'invoice only' => [true, false, false, false, 1];
yield 'invoice + delnote' => [true, true, false, false, 2];
yield 'invoice + NoLogo + delnote' => [true, true, true, false, 3];
yield 'invoice + NoLogo + delnote + NoLogo' => [true, true, true, true, 4];
yield 'invNoLogo + delnote + NoLogo' => [false, true, true, true, 3];
}
/**
* @test
* @throws ReflectionException
* @throws wrongPdfGeneratorInterface
* @covers \D3\PdfDocuments\Application\Model\Registries\registryOrderoverview::getGenerator
*/
public function testGetGenerator(): void
{
$sut = oxNew(registryOrderoverview::class);
$sut->addGenerator(orderDocument::class);
$this->assertInstanceOf(
orderDocument::class,
$this->callMethod(
$sut,
'getGenerator',
[orderDocument::class]
)
);
}
}

Datei anzeigen

@ -0,0 +1,95 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
namespace D3\PdfDocuments\Tests\Unit\Application\Model\Registries;
use D3\PdfDocuments\Application\Model\Constants;
use D3\PdfDocuments\Application\Model\Exceptions\wrongPdfGeneratorInterface;
use D3\PdfDocuments\Application\Model\Registries\registryOrdermanagerActions;
use D3\PdfDocuments\Tests\Unit\Helpers\orderDocument;
use Generator;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
use ReflectionException;
class registryOrdermanagerActionsTest extends registryAbstract
{
/**
* @test
* @throws ReflectionException
* @covers \D3\PdfDocuments\Application\Model\Registries\registryOrdermanagerActions::__construct
* @dataProvider constructDataProvider
*/
public function testConstructor(bool $inv, bool $deln, bool $invNL, bool $delnNL, int $expectedCount): void
{
$settingService = $this->getMockBuilder(ModuleSettingService::class)
->onlyMethods(['getBoolean'])
->disableOriginalConstructor()
->getMock();
$settingService->method('getBoolean')->willReturnMap([
['d3PdfDocumentsDocInvoice', Constants::OXID_MODULE_ID, $inv],
['d3PdfDocumentsDocDeliveryNote', Constants::OXID_MODULE_ID, $deln],
['d3PdfDocumentsDocInvoiceNoLogo', Constants::OXID_MODULE_ID, $invNL],
['d3PdfDocumentsDocDeliveryNoteNoLogo', Constants::OXID_MODULE_ID, $delnNL]
]);
$this->addServiceMocks([ModuleSettingServiceInterface::class => $settingService]);
try {
$sut = $this->getMockBuilder(registryOrdermanagerActions::class)
->disableOriginalConstructor()
->onlyMethods(['addGenerator'])
->getMock();
$sut->expects($this->exactly($expectedCount))->method('addGenerator');
$this->callMethod(
$sut,
'__construct'
);
} finally {
ContainerFactory::resetContainer();
}
}
public static function constructDataProvider(): Generator
{
yield 'nothing' => [false, false, false, false, 0];
yield 'invoice only' => [true, false, false, false, 1];
yield 'invoice + delnote' => [true, true, false, false, 2];
yield 'invoice + NoLogo + delnote' => [true, true, true, false, 3];
yield 'invoice + NoLogo + delnote + NoLogo' => [true, true, true, true, 4];
yield 'invNoLogo + delnote + NoLogo' => [false, true, true, true, 3];
}
/**
* @test
* @throws ReflectionException
* @throws wrongPdfGeneratorInterface
* @covers \D3\PdfDocuments\Application\Model\Registries\registryOrdermanagerActions::getGenerator
*/
public function testGetGenerator(): void
{
$sut = oxNew(registryOrdermanagerActions::class);
$sut->addGenerator(orderDocument::class);
$this->assertInstanceOf(
orderDocument::class,
$this->callMethod(
$sut,
'getGenerator',
[orderDocument::class]
)
);
}
}

Datei anzeigen

@ -58,4 +58,9 @@ class nonOrderDocument implements pdfdocumentsGenericInterface
{
return 'filenameExtension';
}
public function setDevelopmentMode( bool $devMode )
{
return false;
}
}

Datei anzeigen

@ -0,0 +1,81 @@
<?php
namespace D3\PdfDocuments\Tests\Unit\Helpers;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderInterface;
use OxidEsales\Eshop\Application\Model\Order;
class orderDocument implements pdfdocumentsOrderInterface
{
public function getRequestId(): string
{
return 'requestId';
}
public function getTitleIdent(): string
{
return 'titleIdent';
}
public function getTemplate(): string
{
return 'template';
}
public function getHTMLContent(): string
{
return "HtmlContent";
}
public function downloadPdf(int $language = 0): void
{
}
public function getPdfContent(int $language = 0): ?string
{
return "pdfContent";
}
public function savePdfFile(string $path, int $language = 0): void
{
}
public function genPdf(string $filename, int $language = 0, string $target = 'I'): ?string
{
return null;
}
public function setFilename(string $filename): void
{
}
public function getFilename(): string
{
return 'filename';
}
public function addFilenameExtension(string $filename): string
{
return 'filenameExtension';
}
public function setDevelopmentMode( bool $devMode )
{
return false;
}
public function setOrder( Order $order ): void
{
}
public function getOrder(): Order
{
return oxNew(Order::class);
}
public function getTypeForFilename(): string
{
return 'typeForFilename';
}
}