1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aimeos\ShopBundle\Tests\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class JsonapiControllerTest extends WebTestCase |
9
|
|
|
{ |
10
|
|
|
public function testOptionsAction() |
11
|
|
|
{ |
12
|
|
|
$client = static::createClient(); |
13
|
|
|
$client->request( 'OPTIONS', '/unittest/de/EUR/jsonapi' ); |
14
|
|
|
$response = $client->getResponse(); |
15
|
|
|
|
16
|
|
|
$json = json_decode( $response->getContent(), true ); |
17
|
|
|
|
18
|
|
|
$this->assertNotNull( $json ); |
19
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
20
|
|
|
$this->assertArrayHasKey( 'resources', $json['meta'] ); |
21
|
|
|
$this->assertGreaterThan( 1, count( $json['meta']['resources'] ) ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
public function testGetAction() |
26
|
|
|
{ |
27
|
|
|
$client = static::createClient(); |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
$params = ['filter' => ['f_search' => 'Cafe Noire Cap', 'f_listtype' => 'unittype19']]; |
31
|
|
|
$client->request( 'GET', '/unittest/de/EUR/jsonapi/product', $params ); |
32
|
|
|
$response = $client->getResponse(); |
33
|
|
|
|
34
|
|
|
$json = json_decode( $response->getContent(), true ); |
35
|
|
|
|
36
|
|
|
$this->assertNotNull( $json ); |
37
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
38
|
|
|
$this->assertEquals( 1, $json['meta']['total'] ); |
39
|
|
|
$this->assertEquals( 1, count( $json['data'] ) ); |
40
|
|
|
$this->assertArrayHasKey( 'id', $json['data'][0] ); |
41
|
|
|
$this->assertEquals( 'CNC', $json['data'][0]['attributes']['product.code'] ); |
42
|
|
|
|
43
|
|
|
$id = $json['data'][0]['id']; |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
$client->request( 'GET', '/unittest/de/EUR/jsonapi/product/' . $id ); |
47
|
|
|
$response = $client->getResponse(); |
48
|
|
|
|
49
|
|
|
$json = json_decode( $response->getContent(), true ); |
50
|
|
|
|
51
|
|
|
$this->assertNotNull( $json ); |
52
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
53
|
|
|
$this->assertEquals( 1, $json['meta']['total'] ); |
54
|
|
|
$this->assertArrayHasKey( 'id', $json['data'] ); |
55
|
|
|
$this->assertEquals( 'CNC', $json['data']['attributes']['product.code'] ); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|