1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/tests/Feature/EInvoice/FacturaeTest.php

134 lines
3.9 KiB
PHP
Raw Normal View History

2023-04-21 01:52:56 +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-27 08:42:50 +02:00
namespace Tests\Feature\EInvoice;
2023-04-21 01:52:56 +02:00
2023-05-08 06:13:14 +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-21 01:52:56 +02:00
/**
* @test
*/
class FacturaeTest extends TestCase
{
use DatabaseTransactions;
use MockAccountData;
protected function setUp() :void
{
parent::setUp();
$this->makeTestData();
$this->withoutMiddleware(
ThrottleRequests::class
);
}
public function testInvoiceGeneration()
{
2024-03-20 21:15:17 +01:00
$f = new \App\Services\EDocument\Standards\FacturaEInvoice($this->invoice, "3.2.2");
2023-05-08 06:13:14 +02:00
$path = $f->run();
2023-04-21 01:52:56 +02:00
$this->assertNotNull($f->run());
2023-11-08 22:29:35 +01:00
// nlog($f->run());
2023-05-08 06:13:14 +02:00
2023-05-08 11:23:08 +02:00
// $this->assertTrue($this->validateInvoiceXML($path));
2023-04-21 01:52:56 +02:00
}
2023-05-08 06:13:14 +02:00
2023-11-26 08:41:42 +01:00
// protected function validateInvoiceXML($path, $validateSignature=false) {
// // Prepare file to upload
// if (function_exists('curl_file_create')) {
// $postFile = curl_file_create($path);
// } else {
// $postFile = "@" . realpath($path);
// }
// // Send upload request
// $ch = curl_init();
// curl_setopt_array($ch, array(
// CURLOPT_RETURNTRANSFER => true,
// CURLOPT_FOLLOWLOCATION => true,
// CURLOPT_URL => "http://plataforma.firma-e.com/VisualizadorFacturae/index2.jsp",
// CURLOPT_POST => 1,
// CURLOPT_POSTFIELDS => array(
// "referencia" => $postFile,
// "valContable" => "on",
// "valFirma" => $validateSignature ? "on" : "off",
// "aceptarCondiciones" => "on",
// "submit" => "Siguiente"
// ),
// CURLOPT_COOKIEJAR => base_path()."/cookie.txt"
// ));
// $res = curl_exec($ch);
// curl_close($ch);
// unset($ch);
// nlog($res);
// if (strpos($res, "window.open('facturae.jsp'") === false) {
// $this->expectException(\UnexpectedValueException::class);
// }
// // Fetch results
// $ch = curl_init();
// curl_setopt_array($ch, array(
// CURLOPT_RETURNTRANSFER => true,
// CURLOPT_FOLLOWLOCATION => true,
// CURLOPT_URL => "http://plataforma.firma-e.com/VisualizadorFacturae/facturae.jsp",
// CURLOPT_COOKIEFILE => base_path()."/cookie.txt"
// ));
// $res = curl_exec($ch);
// curl_close($ch);
// unset($ch);
// nlog($res);
// // Validate results
// $this->assertNotEmpty($res, 'Invalid Validator Response');
// $this->assertNotEmpty(strpos($res, 'euro_ok.png'), 'Invalid XML Format');
// if ($validateSignature) {
// $this->assertNotEmpty(strpos($res, '>Nivel de Firma Válido<'), 'Invalid Signature');
// }
// if (strpos($res, '>Sellos de Tiempo<') !== false) {
// $this->assertNotEmpty(strpos($res, '>XAdES_T<'), 'Invalid Timestamp');
// }
// }
2023-05-08 11:11:14 +02:00
// private function validateInvoiceXML($path)
// {
// $client = new \GuzzleHttp\Client(['cookies' => true]);
// $response = $client->request('POST', 'https://face.gob.es/api/v1/herramientas/validador',[
// 'multipart' => [
// [
// 'name' => 'validador[factura]',
// 'contents' => Storage::get($path),
// ],
// ]
// ]);
// $response = $client->request('POST', 'http://plataforma.firma-e.com/VisualizadorFacturae/facturae.jsp');
// $body = $response->getBody();
// $stringBody = (string) $body;
// echo print_r($stringBody,1);
// }
2023-05-08 06:13:14 +02:00
2023-11-26 08:41:42 +01:00
}