1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 01:11:34 +02:00
invoiceninja/tests/Unit/EInvoiceTest.php

75 lines
2.3 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();
$e_invoice = (new CreateEInvoice($this->invoice))->handle();
2023-08-16 12:59:42 +02:00
$this->assertIsString($e_invoice);
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
$e_invoice = (new CreateEInvoice($this->invoice))->handle();
2023-08-16 12:59:42 +02:00
$document = ZugferdDocumentReader::readAndGuessFromContent($e_invoice);
2023-04-17 11:55:38 +02:00
$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-16 12:59:42 +02:00
$document = ZugferdDocumentReader::readAndGuessFromContent($pdf);
2023-04-17 11:55:38 +02:00
$document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $documentcurrency, $taxcurrency, $taxname, $documentlangeuage, $rest);
$this->assertEquals($this->invoice->number, $documentno);
}
2023-04-06 11:08:59 +02:00
}