Skip to content

Commit d1dbc2f

Browse files
authored
Merge branch 'FacturaScripts:master' into master
2 parents f0af468 + 70d57c0 commit d1dbc2f

3 files changed

Lines changed: 273 additions & 0 deletions

File tree

.github/workflows/tests.yml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
name: Tests del Plugin FacturaScripts
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
tests:
11+
name: Tests en ${{ matrix.database }} con PHP ${{ matrix.php-version }}
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php-version: ['8.0', '8.1']
18+
database: ['mysql', 'postgresql']
19+
20+
env:
21+
NOMBRE_PLUGIN: "Modelo347"
22+
23+
services:
24+
mysql:
25+
image: mariadb:11
26+
ports:
27+
- 3306:3306
28+
env:
29+
MARIADB_ROOT_PASSWORD: toor
30+
MARIADB_DATABASE: facturascripts_tests
31+
options: >-
32+
--health-cmd="mariadb-admin ping"
33+
--health-interval=10s
34+
--health-timeout=5s
35+
--health-retries=3
36+
37+
postgres:
38+
image: postgres:13
39+
ports:
40+
- 5432:5432
41+
env:
42+
POSTGRES_PASSWORD: toor
43+
POSTGRES_DB: facturascripts_tests
44+
options: >-
45+
--health-cmd=pg_isready
46+
--health-interval=10s
47+
--health-timeout=5s
48+
--health-retries=5
49+
50+
steps:
51+
- name: Instalar PHP y extensiones
52+
uses: shivammathur/setup-php@v2
53+
with:
54+
php-version: ${{ matrix.php-version }}
55+
extensions: json, fileinfo, simplexml, zip, dom, pdo, pdo_mysql, mysql, mysqli, pgsql, pdo_pgsql, bcmath, gd, curl, soap
56+
tools: composer
57+
coverage: none
58+
59+
- name: Clonar FacturaScripts
60+
uses: actions/checkout@v4
61+
with:
62+
fetch-depth: 0
63+
repository: 'NeoRazorX/facturascripts'
64+
65+
- name: Clonar Plugin ${{ env.NOMBRE_PLUGIN }}
66+
uses: actions/checkout@v4
67+
with:
68+
fetch-depth: 0
69+
path: Plugins/${{ env.NOMBRE_PLUGIN }}
70+
71+
- name: Cache de dependencias de Composer
72+
uses: actions/cache@v3
73+
with:
74+
path: ~/.composer/cache/files
75+
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
76+
restore-keys: |
77+
composer-${{ runner.os }}-${{ matrix.php-version }}-
78+
composer-${{ runner.os }}-
79+
80+
- name: Instalar dependencias de FacturaScripts
81+
run: |
82+
mkdir -p MyFiles
83+
touch MyFiles/plugins.json
84+
composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader
85+
86+
- name: Crear archivo de configuración
87+
run: |
88+
cat > config.php << 'EOF'
89+
<?php
90+
91+
define('FS_COOKIES_EXPIRE', 604800);
92+
define('FS_LANG', 'es_ES');
93+
define('FS_TIMEZONE', 'Europe/Madrid');
94+
define('FS_ROUTE', '');
95+
96+
${{ matrix.database == 'mysql' && format('
97+
define(''FS_DB_TYPE'', ''mysql'');
98+
define(''FS_DB_HOST'', ''127.0.0.1'');
99+
define(''FS_DB_PORT'', ''3306'');
100+
define(''FS_DB_USER'', ''root'');
101+
') || format('
102+
define(''FS_DB_TYPE'', ''postgresql'');
103+
define(''FS_DB_HOST'', ''localhost'');
104+
define(''FS_DB_PORT'', ''5432'');
105+
define(''FS_DB_USER'', ''postgres'');
106+
') }}
107+
define('FS_DB_NAME', 'facturascripts_tests');
108+
define('FS_DB_PASS', 'toor');
109+
define('FS_DB_FOREIGN_KEYS', true);
110+
define('FS_DB_TYPE_CHECK', true);
111+
define('FS_MYSQL_CHARSET', 'utf8');
112+
define('FS_MYSQL_COLLATE', 'utf8_bin');
113+
114+
define('FS_HIDDEN_PLUGINS', '');
115+
define('FS_DEBUG', false);
116+
define('FS_DISABLE_ADD_PLUGINS', false);
117+
define('FS_DISABLE_RM_PLUGINS', false);
118+
define('FS_NF0', 2);
119+
EOF
120+
121+
- name: Copiar archivos de tests del Plugin
122+
run: |
123+
if [ -d "Plugins/${{ env.NOMBRE_PLUGIN }}/Test/main" ]; then
124+
cp -r Plugins/${{ env.NOMBRE_PLUGIN }}/Test/main Test/Plugins
125+
else
126+
echo "No se encontraron tests para el plugin"
127+
exit 1
128+
fi
129+
130+
- name: Instalar dependencias del Plugin ${{ env.NOMBRE_PLUGIN }}
131+
run: |
132+
if [ -f "Plugins/${{ env.NOMBRE_PLUGIN }}/composer.json" ]; then
133+
cd Plugins/${{ env.NOMBRE_PLUGIN }}
134+
composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader
135+
else
136+
echo "El plugin no tiene dependencias de Composer"
137+
fi
138+
139+
- name: Instalar el Plugin ${{ env.NOMBRE_PLUGIN }}
140+
run: php Test/install-plugins.php
141+
142+
- name: Ejecutar tests en ${{ matrix.database }}
143+
run: vendor/bin/phpunit -c phpunit-plugins.xml --verbose
144+
145+
- name: Mostrar logs en caso de fallo
146+
if: failure()
147+
run: |
148+
echo "=== Logs de la base de datos ==="
149+
if [ "${{ matrix.database }}" = "mysql" ]; then
150+
docker logs $(docker ps -q --filter ancestor=mariadb:11) || true
151+
else
152+
docker logs $(docker ps -q --filter ancestor=postgres:13) || true
153+
fi

Init.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use FacturaScripts\Core\Template\InitClass;
2525
use FacturaScripts\Dinamic\Model\FacturaCliente;
2626
use FacturaScripts\Dinamic\Model\FacturaProveedor;
27+
use FacturaScripts\Dinamic\Model\User;
2728

2829
/**
2930
* Description of Init
@@ -48,6 +49,7 @@ public function uninstall(): void
4849

4950
public function update(): void
5051
{
52+
new User();
5153
new FacturaCliente();
5254
new FacturaProveedor();
5355
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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

Comments
 (0)