Completed
Push — test ( c38ed8 )
by Aimeos
10:42
created

JsonapiControllerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

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