SubsetTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Class to test routing based on a Service that exposes subset of operations
  8. */
  9. namespace Magento\Webapi\Routing;
  10. class SubsetTest extends \Magento\Webapi\Routing\BaseService
  11. {
  12. /**
  13. * @var string
  14. */
  15. protected $_version;
  16. /**
  17. * @var string
  18. */
  19. protected $_restResourcePath;
  20. /**
  21. * @var string
  22. */
  23. protected $_soapService;
  24. /**
  25. * @Override
  26. */
  27. protected function setUp()
  28. {
  29. $this->_version = 'V1';
  30. $this->_restResourcePath = "/{$this->_version}/testModule2SubsetRest/";
  31. $this->_soapService = 'testModule2SubsetRestV1';
  32. }
  33. /**
  34. * @Override
  35. * Test get item
  36. */
  37. public function testItem()
  38. {
  39. $itemId = 1;
  40. $serviceInfo = [
  41. 'rest' => [
  42. 'resourcePath' => $this->_restResourcePath . $itemId,
  43. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
  44. ],
  45. 'soap' => ['service' => $this->_soapService, 'operation' => $this->_soapService . 'Item'],
  46. ];
  47. $requestData = ['id' => $itemId];
  48. $item = $this->_webApiCall($serviceInfo, $requestData);
  49. $this->assertEquals($itemId, $item['id'], 'Item was retrieved unsuccessfully');
  50. }
  51. /**
  52. * @Override
  53. * Test fetching all items
  54. */
  55. public function testItems()
  56. {
  57. $itemArr = [['id' => 1, 'name' => 'testItem1'], ['id' => 2, 'name' => 'testItem2']];
  58. $serviceInfo = [
  59. 'rest' => [
  60. 'resourcePath' => $this->_restResourcePath,
  61. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
  62. ],
  63. 'soap' => ['service' => $this->_soapService, 'operation' => $this->_soapService . 'Items'],
  64. ];
  65. $item = $this->_webApiCall($serviceInfo);
  66. $this->assertEquals($itemArr, $item, 'Items were not retrieved');
  67. }
  68. }