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