1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Client\JsonApi\Cms; |
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 = \TestHelperJapi::getContext(); |
22
|
|
|
$this->context->getLocale()->setLanguageId( 'en' ); |
23
|
|
|
$this->view = $this->context->getView(); |
24
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\Client\JsonApi\Cms\Standard( $this->context, 'cms' ); |
26
|
|
|
$this->object->setView( $this->view ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
public function testGetItem() |
31
|
|
|
{ |
32
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
33
|
|
|
$pageId = $manager->find( '/contact' )->getId(); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$params = array( |
36
|
|
|
'id' => $pageId, |
37
|
|
|
'fields' => array( |
38
|
|
|
'cms' => 'cms.id,cms.label' |
39
|
|
|
), |
40
|
|
|
'sort' => 'cms.id', |
41
|
|
|
'include' => 'text' |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
45
|
|
|
$this->view->addHelper( 'param', $helper ); |
46
|
|
|
|
47
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
48
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
49
|
|
|
|
50
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
51
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
52
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
53
|
|
|
|
54
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
55
|
|
|
$this->assertEquals( 'cms', $result['data']['type'] ); |
56
|
|
|
$this->assertEquals( 3, count( $result['data']['relationships']['text']['data'] ) ); |
57
|
|
|
$this->assertEquals( 3, count( $result['included'] ) ); |
58
|
|
|
|
59
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function testGetItems() |
64
|
|
|
{ |
65
|
|
|
$params = array( |
66
|
|
|
'filter' => array( |
67
|
|
|
'=~' => array( 'cms.url' => '/cont' ), |
68
|
|
|
), |
69
|
|
|
'fields' => array( |
70
|
|
|
'cms' => 'cms.id,cms.label,cms.url' |
71
|
|
|
), |
72
|
|
|
'include' => 'text', |
73
|
|
|
'sort' => 'cms.label,-cms.id', |
74
|
|
|
); |
75
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
76
|
|
|
$this->view->addHelper( 'param', $helper ); |
77
|
|
|
|
78
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
79
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
80
|
|
|
|
81
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
82
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
83
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
84
|
|
|
|
85
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
86
|
|
|
$this->assertEquals( 1, count( $result['data'] ) ); |
87
|
|
|
$this->assertEquals( 'cms', $result['data'][0]['type'] ); |
88
|
|
|
$this->assertEquals( 3, count( $result['data'][0]['attributes'] ) ); |
89
|
|
|
$this->assertEquals( 3, count( $result['included'] ) ); |
90
|
|
|
|
91
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
public function testGetItemsCriteria() |
96
|
|
|
{ |
97
|
|
|
$params = array( |
98
|
|
|
'filter' => array( |
99
|
|
|
'=~' => array( 'cms.url' => '/contact' ), |
100
|
|
|
), |
101
|
|
|
'sort' => 'cms.label', |
102
|
|
|
); |
103
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
104
|
|
|
$this->view->addHelper( 'param', $helper ); |
105
|
|
|
|
106
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
107
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
111
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
112
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
public function testGetMShopException() |
117
|
|
|
{ |
118
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\JsonApi\Cms\Standard::class ) |
119
|
|
|
->setConstructorArgs( [$this->context, 'cms'] ) |
120
|
|
|
->setMethods( ['getItems'] ) |
121
|
|
|
->getMock(); |
122
|
|
|
|
123
|
|
|
$object->expects( $this->once() )->method( 'getItems' ) |
124
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
125
|
|
|
|
126
|
|
|
$object->setView( $this->view ); |
127
|
|
|
|
128
|
|
|
$response = $object->get( $this->view->request(), $this->view->response() ); |
129
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
$this->assertEquals( 404, $response->getStatusCode() ); |
133
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testGetException() |
138
|
|
|
{ |
139
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\JsonApi\Cms\Standard::class ) |
140
|
|
|
->setConstructorArgs( [$this->context, 'cms'] ) |
141
|
|
|
->setMethods( ['getItems'] ) |
142
|
|
|
->getMock(); |
143
|
|
|
|
144
|
|
|
$object->expects( $this->once() )->method( 'getItems' ) |
145
|
|
|
->will( $this->throwException( new \Exception() ) ); |
146
|
|
|
|
147
|
|
|
$object->setView( $this->view ); |
148
|
|
|
|
149
|
|
|
$response = $object->get( $this->view->request(), $this->view->response() ); |
150
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
$this->assertEquals( 500, $response->getStatusCode() ); |
154
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testOptions() |
159
|
|
|
{ |
160
|
|
|
$response = $this->object->options( $this->view->request(), $this->view->response() ); |
161
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
162
|
|
|
|
163
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
164
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
165
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
166
|
|
|
|
167
|
|
|
$this->assertEquals( null, $result['meta']['prefix'] ); |
168
|
|
|
$this->assertArrayNotHasKey( 'attributes', $result['meta'] ); |
169
|
|
|
$this->assertArrayNotHasKey( 'filter', $result['meta'] ); |
170
|
|
|
$this->assertArrayNotHasKey( 'sort', $result['meta'] ); |
171
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths