1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of FacturaScripts |
4
|
|
|
* Copyright (C) 2017-2021 Carlos Garcia Gomez <[email protected]> |
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\Core\Lib; |
21
|
|
|
|
22
|
|
|
use FacturaScripts\Core\Lib\CodePatterns; |
23
|
|
|
use FacturaScripts\Core\Model\PedidoCliente; |
24
|
|
|
use FacturaScripts\Core\Model\Producto; |
25
|
|
|
use PHPUnit\Framework\TestCase; |
26
|
|
|
|
27
|
|
|
final class CodePatternsTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
public function testDefault() |
30
|
|
|
{ |
31
|
|
|
$order = new PedidoCliente(); |
32
|
|
|
$order->codejercicio = '2021'; |
33
|
|
|
$order->codserie = 'A'; |
34
|
|
|
$order->numero = '1'; |
35
|
|
|
|
36
|
|
|
$code = CodePatterns::trans('PED{EJE}{SERIE}{NUM}', $order); |
37
|
|
|
$this->assertEquals('PED2021A1', $code, 'different-code'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testZeroNum() |
41
|
|
|
{ |
42
|
|
|
$order = new PedidoCliente(); |
43
|
|
|
$order->codejercicio = '2021'; |
44
|
|
|
$order->codserie = 'A'; |
45
|
|
|
$order->numero = '22'; |
46
|
|
|
|
47
|
|
|
$code = CodePatterns::trans('PED{EJE}{SERIE}{0NUM}', $order, ['long' => 6]); |
48
|
|
|
$this->assertEquals('PED2021A000022', $code, 'different-code'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testEje2() |
52
|
|
|
{ |
53
|
|
|
$order = new PedidoCliente(); |
54
|
|
|
$order->codejercicio = '2022'; |
55
|
|
|
$order->codserie = 'A'; |
56
|
|
|
$order->numero = '555'; |
57
|
|
|
|
58
|
|
|
$code = CodePatterns::trans('PED{EJE2}{SERIE}{0NUM}', $order, ['long' => 6]); |
59
|
|
|
$this->assertEquals('PED22A000555', $code, 'different-code'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testZeroSerie() |
63
|
|
|
{ |
64
|
|
|
$order = new PedidoCliente(); |
65
|
|
|
$order->codejercicio = '2022'; |
66
|
|
|
$order->codserie = 'C'; |
67
|
|
|
$order->numero = '9999'; |
68
|
|
|
|
69
|
|
|
$code = CodePatterns::trans('{EJE2}{0SERIE}{0NUM}', $order, ['long' => 6]); |
70
|
|
|
$this->assertEquals('220C009999', $code, 'different-code'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testAnyoMesDiaNum() |
74
|
|
|
{ |
75
|
|
|
$order = new PedidoCliente(); |
76
|
|
|
$order->codejercicio = '2022'; |
77
|
|
|
$order->codserie = 'C'; |
78
|
|
|
$order->fecha = '23-11-2021'; |
79
|
|
|
$order->numero = '777'; |
80
|
|
|
|
81
|
|
|
$code = CodePatterns::trans('{ANYO}-{MES}-{DIA}-{NUM}', $order); |
82
|
|
|
$this->assertEquals('2021-11-23-777', $code, 'different-code'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testNombreMesNum() |
86
|
|
|
{ |
87
|
|
|
$order = new PedidoCliente(); |
88
|
|
|
$order->codejercicio = '2020'; |
89
|
|
|
$order->codserie = 'A'; |
90
|
|
|
$order->fecha = '23-03-2021'; |
91
|
|
|
$order->numero = '123'; |
92
|
|
|
|
93
|
|
|
$code = CodePatterns::trans('{SERIE}-{NOMBREMES}-{NUM}', $order); |
94
|
|
|
$this->assertEquals('A-Marzo-123', $code, 'different-code'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testDateNum() |
98
|
|
|
{ |
99
|
|
|
$order = new PedidoCliente(); |
100
|
|
|
$order->codejercicio = '2020'; |
101
|
|
|
$order->codserie = 'A'; |
102
|
|
|
$order->fecha = '02-03-2021'; |
103
|
|
|
$order->hora = '11:22:33'; |
104
|
|
|
$order->numero = '87'; |
105
|
|
|
|
106
|
|
|
$code = CodePatterns::trans('{SERIE}{NUM}-{FECHA}-{HORA}', $order); |
107
|
|
|
$this->assertEquals('A87-02-03-2021-11:22:33', $code, 'different-code'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testDateTimeNum() |
111
|
|
|
{ |
112
|
|
|
$order = new PedidoCliente(); |
113
|
|
|
$order->codejercicio = '2020'; |
114
|
|
|
$order->codserie = 'Z'; |
115
|
|
|
$order->fecha = '07-07-2020'; |
116
|
|
|
$order->hora = '15:16:17'; |
117
|
|
|
$order->numero = '88'; |
118
|
|
|
|
119
|
|
|
$code = CodePatterns::trans('{SERIE}{NUM}-{FECHAHORA}', $order); |
120
|
|
|
$this->assertEquals('Z88-07-07-2020 15:16:17', $code, 'different-code'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testFilters() |
124
|
|
|
{ |
125
|
|
|
$order = new PedidoCliente(); |
126
|
|
|
$order->codejercicio = '2020'; |
127
|
|
|
$order->codserie = 'Z'; |
128
|
|
|
$order->numero = '63'; |
129
|
|
|
|
130
|
|
|
$code1 = CodePatterns::trans('pEd{EJE}{SERIE}{NUM}ccc|M', $order); |
131
|
|
|
$this->assertEquals('PED2020Z63CCC', $code1, 'upper-fail'); |
132
|
|
|
|
133
|
|
|
$code2 = CodePatterns::trans('pEd{EJE}{SERIE}{NUM}ccc|m', $order); |
134
|
|
|
$this->assertEquals('ped2020z63ccc', $code2, 'lower-fail'); |
135
|
|
|
|
136
|
|
|
$code3 = CodePatterns::trans('pEd{EJE}{SERIE}{NUM}ccc|P', $order); |
137
|
|
|
$this->assertEquals('PEd2020Z63ccc', $code3, 'uc-first-fail'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function testNoBusinessDoc() |
141
|
|
|
{ |
142
|
|
|
$product = new Producto(); |
143
|
|
|
$product->actualizado = '03-04-2021 11:33:55'; |
144
|
|
|
$product->codfamilia = 'J'; |
145
|
|
|
$product->referencia = '999'; |
146
|
|
|
|
147
|
|
|
$code = CodePatterns::trans('{SERIE}{NUM}-{FECHA}', $product, [ |
148
|
|
|
'fecha' => 'actualizado', |
149
|
|
|
'numero' => 'referencia', |
150
|
|
|
'serie' => 'codfamilia' |
151
|
|
|
]); |
152
|
|
|
$this->assertEquals('J999-03-04-2021', $code, 'different-code'); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|