StandardTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
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 testGetIncluded() 0 26 1
A testGetFieldsIncluded() 0 30 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\Supplier;
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\Supplier\Standard( $this->context, 'supplier' );
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( 'supplier.code' => 'unitSupplier001' )
35
			),
36
			'include' => 'text,supplier/address'
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
45
		$this->assertEquals( 200, $response->getStatusCode() );
46
		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
47
48
		$this->assertEquals( 1, $result['meta']['total'] );
49
		$this->assertEquals( 1, count( $result['data'] ) );
50
		$this->assertEquals( 'supplier', $result['data'][0]['type'] );
51
		$this->assertEquals( 3, count( $result['data'][0]['relationships']['text']['data'] ) );
52
		$this->assertEquals( 1, count( $result['data'][0]['relationships']['supplier/address']['data'] ) );
53
		$this->assertEquals( 4, count( $result['included'] ) );
54
55
		$this->assertArrayNotHasKey( 'errors', $result );
56
	}
57
58
59
	public function testGetFieldsIncluded()
60
	{
61
		$params = array(
62
			'filter' => array(
63
				'=~' => array( 'supplier.code' => 'unitSupplier00' )
64
			),
65
			'fields' => array(
66
				'supplier' => 'supplier.id,supplier.label'
67
			),
68
			'sort' => 'supplier.id',
69
			'include' => 'supplier/address'
70
		);
71
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params );
72
		$this->view->addHelper( 'param', $helper );
73
74
		$response = $this->object->get( $this->view->request(), $this->view->response() );
75
		$result = json_decode( (string) $response->getBody(), true );
76
77
78
		$this->assertEquals( 200, $response->getStatusCode() );
79
		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
80
81
		$this->assertEquals( 3, $result['meta']['total'] );
82
		$this->assertEquals( 3, count( $result['data'] ) );
83
		$this->assertEquals( 'supplier', $result['data'][0]['type'] );
84
		$this->assertEquals( 2, count( $result['data'][0]['attributes'] ) );
85
		$this->assertEquals( 1, count( $result['data'][0]['relationships']['supplier/address'] ) );
86
		$this->assertEquals( 3, count( $result['included'] ) );
87
88
		$this->assertArrayNotHasKey( 'errors', $result );
89
	}
90
}
91