NoWebApiXmlTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Webapi\Routing;
  7. /**
  8. * Class to test routing with a service that has no webapi.xml
  9. */
  10. class NoWebApiXmlTest extends \Magento\Webapi\Routing\BaseService
  11. {
  12. /**
  13. * @var string
  14. */
  15. private $_version;
  16. /**
  17. * @var string
  18. */
  19. private $_restResourcePath;
  20. protected function setUp()
  21. {
  22. $this->_version = 'V1';
  23. $this->_restResourcePath = "/{$this->_version}/testModule2NoWebApiXml/";
  24. }
  25. /**
  26. * Test get item
  27. */
  28. public function testItem()
  29. {
  30. $this->_markTestAsRestOnly();
  31. $itemId = 1;
  32. $serviceInfo = [
  33. 'rest' => [
  34. 'resourcePath' => $this->_restResourcePath . $itemId,
  35. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
  36. ],
  37. ];
  38. $requestData = ['id' => $itemId];
  39. $this->_assertNoRestRouteException($serviceInfo, $requestData);
  40. }
  41. /**
  42. * Test fetching all items
  43. */
  44. public function testItems()
  45. {
  46. $this->_markTestAsRestOnly();
  47. $serviceInfo = [
  48. 'rest' => [
  49. 'resourcePath' => $this->_restResourcePath,
  50. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET
  51. ],
  52. ];
  53. $this->_assertNoRestRouteException($serviceInfo);
  54. }
  55. /**
  56. * Test create item
  57. */
  58. public function testCreate()
  59. {
  60. $this->_markTestAsRestOnly();
  61. $createdItemName = 'createdItemName';
  62. $serviceInfo = [
  63. 'rest' => [
  64. 'resourcePath' => $this->_restResourcePath,
  65. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST
  66. ],
  67. ];
  68. $requestData = ['name' => $createdItemName];
  69. $this->_assertNoRestRouteException($serviceInfo, $requestData);
  70. }
  71. /**
  72. * Test update item
  73. */
  74. public function testUpdate()
  75. {
  76. $this->_markTestAsRestOnly();
  77. $itemId = 1;
  78. $serviceInfo = [
  79. 'rest' => [
  80. 'resourcePath' => $this->_restResourcePath . $itemId,
  81. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
  82. ],
  83. ];
  84. $requestData = ['id' => $itemId];
  85. $this->_assertNoRestRouteException($serviceInfo, $requestData);
  86. }
  87. /**
  88. * Test remove item
  89. */
  90. public function testRemove()
  91. {
  92. $this->_markTestAsRestOnly();
  93. $itemId = 1;
  94. $serviceInfo = [
  95. 'rest' => [
  96. 'resourcePath' => $this->_restResourcePath . $itemId,
  97. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
  98. ],
  99. ];
  100. $requestData = ['id' => $itemId];
  101. $this->_assertNoRestRouteException($serviceInfo, $requestData);
  102. }
  103. }