|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of Modelo347 plugin for FacturaScripts |
| 4 | + * Copyright (C) 2024 Carlos Garcia Gomez <carlos@facturascripts.com> |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Lesser General Public License as |
| 8 | + * published by the Free Software Foundation, either version 3 of the |
| 9 | + * License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +namespace FacturaScripts\Test\Plugins\Extension\Table; |
| 21 | + |
| 22 | +use FacturaScripts\Dinamic\Model\Cliente; |
| 23 | +use FacturaScripts\Dinamic\Model\FacturaCliente; |
| 24 | +use FacturaScripts\Dinamic\Model\FacturaProveedor; |
| 25 | +use FacturaScripts\Dinamic\Model\Proveedor; |
| 26 | +use FacturaScripts\Test\Traits\DefaultSettingsTrait; |
| 27 | +use FacturaScripts\Test\Traits\LogErrorsTrait; |
| 28 | +use PHPUnit\Framework\TestCase; |
| 29 | + |
| 30 | +/** |
| 31 | + * @author Daniel Fernández Giménez <hola@danielfg.es> |
| 32 | + */ |
| 33 | +final class FacturasTest extends TestCase |
| 34 | +{ |
| 35 | + use LogErrorsTrait; |
| 36 | + use DefaultSettingsTrait; |
| 37 | + |
| 38 | + public static function setUpBeforeClass(): void |
| 39 | + { |
| 40 | + // configuración por defecto para el almacén por defecto |
| 41 | + self::setDefaultSettings(); |
| 42 | + self::installAccountingPlan(); |
| 43 | + self::removeTaxRegularization(); |
| 44 | + } |
| 45 | + |
| 46 | + public function testExistsPropertyFacturaCliente() |
| 47 | + { |
| 48 | + // crear el cliente |
| 49 | + $customer = new Cliente(); |
| 50 | + $customer->cifnif = 'B' . mt_rand(1, 999999); |
| 51 | + $customer->nombre = 'Customer Rand ' . mt_rand(1, 99999); |
| 52 | + $customer->observaciones = 'Test'; |
| 53 | + $customer->razonsocial = 'Empresa ' . mt_rand(1, 99999); |
| 54 | + $this->assertTrue($customer->save(), 'cant-create-customer'); |
| 55 | + |
| 56 | + // crear la factura |
| 57 | + $invoice = new FacturaCliente(); |
| 58 | + $invoice->setSubject($customer); |
| 59 | + $invoice->numero2 = 'INV-' . mt_rand(1, 99999) . '-' . mt_rand(1, 99999); |
| 60 | + $invoice->observaciones = 'Test'; |
| 61 | + $invoice->excluir347 = true; |
| 62 | + $this->assertTrue($invoice->save(), 'cant-create-invoice'); |
| 63 | + $this->assertTrue($invoice->exists(), 'invoice-not-exists'); |
| 64 | + |
| 65 | + // comprobar el campo |
| 66 | + $this->assertTrue($invoice->loadFromCode($invoice->idfactura), 'cant-create-load'); |
| 67 | + $this->assertTrue($invoice->excluir347, 'value-not-saved'); |
| 68 | + $invoice->excluir347 = false; |
| 69 | + $this->assertTrue($invoice->save(), 'cant-create-invoice'); |
| 70 | + |
| 71 | + $this->assertTrue($invoice->loadFromCode($invoice->idfactura), 'cant-create-load'); |
| 72 | + $this->assertFalse($invoice->excluir347, 'value-not-saved'); |
| 73 | + |
| 74 | + // eliminar la factura |
| 75 | + $this->assertTrue($invoice->delete(), 'cant-delete-invoice'); |
| 76 | + $this->assertTrue($customer->getDefaultAddress()->delete()); |
| 77 | + $this->assertTrue($customer->delete(), 'cant-delete-customer'); |
| 78 | + } |
| 79 | + |
| 80 | + public function testExistsPropertyFacturaProveedor() |
| 81 | + { |
| 82 | + // crear proveedor |
| 83 | + $suplier = new Proveedor(); |
| 84 | + $suplier->cifnif = 'B' . mt_rand(1, 999999); |
| 85 | + $suplier->nombre = 'suplier Rand ' . mt_rand(1, 99999); |
| 86 | + $suplier->observaciones = 'Test'; |
| 87 | + $suplier->razonsocial = 'Empresa ' . mt_rand(1, 99999); |
| 88 | + $this->assertTrue($suplier->save(), 'cant-create-suplier'); |
| 89 | + |
| 90 | + // crear la factura de proveedor |
| 91 | + $invoice = new FacturaProveedor(); |
| 92 | + $invoice->setSubject($suplier); |
| 93 | + $invoice->numero2 = 'INV-' . mt_rand(1, 99999) . '-' . mt_rand(1, 99999); |
| 94 | + $invoice->observaciones = 'Test'; |
| 95 | + $invoice->excluir347 = true; |
| 96 | + $this->assertTrue($invoice->save(), 'cant-create-invoice'); |
| 97 | + $this->assertTrue($invoice->exists(), 'invoice-not-exists'); |
| 98 | + |
| 99 | + // comprobar el campo |
| 100 | + $this->assertTrue($invoice->loadFromCode($invoice->idfactura), 'cant-create-load'); |
| 101 | + $this->assertTrue($invoice->excluir347, 'value-not-saved'); |
| 102 | + $invoice->excluir347 = false; |
| 103 | + $this->assertTrue($invoice->save(), 'cant-create-invoice'); |
| 104 | + |
| 105 | + $this->assertTrue($invoice->loadFromCode($invoice->idfactura), 'cant-create-load'); |
| 106 | + $this->assertFalse($invoice->excluir347, 'value-not-saved'); |
| 107 | + |
| 108 | + // eliminar la factura |
| 109 | + $this->assertTrue($invoice->delete(), 'cant-delete-invoice'); |
| 110 | + $this->assertTrue($suplier->getDefaultAddress()->delete()); |
| 111 | + $this->assertTrue($suplier->delete(), 'cant-delete-suplier'); |
| 112 | + } |
| 113 | + |
| 114 | + protected function tearDown(): void |
| 115 | + { |
| 116 | + $this->logErrors(); |
| 117 | + } |
| 118 | +} |
0 commit comments