StandardTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testGetFieldsIncluded() 0 25 1
A testGetIncluded() 0 31 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2025
6
 */
7
8
9
namespace Aimeos\Admin\JsonAdm\Product;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $view;
17
18
19
	protected function setUp() : void
20
	{
21
		$this->context = \TestHelper::context();
22
		$this->view = $this->context->view();
23
24
		$this->object = new \Aimeos\Admin\JsonAdm\Product\Standard( $this->context, 'product' );
25
		$this->object->setAimeos( \TestHelper::getAimeos() );
26
		$this->object->setView( $this->view );
27
	}
28
29
30
	public function testGetIncluded()
31
	{
32
		$params = array(
33
			'filter' => array(
34
				'==' => array( 'product.code' => 'CNE' )
35
			),
36
			'include' => 'text,product,product/property'
37
		);
38
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params );
39
		$this->view->addHelper( 'param', $helper );
40
41
		$response = $this->object->get( $this->view->request(), $this->view->response() );
42
		$result = json_decode( (string) $response->getBody(), true );
43
44
		$this->assertEquals( 200, $response->getStatusCode() );
45
		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
46
47
		$this->assertEquals( 1, $result['meta']['total'] );
48
		$this->assertEquals( 1, count( $result['data'] ) );
49
		$this->assertEquals( 'product', $result['data'][0]['type'] );
50
		$this->assertEquals( 7, count( $result['data'][0]['relationships']['text']['data'] ) );
51
		$this->assertArrayHaskey( 'self', $result['data'][0]['relationships']['text']['data'][0]['links'] );
52
		$this->assertEquals( 2, count( $result['data'][0]['relationships']['product']['data'] ) );
53
		$this->assertArrayHaskey( 'self', $result['data'][0]['relationships']['product']['data'][0]['links'] );
54
		$this->assertEquals( 4, count( $result['data'][0]['relationships']['product/property']['data'] ) );
55
		$this->assertEquals( 12, count( $result['included'] ) );
56
		$this->assertEquals( 'product/property', $result['included'][0]['type'] );
57
		$this->assertArrayHaskey( 'self', $result['included'][0]['links'] );
58
		$this->assertArrayHaskey( 'related', $result['included'][0]['links'] );
59
60
		$this->assertArrayNotHasKey( 'errors', $result );
61
	}
62
63
64
	public function testGetFieldsIncluded()
65
	{
66
		$params = array(
67
			'fields' => array(
68
				'product' => 'product.id,product.code,product.label'
69
			),
70
			'sort' => 'product.code',
71
			'include' => 'product,product/property'
72
		);
73
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params );
74
		$this->view->addHelper( 'param', $helper );
75
76
		$response = $this->object->get( $this->view->request(), $this->view->response() );
77
		$result = json_decode( (string) $response->getBody(), true );
78
79
		$this->assertEquals( 200, $response->getStatusCode() );
80
		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
81
82
		$this->assertEquals( 28, $result['meta']['total'] );
83
		$this->assertEquals( 25, count( $result['data'] ) );
84
		$this->assertEquals( 'product', $result['data'][5]['type'] );
85
		$this->assertEquals( 3, count( $result['data'][5]['attributes'] ) );
86
		$this->assertGreaterThanOrEqual( 18, count( $result['included'] ) );
87
88
		$this->assertArrayNotHasKey( 'errors', $result );
89
	}
90
}
91