Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CoreRoutingTest.php
Go to the documentation of this file.
1 <?php
10 namespace Magento\Webapi\Routing;
11 
14 
16 {
17  public function testBasicRoutingExplicitPath()
18  {
19  $itemId = 1;
20  $serviceInfo = [
21  'rest' => [
22  'resourcePath' => '/V1/testmodule1/' . $itemId,
24  ],
25  'soap' => [
26  'service' => 'testModule1AllSoapAndRestV1',
27  'operation' => 'testModule1AllSoapAndRestV1Item',
28  ],
29  ];
30  $requestData = ['itemId' => $itemId];
31  $item = $this->_webApiCall($serviceInfo, $requestData);
32  $this->assertEquals('testProduct1', $item['name'], "Item was retrieved unsuccessfully");
33  }
34 
35  public function testDisabledIntegrationAuthorizationException()
36  {
37  $itemId = 1;
38  $serviceInfo = [
39  'rest' => [
40  'resourcePath' => '/V1/testmodule1/' . $itemId,
42  ],
43  'soap' => [
44  'service' => 'testModule1AllSoapAndRestV1',
45  'operation' => 'testModule1AllSoapAndRestV1Item',
46  ],
47  ];
48  $requestData = ['itemId' => $itemId];
49 
51  $credentials = \Magento\TestFramework\Authentication\OauthHelper::getApiAccessCredentials();
53  $integration = $credentials['integration'];
54  $originalStatus = $integration->getStatus();
55  $integration->setStatus(\Magento\Integration\Model\Integration::STATUS_INACTIVE)->save();
56 
57  try {
58  $this->assertUnauthorizedException($serviceInfo, $requestData);
59  } catch (\Exception $e) {
61  $integration->setStatus($originalStatus)->save();
62  throw $e;
63  }
64  $integration->setStatus($originalStatus)->save();
65  }
66 
68  {
69  $this->_markTestAsSoapOnly();
70  $serviceInfo = [
71  'soap' => [
72  'service' => 'testModule3ErrorV1',
73  'operation' => 'testModule3ErrorV1ServiceException',
74  ],
75  ];
76  $this->expectException('SoapFault');
77  $this->expectExceptionMessage('Generic service exception');
78  $this->_webApiCall($serviceInfo);
79  }
80 
81  public function testRestNoAcceptHeader()
82  {
83  $this->_markTestAsRestOnly();
85  $curlClient = Bootstrap::getObjectManager()->get(
86  \Magento\TestFramework\TestCase\Webapi\Adapter\Rest\RestClient::class
87  );
88  $response = $curlClient->get('/V1/testmodule1/resource1/1', [], ['Accept:']);
89  $this->assertEquals('testProduct1', $response['name'], "Empty Accept header failed to return response.");
90  }
91 }
$response
Definition: 404.php:11
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
assertUnauthorizedException($serviceInfo, $requestData=null)
Definition: BaseService.php:22