Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
JsonGenerationFromDataObjectTest Class Reference
Inheritance diagram for JsonGenerationFromDataObjectTest:
WebapiAbstract

Public Member Functions

 testMultiServiceRetrieval ()
 
 testSingleServiceRetrieval ()
 
 testInvalidRestUrlNoServices ()
 
 testInvalidRestUrlInvalidServiceName ()
 
 checkActualData ($expected, $actual)
 
 getExpectedCommonData ()
 
 getExpectedMultiServiceData ()
 
 getExpectedSingleServiceData ()
 
- Public Member Functions inherited from WebapiAbstract
 addModelToDelete ($model, $secure=false)
 
 processRestExceptionResult (\Exception $e)
 

Protected Member Functions

 setUp ()
 
- Protected Member Functions inherited from WebapiAbstract
 tearDown ()
 
 _webApiCall ( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
 
 _markTestAsSoapOnly ($message=null)
 
 _markTestAsRestOnly ($message=null)
 
 _getWebApiAdapter ($webApiAdapterCode)
 
 _assertMessagesEqual ($expectedMessages, $receivedMessages)
 
 _cleanAppConfigCache ()
 
 _restoreAppConfig ()
 
 checkSoapFault ( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)
 
 _checkFaultParams ($expectedErrorParams, $errorDetails)
 
 _checkWrappedErrors ($expectedWrappedErrors, $errorDetails)
 

Protected Attributes

 $baseUrl = TESTS_BASE_URL
 
 $storeCode
 
 $isSingleService
 
 $productMetadata
 
- Protected Attributes inherited from WebapiAbstract
 $_appCache
 
 $_modelsToDelete = []
 
 $_origConfigValues = []
 
 $_webApiAdapters
 
 $_webApiAdaptersMap
 

Additional Inherited Members

- Static Public Member Functions inherited from WebapiAbstract
static setUpBeforeClass ()
 
static tearDownAfterClass ()
 
static setFixture ($key, $fixture, $tearDown=self::AUTO_TEAR_DOWN_AFTER_METHOD)
 
static getFixture ($key)
 
static callModelDelete ($model, $secure=false)
 
static deleteFixture ($key, $secure=false)
 
- Data Fields inherited from WebapiAbstract
const AUTO_TEAR_DOWN_DISABLED = 0
 
const AUTO_TEAR_DOWN_AFTER_METHOD = 1
 
const AUTO_TEAR_DOWN_AFTER_CLASS = 2
 
const ADAPTER_SOAP = 'soap'
 
const ADAPTER_REST = 'rest'
 
- Static Protected Member Functions inherited from WebapiAbstract
static _setFixtureNamespace ()
 
static _unsetFixtureNamespace ()
 
static _getFixtureNamespace ()
 
static _deleteFixtures ($fixtures)
 
- Static Protected Attributes inherited from WebapiAbstract
static $_fixturesNamespace
 
static $_fixtures = []
 
static $_methodLevelFixtures = []
 
static $_classLevelFixtures = []
 

Detailed Description

Test REST schema generation mechanisms.

Definition at line 16 of file JsonGenerationFromDataObjectTest.php.

Member Function Documentation

◆ checkActualData()

checkActualData (   $expected,
  $actual 
)

Definition at line 132 of file JsonGenerationFromDataObjectTest.php.

133  {
134  $this->assertRecursiveArray($expected, $actual, true);
135  }

◆ getExpectedCommonData()

getExpectedCommonData ( )

Definition at line 137 of file JsonGenerationFromDataObjectTest.php.

138  {
139  $versionParts = explode('.', $this->productMetadata->getVersion());
140  if (!isset($versionParts[0]) || !isset($versionParts[1])) {
141  return []; // Major and minor version are not set - return empty response
142  }
143  $majorMinorVersion = $versionParts[0] . '.' . $versionParts[1];
144  $url = str_replace('://', '', strstr($this->baseUrl, '://'));
145  $host = strpos($url, '/') ? strstr($url, '/', true) : $url;
146  $basePath = strstr(rtrim($url, '/'), '/');
147  $basePath = $basePath ? trim($basePath, '/') . '/' : '';
148  $basePath = '/' . $basePath . 'rest/' . $this->storeCode;
149  return [
150  'swagger' => '2.0',
151  'info' => [
152  'version' => $majorMinorVersion,
153  'title' => $this->productMetadata->getName() . ' ' .$this->productMetadata->getEdition(),
154  ],
155  'host' => $host,
156  'basePath' => $basePath,
157  ];
158  }

◆ getExpectedMultiServiceData()

getExpectedMultiServiceData ( )
Returns
array @SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 164 of file JsonGenerationFromDataObjectTest.php.

165  {
166  $expected = [
167  'tags' => [
168  [
169  'name' => 'testModule5AllSoapAndRestV1',
170  'description' => 'Both SOAP and REST Version ONE',
171  ],
172  [
173  'name' => 'testModule5AllSoapAndRestV2',
174  'description' => 'Both SOAP and REST Version TWO',
175  ],
176  ],
177  'paths' => [
178  '/V1/TestModule5/{parentId}/nestedResource/{entityId}' => [
179  'put' => [
180  'tags' => [
181  'testModule5AllSoapAndRestV1',
182  ],
183  'description' => 'Update existing item.',
184  'operationId' => 'testModule5AllSoapAndRestV1NestedUpdatePut',
185  'parameters' => [
186  [
187  'name' => 'parentId',
188  'in' => 'path',
189  'type' => 'string',
190  'required' => true
191  ],
192  [
193  'name' => 'entityId',
194  'in' => 'path',
195  'type' => 'string',
196  'required' => true
197  ],
198  [
199  'name' => 'testModule5AllSoapAndRestV1NestedUpdatePutBody',
200  'in' => 'body',
201  'schema' => [
202  'required' => [
203  'entityItem',
204  ],
205  'properties' => [
206  'entityItem' => [
207  '$ref' => '#/definitions/test-module5-v1-entity-all-soap-and-rest',
208  ],
209  ],
210  'type' => 'object'
211  ],
212  ]
213  ],
214  'responses' => [
215  200 => [
216  'description' => '200 Success.',
217  'schema' => [
218  '$ref' => '#/definitions/test-module5-v1-entity-all-soap-and-rest',
219  ],
220  ],
221  401 => [
222  'description' => '401 Unauthorized',
223  'schema' => [
224  '$ref' => '#/definitions/error-response',
225  ],
226  ],
227  'default' => [
228  'description' => 'Unexpected error',
229  'schema' => [
230  '$ref' => '#/definitions/error-response',
231  ],
232  ],
233  ],
234  ],
235  ],
236  ],
237  'definitions' => [
238  'framework-attribute-interface' => [
239  'type' => 'object',
240  'description' => 'Interface for custom attribute value.',
241  'properties' => [
242  'attribute_code' => [
243  'type' => 'string',
244  'description' => 'Attribute code',
245  ],
246  'value' => [
247  'type' => 'string',
248  'description' => 'Attribute value',
249  ],
250  ],
251  'required' => [
252  'attribute_code',
253  'value',
254  ],
255  ],
256  'test-module5-v1-entity-all-soap-and-rest' => [
257  'type' => 'object',
258  'description' => 'Some Data Object short description. Data Object long multi line description.',
259  'properties' => [
260  'entity_id' => [
261  'type' => 'integer',
262  'description' => 'Item ID',
263  ],
264  'name' => [
265  'type' => 'string',
266  'description' => 'Item name',
267  ],
268  'enabled' => [
269  'type' => 'boolean',
270  'description' => 'If entity is enabled',
271  ],
272  'orders' => [
273  'type' => 'boolean',
274  'description' => 'If current entity has a property defined',
275  ],
276  'custom_attributes' => [
277  'type' => 'array',
278  'description' => 'Custom attributes values.',
279  'items' => [
280  '$ref' => '#/definitions/framework-attribute-interface',
281  ],
282  ],
283  ],
284  'required' => [
285  'entity_id',
286  'enabled',
287  'orders',
288  ],
289  ],
290  ],
291  ];
292  return array_merge_recursive($expected, $this->getExpectedCommonData());
293  }

◆ getExpectedSingleServiceData()

getExpectedSingleServiceData ( )
Returns
array @SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 299 of file JsonGenerationFromDataObjectTest.php.

300  {
301  $expected = [
302  'tags' => [
303  [
304  'name' => 'testModule5AllSoapAndRestV2',
305  'description' => 'Both SOAP and REST Version TWO',
306  ],
307  ],
308  'paths' => [
309  '/V2/TestModule5/{id}' => [
310  'delete' => [
311  'tags' => [
312  'testModule5AllSoapAndRestV2',
313  ],
314  'description' => 'Delete existing item.',
315  'operationId' => 'testModule5AllSoapAndRestV2DeleteDelete',
316  'parameters' => [
317  [
318  'name' => 'id',
319  'in' => 'path',
320  'type' => 'string',
321  'required' => true
322  ],
323  ],
324  'responses' => [
325  200 => [
326  'description' => '200 Success.',
327  'schema' => [
328  '$ref' => '#/definitions/test-module5-v2-entity-all-soap-and-rest',
329  ],
330  ],
331  401 => [
332  'description' => '401 Unauthorized',
333  'schema' => [
334  '$ref' => '#/definitions/error-response',
335  ],
336  ],
337  'default' => [
338  'description' => 'Unexpected error',
339  'schema' => [
340  '$ref' => '#/definitions/error-response',
341  ],
342  ],
343  ],
344  ],
345  ],
346  ],
347  'definitions' => [
348  'test-module5-v2-entity-all-soap-and-rest' => [
349  'type' => 'object',
350  'description' => 'Some Data Object short description. Data Object long multi line description.',
351  'properties' => [
352  'price' => [
353  'type' => 'integer',
354  ],
355  ],
356  'required' => [
357  'price',
358  ],
359  ],
360  ],
361  ];
362  return array_merge($expected, $this->getExpectedCommonData());
363  }

◆ setUp()

setUp ( )
protected

Definition at line 32 of file JsonGenerationFromDataObjectTest.php.

33  {
34  $this->_markTestAsRestOnly("JSON generation tests are intended to be executed for REST adapter only.");
35 
36  $this->storeCode = Bootstrap::getObjectManager()->get(StoreManagerInterface::class)
37  ->getStore()->getCode();
38 
39  $this->productMetadata = Bootstrap::getObjectManager()->get(ProductMetadataInterface::class);
40 
41  parent::setUp();
42  }

◆ testInvalidRestUrlInvalidServiceName()

testInvalidRestUrlInvalidServiceName ( )

@expectedException \Exception @expectedExceptionMessage Incorrect format of request URI or Requested services are missing.

Definition at line 101 of file JsonGenerationFromDataObjectTest.php.

102  {
103  $this->isSingleService = false;
104 
105  $resourcePath = '/schema?services=invalidServiceName';
106 
107  $serviceInfo = [
108  'rest' => [
109  'resourcePath' => $resourcePath,
111  ],
112  ];
113 
114  $this->_webApiCall($serviceInfo);
115  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testInvalidRestUrlNoServices()

testInvalidRestUrlNoServices ( )

@expectedException \Exception @expectedExceptionMessage Specified request cannot be processed.

Definition at line 83 of file JsonGenerationFromDataObjectTest.php.

84  {
85  $resourcePath = '';
86 
87  $serviceInfo = [
88  'rest' => [
89  'resourcePath' => $resourcePath,
91  ],
92  ];
93 
94  $this->_webApiCall($serviceInfo);
95  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testMultiServiceRetrieval()

testMultiServiceRetrieval ( )

Definition at line 44 of file JsonGenerationFromDataObjectTest.php.

45  {
46  $this->isSingleService = false;
47 
48  $resourcePath = '/schema?services=testModule5AllSoapAndRestV1,testModule5AllSoapAndRestV2';
49 
50  $serviceInfo = [
51  'rest' => [
52  'resourcePath' => $resourcePath,
54  ],
55  ];
56 
57  $schemaContent = $this->_webApiCall($serviceInfo);
58  $this->checkActualData($this->getExpectedMultiServiceData(), $schemaContent);
59  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testSingleServiceRetrieval()

testSingleServiceRetrieval ( )

Definition at line 61 of file JsonGenerationFromDataObjectTest.php.

62  {
63  $this->isSingleService = false;
64 
65  $resourcePath = '/schema?services=testModule5AllSoapAndRestV2';
66 
67  $serviceInfo = [
68  'rest' => [
69  'resourcePath' => $resourcePath,
71  ],
72  ];
73 
74  $schemaContent = $this->_webApiCall($serviceInfo);
75 
76  $this->checkActualData($this->getExpectedSingleServiceData(), $schemaContent);
77  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

Field Documentation

◆ $baseUrl

$baseUrl = TESTS_BASE_URL
protected

Definition at line 19 of file JsonGenerationFromDataObjectTest.php.

◆ $isSingleService

$isSingleService
protected

Definition at line 25 of file JsonGenerationFromDataObjectTest.php.

◆ $productMetadata

$productMetadata
protected

Definition at line 30 of file JsonGenerationFromDataObjectTest.php.

◆ $storeCode

$storeCode
protected

Definition at line 22 of file JsonGenerationFromDataObjectTest.php.


The documentation for this class was generated from the following file: