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 testPostAction() |
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
|
|
|
$params = ['related' => 'product']; |
57
|
|
|
$content = json_encode( ['data' => ['attributes' => ['product.id' => $json['data'][0]['id']]]] ); |
58
|
|
|
$response = $this->browser->request( 'http://localhost/unittest/jsonapi/basket/default', 'POST', $params, [], [], $content ); |
59
|
|
|
$json = json_decode( $response->getContent(), true ); |
60
|
|
|
$this->assertEquals( 'CNC', $json['included'][0]['attributes']['order.base.product.prodcode'] ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testPutAction() |
65
|
|
|
{ |
66
|
|
|
$response = $this->browser->request( 'http://localhost/unittest/jsonapi/basket', 'PUT' ); |
67
|
|
|
$json = json_decode( $response->getContent(), true ); |
68
|
|
|
$this->assertArrayHasKey( 'errors', $json ); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|