Completed
Push — master ( 98e6c7...18f4ad )
by Aimeos
14:21
created

JsonapiControllerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testOptionsAction() 0 13 1
B testGetAction() 0 32 1
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