Issues (43)

Functional/Controller/JsonadmControllerTest.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Aimeos\Shop\Tests\Functional\Controller;
4
5
6
class JsonadmControllerTest extends \Neos\Flow\Tests\FunctionalTestCase
0 ignored issues
show
The type Neos\Flow\Tests\FunctionalTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
{
8
	public function testOptionsAction()
9
	{
10
		$response = $this->browser->request( 'http://localhost/unittest/jsonadm/product', '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
		$response = $this->browser->request( 'http://localhost/unittest/jsonadm', 'OPTIONS' );
20
		$json = json_decode( $response->getContent(), true );
21
22
		$this->assertNotNull( $json );
23
		$this->assertEquals( 200, $response->getStatusCode() );
24
		$this->assertArrayHasKey( 'resources', $json['meta'] );
25
		$this->assertGreaterThan( 1, count( $json['meta']['resources'] ) );
26
	}
27
28
29
	public function testActionsSingle()
30
	{
31
		$content = '{"data":{"type":"stock/type","attributes":{"stock.type.code":"flow","stock.type.label":"flow"}}}';
32
		$response = $this->browser->request( 'http://localhost/unittest/jsonadm/stock%2Ftype', 'POST', [], [], [], $content );
33
		$json = json_decode( $response->getContent(), true );
34
35
		$this->assertNotNull( $json );
36
		$this->assertEquals( 201, $response->getStatusCode() );
37
		$this->assertArrayHasKey( 'stock.type.id', $json['data']['attributes'] );
38
		$this->assertEquals( 'flow', $json['data']['attributes']['stock.type.code'] );
39
		$this->assertEquals( 'flow', $json['data']['attributes']['stock.type.label'] );
40
		$this->assertEquals( 1, $json['meta']['total'] );
41
42
		$id = $json['data']['attributes']['stock.type.id'];
43
44
45
		$content = '{"data":{"type":"stock/type","attributes":{"stock.type.code":"flow2","stock.type.label":"flow2"}}}';
46
		$response = $this->browser->request( 'http://localhost/unittest/jsonadm/stock%2Ftype', 'PATCH', ['id' => $id], [], [], $content );
47
		$json = json_decode( $response->getContent(), true );
48
49
		$this->assertNotNull( $json );
50
		$this->assertEquals( 200, $response->getStatusCode() );
51
		$this->assertArrayHasKey( 'stock.type.id', $json['data']['attributes'] );
52
		$this->assertEquals( 'flow2', $json['data']['attributes']['stock.type.code'] );
53
		$this->assertEquals( 'flow2', $json['data']['attributes']['stock.type.label'] );
54
		$this->assertEquals( $id, $json['data']['attributes']['stock.type.id'] );
55
		$this->assertEquals( 1, $json['meta']['total'] );
56
57
58
		$response = $this->browser->request( 'http://localhost/unittest/jsonadm/stock%2Ftype', 'GET', ['id' => $id] );
59
		$json = json_decode( $response->getContent(), true );
60
61
		$this->assertNotNull( $json );
62
		$this->assertEquals( 200, $response->getStatusCode() );
63
		$this->assertArrayHasKey( 'stock.type.id', $json['data']['attributes'] );
64
		$this->assertEquals( 'flow2', $json['data']['attributes']['stock.type.code'] );
65
		$this->assertEquals( 'flow2', $json['data']['attributes']['stock.type.label'] );
66
		$this->assertEquals( $id, $json['data']['attributes']['stock.type.id'] );
67
		$this->assertEquals( 1, $json['meta']['total'] );
68
69
70
		$response = $this->browser->request( 'http://localhost/unittest/jsonadm/stock%2Ftype', 'DELETE', ['id' => $id] );
71
		$json = json_decode( $response->getContent(), true );
72
73
		$this->assertNotNull( $json );
74
		$this->assertEquals( 200, $response->getStatusCode() );
75
		$this->assertEquals( 1, $json['meta']['total'] );
76
	}
77
78
79
	public function testActionsBulk()
80
	{
81
		$content = '{"data":[
82
			{"type":"stock/type","attributes":{"stock.type.code":"flow","stock.type.label":"flow"}},
83
			{"type":"stock/type","attributes":{"stock.type.code":"flow2","stock.type.label":"flow"}}
84
		]}';
85
		$response = $this->browser->request( 'http://localhost/unittest/jsonadm/stock%2Ftype', 'POST', [], [], [], $content );
86
		$json = json_decode( $response->getContent(), true );
87
88
		$this->assertNotNull( $json );
89
		$this->assertEquals( 201, $response->getStatusCode() );
90
		$this->assertEquals( 2, count( $json['data'] ) );
91
		$this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] );
