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

JsonapiControllerTest::testOptionsAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
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