2023-04-06 11:08:59 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
2024-08-30 07:44:01 +02:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
2024-03-10 08:13:34 +01:00
|
|
|
use App\Jobs\EDocument\CreateEDocument;
|
2023-10-26 03:25:56 +02:00
|
|
|
use App\Jobs\Entity\CreateRawPdf;
|
2023-04-06 11:08:59 +02:00
|
|
|
use horstoeko\zugferd\ZugferdDocumentReader;
|
2023-04-17 10:23:07 +02:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2023-11-26 08:41:42 +01:00
|
|
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
2023-04-06 11:08:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2023-04-17 09:24:16 +02:00
|
|
|
* @covers App\Jobs\Invoice\CreateXInvoice
|
2023-04-06 11:08:59 +02:00
|
|
|
*/
|
2023-04-17 09:24:16 +02:00
|
|
|
class EInvoiceTest extends TestCase
|
2023-04-06 11:08:59 +02:00
|
|
|
{
|
|
|
|
use MockAccountData;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
2024-08-22 08:57:52 +02:00
|
|
|
protected function setUp(): void
|
2023-04-06 11:08:59 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->withoutMiddleware(
|
|
|
|
ThrottleRequests::class
|
|
|
|
);
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
2023-04-17 09:24:16 +02:00
|
|
|
public function testEInvoiceGenerates()
|
2023-04-06 11:08:59 +02:00
|
|
|
{
|
2023-04-17 11:55:38 +02:00
|
|
|
$this->company->e_invoice_type = "EN16931";
|
2023-04-17 10:23:07 +02:00
|
|
|
$this->invoice->client->routing_id = 'DE123456789';
|
|
|
|
$this->invoice->client->save();
|
2024-03-10 08:13:34 +01:00
|
|
|
$e_invoice = (new CreateEDocument($this->invoice))->handle();
|
2023-08-16 12:59:42 +02:00
|
|
|
$this->assertIsString($e_invoice);
|
2023-04-06 11:08:59 +02:00
|
|
|
}
|
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function testValidityofXMLFile()
|
|
|
|
{
|
|
|
|
$this->company->e_invoice_type = "EN16931";
|
|
|
|
$this->invoice->client->routing_id = 'DE123456789';
|
|
|
|
$this->invoice->client->save();
|
2023-04-17 10:23:07 +02:00
|
|
|
|
2024-03-10 08:13:34 +01:00
|
|
|
$e_invoice = (new CreateEDocument($this->invoice))->handle();
|
2023-11-26 08:41:42 +01:00
|
|
|
$document = ZugferdDocumentReader::readAndGuessFromContent($e_invoice);
|
|
|
|
$document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $documentcurrency, $taxcurrency, $taxname, $documentlangeuage, $rest);
|
|
|
|
$this->assertEquals($this->invoice->number, $documentno);
|
|
|
|
}
|
2023-04-17 09:24:16 +02:00
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function checkEmbededPDFFile()
|
|
|
|
{
|
|
|
|
$pdf = (new CreateRawPdf($this->invoice->invitations()->first()))->handle();
|
|
|
|
$document = ZugferdDocumentReader::readAndGuessFromContent($pdf);
|
|
|
|
$document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $documentcurrency, $taxcurrency, $taxname, $documentlangeuage, $rest);
|
|
|
|
$this->assertEquals($this->invoice->number, $documentno);
|
|
|
|
}
|
2023-04-06 11:08:59 +02:00
|
|
|
}
|