1
|
|
|
<?php |
2
|
|
|
namespace VatNumberCheck\Test\TestCase\Controller; |
3
|
|
|
|
4
|
|
|
use Cake\TestSuite\IntegrationTestTrait; |
5
|
|
|
use Cake\TestSuite\TestCase; |
6
|
|
|
use VatNumberCheck\Controller\VatNumberChecksController; |
7
|
|
|
use VatNumberCheck\Utility\VatNumberCheck; |
8
|
|
|
use VatNumberCheck\Test\TestApp; |
9
|
|
|
/** |
10
|
|
|
* VatNumberChecksController Test Case. |
11
|
|
|
* |
12
|
|
|
* @property \VatNumberCheck\Controller\VatNumberChecksController $VatNumberChecks |
13
|
|
|
*/ |
14
|
|
|
class VatNumberChecksControllerTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
use IntegrationTestTrait; |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Fixtures |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
public $fixtures = []; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* setUp method |
27
|
|
|
* |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
public function setUp() { |
31
|
|
|
$this->useHttpServer(true); |
32
|
|
|
$VatNumberChecks = new VatNumberCheck(); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
/** |
35
|
|
|
* Tests `/vat_number_check/vat_number_checks/check.json`. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function testCheck() { |
40
|
|
|
$url = '/vat_number_check/vat_number_checks/check.json'; |
41
|
|
|
// Post request, correct vat |
42
|
|
|
$data = ['vatNumber' => 'NL820345672B01']; |
43
|
|
|
|
44
|
|
|
$this->get('url'); |
45
|
|
|
$actual = $this->post($url, $data); |
|
|
|
|
46
|
|
|
$expected = array_merge($data, ['status' => 'ok']); |
|
|
|
|
47
|
|
|
// // Test response body |
48
|
|
|
// $this->assertSame($expected, json_decode($actual, true)); |
49
|
|
|
// $actual = $VatNumberChecks->response->statusCode(); |
50
|
|
|
// $expected = 200; |
51
|
|
|
// // Test response code |
52
|
|
|
// $this->assertSame($expected, $actual); |
53
|
|
|
// // Get request |
54
|
|
|
// $VatNumberChecks = $this->_getMock(); |
55
|
|
|
// $data = ['vatNumber' => '']; |
56
|
|
|
// $actual = $this->get($url, ['return' => 'contents']); |
57
|
|
|
// $expected = array_merge($data, ['status' => 'failure']); |
58
|
|
|
// $this->assertSame($expected, json_decode($actual, true)); |
59
|
|
|
// // Post request, incorrect vat |
60
|
|
|
// $VatNumberChecks = $this->_getMock(); |
61
|
|
|
// $data = ['vatNumber' => 'NL820345672B02']; |
62
|
|
|
// $actual = $this->get($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']); |
63
|
|
|
// $expected = array_merge($data, ['status' => 'failure']); |
64
|
|
|
// $this->assertSame($expected, json_decode($actual, true)); |
65
|
|
|
// // Post request, correct vat, timeout |
66
|
|
|
// $VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks', [ |
67
|
|
|
// 'models' => [ |
68
|
|
|
// 'VatNumberCheck.VatNumberCheck' => ['check'] |
69
|
|
|
// ] |
70
|
|
|
// ]); |
71
|
|
|
// $VatNumberChecks->VatNumberCheck->setDataSource('vatNumberCheckWebservice'); |
72
|
|
|
// $VatNumberChecks->VatNumberCheck->expects($this->any()) |
73
|
|
|
// ->method('check')->will($this->throwException(new Exception())); |
74
|
|
|
// $data = ['vatNumber' => 'NL820345672B01']; |
75
|
|
|
// $actual = $this->get($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']); |
76
|
|
|
// $expected = array_merge($data, ['status' => 'failure']); |
77
|
|
|
// // Test response body |
78
|
|
|
// $this->assertSame($expected, json_decode($actual, true)); |
79
|
|
|
// $actual = $VatNumberChecks->response->statusCode(); |
80
|
|
|
// $expected = 503; |
81
|
|
|
// // Test response code |
82
|
|
|
// $this->assertSame($expected, $actual); |
83
|
|
|
} |
84
|
|
|
} |