|
1
|
|
|
<?php |
|
2
|
|
|
App::uses('VatNumberCheck', 'VatNumberCheck.Model'); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* VatNumberCheck Test Case |
|
6
|
|
|
* |
|
7
|
|
|
* @property VatNumberCheck.VatNumberCheck $VatNumberCheck |
|
8
|
|
|
*/ |
|
|
|
|
|
|
9
|
|
|
class VatNumberCheckTest extends CakeTestCase { |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Fixtures |
|
13
|
|
|
* |
|
14
|
|
|
* @var array |
|
15
|
|
|
*/ |
|
16
|
|
|
public $fixtures = []; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* setUp method |
|
20
|
|
|
* |
|
21
|
|
|
* @return void |
|
22
|
|
|
*/ |
|
23
|
|
|
public function setUp() { |
|
24
|
|
|
parent::setUp(); |
|
25
|
|
|
|
|
26
|
|
|
$this->VatNumberCheck = ClassRegistry::init('VatNumberCheck.VatNumberCheck', true); |
|
|
|
|
|
|
27
|
|
|
$this->VatNumberCheck->setDataSource('vatNumberCheckWebservice'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* tearDown method |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
|
|
public function tearDown() { |
|
36
|
|
|
unset($this->VatNumberCheck); |
|
37
|
|
|
|
|
38
|
|
|
parent::tearDown(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Tests `normalize`. |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $vatNumber |
|
45
|
|
|
* @param string $expected |
|
46
|
|
|
* @return void |
|
47
|
|
|
* @dataProvider normalizeProvider |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testNormalize(string $vatNumber, string $expected) { |
|
50
|
|
|
$actual = $this->VatNumberCheck->normalize($vatNumber); |
|
51
|
|
|
$this->assertSame($expected, $actual); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Data provider for `normalize`. |
|
56
|
|
|
* |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
public function normalizeProvider() : array { |
|
60
|
|
|
return [ |
|
61
|
|
|
// $vatNumber, $expected |
|
62
|
|
|
|
|
63
|
|
|
// Correct |
|
64
|
|
|
['NL820345672B01', 'NL820345672B01'], |
|
65
|
|
|
// To upper case |
|
66
|
|
|
['NL820345672b01', 'NL820345672B01'], |
|
67
|
|
|
// Removal of non-alphanumeric |
|
68
|
|
|
['NL820345672 B01', 'NL820345672B01'], |
|
69
|
|
|
['NL820345672!B01', 'NL820345672B01'], |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Tests `check`. |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $vatNumber |
|
77
|
|
|
* @param string $expected |
|
78
|
|
|
* @return void |
|
79
|
|
|
* @dataProvider checkProvider |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testCheck(string $vatNumber, bool $expected) { |
|
82
|
|
|
$actual = $this->VatNumberCheck->check($vatNumber); |
|
83
|
|
|
$this->assertSame($expected, $actual); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Data provider for `check`. |
|
88
|
|
|
* |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
public function checkProvider() : array { |
|
92
|
|
|
return [ |
|
93
|
|
|
// $vatNumber, $expected |
|
94
|
|
|
|
|
95
|
|
|
// Correct |
|
96
|
|
|
['NL820345672B01', true], |
|
97
|
|
|
['BE0475899519', true], |
|
98
|
|
|
// Incorrect vat |
|
99
|
|
|
['NL820345672B02', false], |
|
100
|
|
|
// Empty vat |
|
101
|
|
|
['', false], |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|