StandardTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 76
dl 0
loc 127
c 0
b 0
f 0
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetAggregate() 0 23 1
A testGetIncluded() 0 25 1
A testGetAggregateMultiple() 0 25 1
A testGetFieldsIncluded() 0 27 1
A setUp() 0 8 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\Order;
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\Order\Standard( $this->context, 'order' );
25
		$this->object->setAimeos( \TestHelper::getAimeos() );
26
		$this->object->setView( $this->view );
27
	}
28
29
30
	public function testGetAggregate()
31
	{
32
		$params = array(
33
			'filter' => array(
34
				'==' => array( 'order.editor' => 'core' )
35
			),
36
			'aggregate' => 'order.cdate',
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( 'aggregate', $result['data'][0]['type'] );
50
		$this->assertGreaterThan( 0, $result['data'][0]['attributes'] );
51
52
		$this->assertArrayNotHasKey( 'errors', $result );
53
	}
54
55
56
	public function testGetAggregateMultiple()
57
	{
58
		$params = array(
59
			'filter' => array(
60
				'==' => array( 'order.editor' => 'core' )
61
			),
62
			'aggregate' => 'order.statuspayment,order.cdate',
63
		);
64
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params );
65
		$this->view->addHelper( 'param', $helper );
66
67
		$response = $this->object->get( $this->view->request(), $this->view->response() );
68
		$result = json_decode( (string) $response->getBody(), true );
69
70
		$this->assertEquals( 200, $response->getStatusCode() );
71
		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
72
73
		$this->assertEquals( 2, $result['meta']['total'] );
74
		$this->assertEquals( 2, count( $result['data'] ) );
75
		$this->assertEquals( 'aggregate', $result['data'][0]['type'] );
76
		$this->assertEquals( 1, count( $result['data'][0]['attributes'] ) );
77
		$this->assertEquals( 'aggregate', $result['data'][1]['type'] );
78
		$this->assertEquals( 1, count( $result['data'][1]['attributes'] ) );
79
80
		$this->assertArrayNotHasKey( 'errors', $result );
81
	}
82
83
84
	public function testGetIncluded()
85
	{
86
		$params = array(
87
			'filter' => array(
88
				'==' => array( 'order.datepayment' => '2008-02-15 12:34:56' )
89
			),
90
			'include' => 'order,order/status,order/address,order/product,order/service,order/coupon,order/product/attribute,order/service/attribute'
91
		);
92
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params );
93
		$this->view->addHelper( 'param', $helper );
94
95
		$response = $this->object->get( $this->view->request(), $this->view->response() );
96
		$result = json_decode( (string) $response->getBody(), true );
97
98
		$this->assertEquals( 200, $response->getStatusCode() );
99
		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
100
101
		$this->assertEquals( 1, $result['meta']['total'] );
102
		$this->assertEquals( 1, count( $result['data'] ) );
103
		$this->assertEquals( 'order', $result['data'][0]['type'] );
104
		$this->assertEquals( 1, count( $result['data'][0]['relationships']['order/status'] ) );
105
		$this->assertEquals( 1, count( $result['data'][0]['relationships']['order'] ) );
106
		$this->assertGreaterThanOrEqual( 31, count( $result['included'] ) );
107
108
		$this->assertArrayNotHasKey( 'errors', $result );
109
	}
110
111
112
	public function testGetFieldsIncluded()
113
	{
114
		$params = array(
115
			'fields' => array(
116
				'order' => 'order.id,order.channel'
117
			),
118
			'sort' => 'order.id',
119
			'include' => 'order/status'
120
		);
121
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params );
122
		$this->view->addHelper( 'param', $helper );
123
124
		$response = $this->object->get( $this->view->request(), $this->view->response() );
125
		$result = json_decode( (string) $response->getBody(), true );
126
127
128
		$this->assertEquals( 200, $response->getStatusCode() );
129
		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
130
131
		$this->assertGreaterThanOrEqual( 4, $result['meta']['total'] );
132
		$this->assertGreaterThanOrEqual( 4, count( $result['data'] ) );
133
		$this->assertEquals( 'order', $result['data'][0]['type'] );
134
		$this->assertEquals( 2, count( $result['data'][0]['attributes'] ) );
135
		$this->assertGreaterThanOrEqual( 1, count( $result['data'][0]['relationships']['order/status'] ) );
136
		$this->assertGreaterThanOrEqual( 3, count( $result['included'] ) );
137
138
		$this->assertArrayNotHasKey( 'errors', $result );
139
	}
140
}
141