92
		$this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] );
93
		$this->assertEquals( 'flow', $json['data'][0]['attributes']['stock.type.label'] );
94
		$this->assertEquals( 'flow', $json['data'][1]['attributes']['stock.type.label'] );
95
		$this->assertEquals( 2, $json['meta']['total'] );
96
97
		$ids = array( $json['data'][0]['attributes']['stock.type.id'], $json['data'][1]['attributes']['stock.type.id'] );
98
99
100
		$content = '{"data":[
101
			{"type":"stock/type","id":' . $ids[0] . ',"attributes":{"stock.type.label":"flow2"}},
102
			{"type":"stock/type","id":' . $ids[1] . ',"attributes":{"stock.type.label":"flow2"}}
103
		]}';
104
		$response = $this->browser->request( 'http://localhost/unittest/jsonadm/stock%2Ftype', 'PATCH', [], [], [], $content );
105
		$json = json_decode( $response->getContent(), true );
106
107
		$this->assertNotNull( $json );
108
		$this->assertEquals( 200, $response->getStatusCode() );
109
		$this->assertEquals( 2, count( $json['data'] ) );
110
		$this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] );
111
		$this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] );
112
		$this->assertEquals( 'flow2', $json['data'][0]['attributes']['stock.type.label'] );
113
		$this->assertEquals( 'flow2', $json['data'][1]['attributes']['stock.type.label'] );
114
		$this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) );
115
		$this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) );
116
		$this->assertEquals( 2, $json['meta']['total'] );
117
118
119
		$getParams = array( 'filter' => array( '&&' => array(
120
			array( '=~' => array( 'stock.type.code' => 'flow' ) ),
121
			array( '==' => array( 'stock.type.label' => 'flow2' ) )
122
			) ),
123
			'sort' => 'stock.type.code', 'page' => array( 'offset' => 0, 'limit' => 3 )
124
		);
125
		$response = $this->browser->request( 'http://localhost/unittest/jsonadm/stock%2Ftype', 'GET', $getParams );
126
		$json = json_decode( $response->getContent(), true );
127
128
		$this->assertNotNull( $json );
129
		$this->assertEquals( 200, $response->getStatusCode() );
130
		$this->assertEquals( 2, count( $json['data'] ) );
131
		$this->assertEquals( 'flow', $json['data'][0]['attributes']['stock.type.code'] );
132
		$this->assertEquals( 'flow2', $json['data'][1]['attributes']['stock.type.code'] );
133
		$this->assertEquals( 'flow2', $json['data'][0]['attributes']['stock.type.label'] );
134
		$this->assertEquals( 'flow2', $json['data'][1]['attributes']['stock.type.label'] );
135
		$this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) );
136
		$this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) );
137
		$this->assertEquals( 2, $json['meta']['total'] );
138
139
140
		$content = '{"data":[
141
			{"type":"stock/type","id":' . $ids[0] . '},
142
			{"type":"stock/type","id":' . $ids[1] . '}
143
		]}';
144
		$response = $this->browser->request( 'http://localhost/unittest/jsonadm/stock%2Ftype', 'DELETE', [], [], [], $content );
145
		$json = json_decode( $response->getContent(), true );
146
147
		$this->assertNotNull( $json );
148
		$this->assertEquals( 200, $response->getStatusCode() );
149
		$this->assertEquals( 2, $json['meta']['total'] );
150
	}
151
}
152