|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class JsonapiTest extends \LocalWebTestCase |
|
5
|
|
|
{ |
|
6
|
|
|
public function testOptionsAction() |
|
7
|
|
|
{ |
|
8
|
|
|
$response = $this->call( 'OPTIONS', '/unittest/jsonapi/' ); |
|
9
|
|
|
$json = json_decode( (string) $response->getBody(), true ); |
|
10
|
|
|
|
|
11
|
|
|
$this->assertNotNull( $json ); |
|
12
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
|
13
|
|
|
$this->assertArrayHasKey( 'resources', $json['meta'] ); |
|
14
|
|
|
$this->assertGreaterThan( 1, count( $json['meta']['resources'] ) ); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
public function testGetAction() |
|
19
|
|
|
{ |
|
20
|
|
|
$getParams = ['filter' => ['f_search' => 'Cafe Noire Cap']]; |
|
21
|
|
|
$response = $this->call( 'GET', '/unittest/jsonapi/product', $getParams ); |
|
22
|
|
|
$json = json_decode( $response->getBody(), true ); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertNotNull( $json ); |
|
25
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
|
26
|
|
|
$this->assertEquals( 2, $json['meta']['total'] ); |
|
27
|
|
|
$this->assertEquals( 2, count( $json['data'] ) ); |
|
28
|
|
|
$this->assertArrayHasKey( 'id', $json['data'][0] ); |
|
29
|
|
|
$this->assertEquals( 'CNC', $json['data'][0]['attributes']['product.code'] ); |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
$response = $this->call( 'GET', '/unittest/jsonapi/product', ['id' => $json['data'][0]['id']] ); |
|
33
|
|
|
$json = json_decode( $response->getBody(), true ); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertNotNull( $json ); |
|
36
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
|
37
|
|
|
$this->assertEquals( 1, $json['meta']['total'] ); |
|
38
|
|
|
$this->assertArrayHasKey( 'id', $json['data'] ); |
|
39
|
|
|
$this->assertEquals( 'CNC', $json['data']['attributes']['product.code'] ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
public function testPostPatchDeleteAction() |
|
44
|
|
|
{ |
|
45
|
|
|
// get CNC product |
|
46
|
|
|
$params = ['filter' => ['f_search' => 'Cafe Noire Cap', 'f_listtype' => 'unittype19']]; |
|
47
|
|
|
$response = $this->call( 'GET', '/unittest/jsonapi/product', $params ); |
|
48
|
|
|
$json = json_decode( $response->getBody(), true ); |
|
49
|
|
|
$this->assertEquals( 'CNC', $json['data'][0]['attributes']['product.code'] ); |
|
50
|
|
|
|
|
51
|
|
|
// add CNC product to basket |
|
52
|
|
|
$params = ['id' => 'default', 'related' => 'product']; |
|
53
|
|
|
$content = json_encode( ['data' => ['attributes' => ['product.id' => $json['data'][0]['id']]]] ); |
|
54
|
|
|
$response = $this->call( 'POST', '/unittest/jsonapi/basket', $params, $content ); |
|
55
|
|
|
$json = json_decode( $response->getBody(), true ); |
|
56
|
|
|
$this->assertEquals( 'CNC', $json['included'][0]['attributes']['order.base.product.prodcode'] ); |
|
57
|
|
|
|
|
58
|
|
|
// change product quantity in basket |
|
59
|
|
|
$content = json_encode( ['data' => ['attributes' => ['quantity' => 2]]] ); |
|
60
|
|
|
$response = $this->call( 'PATCH', '/unittest/jsonapi/basket', $params + ['relatedid' => 0], $content ); |
|
61
|
|
|
$json = json_decode( $response->getBody(), true ); |
|
62
|
|
|
$this->assertEquals( 2, $json['included'][0]['attributes']['order.base.product.quantity'] ); |
|
63
|
|
|
|
|
64
|
|
|
// delete product from basket |
|
65
|
|
|
$response = $this->call( 'DELETE', '/unittest/jsonapi/basket', $params + ['relatedid' => 0] ); |
|
66
|
|
|
$json = json_decode( $response->getBody(), true ); |
|
67
|
|
|
$this->assertEquals( 0, count( $json['included'] ) ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
public function testPutAction() |
|
72
|
|
|
{ |
|
73
|
|
|
$response = $this->call( 'PUT', '/unittest/jsonapi/basket' ); |
|
74
|
|
|
$json = json_decode( $response->getBody(), true ); |
|
75
|
|
|
$this->assertArrayHasKey( 'errors', $json ); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|