add tests
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.phpunit.result.cache
|
||||
Tests/.phpunit.result.cache
|
||||
Tests/result
|
@ -19,8 +19,12 @@ use D3\PdfDocuments\Application\Model\Exceptions\noPdfHandlerFoundException;
|
||||
use D3\PdfDocuments\Application\Model\Exceptions\wrongPdfGeneratorInterface;
|
||||
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderInterface;
|
||||
use D3\PdfDocuments\Application\Model\Registries\registryOrderoverview;
|
||||
use D3\PdfDocuments\Application\Model\Registries\registryOrderoverviewInterface;
|
||||
use OxidEsales\Eshop\Application\Model\Order;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class orderOverviewPdfGenerator
|
||||
{
|
||||
@ -37,15 +41,17 @@ class orderOverviewPdfGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return pdfdocumentsOrderInterface
|
||||
* @throws noPdfHandlerFoundException
|
||||
* @throws wrongPdfGeneratorInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws noPdfHandlerFoundException
|
||||
*/
|
||||
public function getPdfClass(): pdfdocumentsOrderInterface
|
||||
{
|
||||
$requestedType = Registry::getRequest()->getRequestParameter('pdftype');
|
||||
|
||||
$generatorList = oxNew(registryOrderoverview::class);
|
||||
/** @var registryOrderoverview $generatorList */
|
||||
$generatorList = ContainerFactory::getInstance()->getContainer()->get(registryOrderoverviewInterface::class);
|
||||
/** @var pdfdocumentsOrderInterface $generator */
|
||||
foreach ($generatorList->getList() as $generator) {
|
||||
if ($generator->getRequestId() == $requestedType) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
$sLangName = "Deutsch";
|
||||
return [
|
||||
'charset' => 'utf-8',
|
||||
@ -78,3 +79,4 @@ return [
|
||||
|
||||
'D3_PDFDOCUMENTS_BANK_BANKCODE' => 'BIC/SWIFT-Code',
|
||||
];
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
@ -11,6 +11,7 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return [
|
||||
'charset' => 'utf-8',
|
||||
|
||||
@ -77,3 +78,4 @@ return [
|
||||
|
||||
'D3_PDFDOCUMENTS_BANK_BANKCODE' => 'BIC/SWIFT Code',
|
||||
];
|
||||
// @codeCoverageIgnoreEnd
|
@ -42,3 +42,4 @@ return [
|
||||
'D3_PDFDOCUMENTS_LANGUAGE' => 'Sprache',
|
||||
'D3_PDFDOCUMENTS_PDF_GENERATE' => 'Dokument erstellen',
|
||||
];
|
||||
// @codeCoverageIgnoreEnd
|
@ -42,3 +42,4 @@ return [
|
||||
'D3_PDFDOCUMENTS_LANGUAGE' => 'Language',
|
||||
'D3_PDFDOCUMENTS_PDF_GENERATE' => 'Create Document',
|
||||
];
|
||||
// @codeCoverageIgnoreEnd
|
@ -0,0 +1,116 @@
|
||||
<?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\Controller;
|
||||
|
||||
use Assert\InvalidArgumentException;
|
||||
use D3\PdfDocuments\Application\Controller\orderOverviewPdfGenerator;
|
||||
use D3\PdfDocuments\Application\Model\AbstractClasses\pdfdocumentsGeneric;
|
||||
use D3\PdfDocuments\Application\Model\Constants;
|
||||
use D3\PdfDocuments\Application\Model\Documents\invoicePdf;
|
||||
use D3\PdfDocuments\Application\Model\Exceptions\noPdfHandlerFoundException;
|
||||
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface as genericInterface;
|
||||
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderInterface;
|
||||
use D3\PdfDocuments\Application\Model\Registries\registryOrderoverview;
|
||||
use D3\PdfDocuments\Application\Model\Registries\registryOrderoverviewInterface;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use Generator;
|
||||
use OxidEsales\Eshop\Application\Model\Order;
|
||||
use OxidEsales\Eshop\Core\Base;
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\UtilsView;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRenderer;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
|
||||
use OxidEsales\Twig\Resolver\TemplateChain\TemplateNotInChainException;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use ReflectionException;
|
||||
use Spipu\Html2Pdf\Exception\Html2PdfException;
|
||||
use Spipu\Html2Pdf\Html2Pdf;
|
||||
use Symfony\Component\String\UnicodeString;
|
||||
use Twig\Error\Error;
|
||||
|
||||
class orderOverviewPdfGeneratorTest extends TestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers \D3\PdfDocuments\Application\Controller\orderOverviewPdfGenerator::generatePdf
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGeneratePdf(): void
|
||||
{
|
||||
$document = $this->getMockBuilder(invoicePdf::class)
|
||||
->onlyMethods(['downloadPdf'])
|
||||
->getMock();
|
||||
$document->expects($this->once())->method('downloadPdf');
|
||||
|
||||
$sut = $this->getMockBuilder(orderOverviewPdfGenerator::class)
|
||||
->onlyMethods(['getPdfClass'])
|
||||
->getMock();
|
||||
$sut->expects($this->once())->method('getPdfClass')->willReturn($document);
|
||||
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'generatePdf',
|
||||
[oxNew(Order::class)]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers \D3\PdfDocuments\Application\Controller\orderOverviewPdfGenerator::getPdfClass
|
||||
* @throws ReflectionException
|
||||
* @dataProvider getPdfClassDataProvider
|
||||
*/
|
||||
public function testGetPdfClass(array $generatorList, string $request, bool $expectException): void
|
||||
{
|
||||
$_GET['pdftype'] = $request;
|
||||
|
||||
$orderOverviewRegistry = $this->getMockBuilder(registryOrderoverview::class)
|
||||
->onlyMethods(['getList'])
|
||||
->getMock();
|
||||
$orderOverviewRegistry->method('getList')->willReturn($generatorList);
|
||||
|
||||
$this->addServiceMocks([
|
||||
registryOrderoverviewInterface::class => $orderOverviewRegistry,
|
||||
]);
|
||||
|
||||
$sut = oxNew(orderOverviewPdfGenerator::class);
|
||||
|
||||
if ($expectException) {
|
||||
$this->expectException(noPdfHandlerFoundException::class);
|
||||
}
|
||||
|
||||
$this->assertInstanceOf(
|
||||
pdfdocumentsOrderInterface::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getPdfClass',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function getPdfClassDataProvider(): Generator
|
||||
{
|
||||
yield 'no generator set' => [[], 'foo', true];
|
||||
yield 'unknown generator set' => [[new invoicePdf()], 'foo', true];
|
||||
yield 'valid generator set' => [[new invoicePdf()], 'invoice', false];
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ use D3\PdfDocuments\Application\Model\Constants as Constants;
|
||||
use D3\PdfDocuments\Modules\Application\Controller\d3_overview_controller_pdfdocuments;
|
||||
use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview;
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
$sMetadataVersion = '2.1';
|
||||
|
||||
$aModule = [
|
||||
@ -100,3 +101,4 @@ $aModule = [
|
||||
],
|
||||
],
|
||||
];
|
||||
// @codeCoverageIgnoreEnd
|
10
services.yaml
Normal file
10
services.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
services:
|
||||
_defaults:
|
||||
autowire: false
|
||||
public: true
|
||||
|
||||
D3\PdfDocuments\Application\Model\Registries\registryOrderoverviewInterface:
|
||||
factory: 'oxNew'
|
||||
shared: true
|
||||
arguments:
|
||||
- D3\PdfDocuments\Application\Model\Registries\registryOrderoverview
|
Reference in New Issue
Block a user