|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Aimeos\Shop\Tests\Functional\Controller; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class JsonapiControllerTest extends \TYPO3\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
|
|
|
|