1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/tests/Unit/EInvoiceTest.php

78 lines
2.5 KiB
PHP
Raw Normal View History

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
*/
2023-04-17 10:23:07 +02:00
use Tests\TestCase;
use Tests\MockAccountData;
2023-04-06 11:08:59 +02:00
use App\Jobs\Entity\CreateEntityPdf;
2023-04-21 07:44:11 +02:00
use App\Jobs\Invoice\CreateEInvoice;
2023-04-17 10:23:07 +02:00
use Illuminate\Support\Facades\Storage;
2023-04-06 11:08:59 +02:00
use horstoeko\zugferd\ZugferdDocumentReader;
2023-04-17 10:23:07 +02:00
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Foundation\Testing\DatabaseTransactions;
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;
protected function setUp() :void
{
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();
2023-08-07 09:59:10 +02:00
$xinvoice = (new CreateEInvoice($this->invoice))->handle();
2023-04-06 11:08:59 +02:00
$this->assertNotNull($xinvoice);
2023-04-17 10:23:07 +02:00
$this->assertTrue(Storage::exists($xinvoice));
2023-04-06 11:08:59 +02:00
}
2023-04-17 11:55:38 +02: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
2023-08-07 09:59:10 +02:00
$xinvoice = (new CreateEInvoice($this->invoice))->handle();
2023-04-17 11:55:38 +02:00
nlog(Storage::path($xinvoice));
$document = ZugferdDocumentReader::readAndGuessFromFile(Storage::path($xinvoice));
$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-04-17 11:55:38 +02:00
/**
* @throws Exception
*/
public function checkEmbededPDFFile()
{
$pdf = (new CreateEntityPdf($this->invoice->invitations()->first()))->handle();
2023-08-07 09:59:10 +02:00
(new CreateEInvoice($this->invoice))->handle();
2023-04-17 11:55:38 +02:00
$document = ZugferdDocumentReader::readAndGuessFromFile($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
}