ServiceMetadataTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Webapi\Model;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. use Magento\Customer\Api\AccountManagementInterface;
  9. use Magento\Framework\Exception\LocalizedException;
  10. class ServiceMetadataTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var ServiceMetadata
  14. */
  15. private $serviceMetadata;
  16. protected function setUp()
  17. {
  18. $objectManager = Bootstrap::getObjectManager();
  19. $this->serviceMetadata = $objectManager->create(ServiceMetadata::class);
  20. }
  21. public function testGetServiceMetadata()
  22. {
  23. $expected = [
  24. 'methods' => [
  25. 'activate' => [
  26. 'method' => 'activate',
  27. 'inputRequired' => false,
  28. 'isSecure' => false,
  29. 'resources' => [
  30. 'Magento_Customer::manage'
  31. ],
  32. 'documentation' => 'Activate a customer account using a key that was sent in a confirmation email.',
  33. 'interface' => [
  34. 'in' => [
  35. 'parameters' => [
  36. 'email' => [
  37. 'type' => 'string',
  38. 'required' => true,
  39. 'documentation' => null
  40. ],
  41. 'confirmationKey' => [
  42. 'type' => 'string',
  43. 'required' => true,
  44. 'documentation' => null
  45. ]
  46. ]
  47. ],
  48. 'out' => [
  49. 'parameters' => [
  50. 'result' => [
  51. 'type' => 'CustomerDataCustomerInterface',
  52. 'required' => true,
  53. 'documentation' => ''
  54. ]
  55. ],
  56. 'throws' => [
  57. '\\' . LocalizedException::class
  58. ]
  59. ]
  60. ]
  61. ]
  62. ],
  63. 'class' => AccountManagementInterface::class,
  64. 'description' => 'Interface for managing customers accounts.',
  65. ];
  66. $actual = $this->serviceMetadata->getServiceMetadata('customerAccountManagementV1');
  67. $this->assertEquals(array_replace_recursive($actual, $expected), $actual);
  68. }
  69. public function testGetRouteMetadata()
  70. {
  71. $expected = [
  72. 'methods' => [
  73. 'activate' => [
  74. 'method' => 'activate',
  75. 'inputRequired' => false,
  76. 'isSecure' => false,
  77. 'resources' => [
  78. 'Magento_Customer::manage'
  79. ],
  80. 'documentation' => 'Activate a customer account using a key that was sent in a confirmation email.',
  81. 'interface' => [
  82. 'in' => [
  83. 'parameters' => [
  84. 'email' => [
  85. 'type' => 'string',
  86. 'required' => true,
  87. 'documentation' => null
  88. ],
  89. 'confirmationKey' => [
  90. 'type' => 'string',
  91. 'required' => true,
  92. 'documentation' => null
  93. ]
  94. ]
  95. ],
  96. 'out' => [
  97. 'parameters' => [
  98. 'result' => [
  99. 'type' => 'CustomerDataCustomerInterface',
  100. 'required' => true,
  101. 'documentation' => ''
  102. ]
  103. ],
  104. 'throws' => [
  105. '\\' . LocalizedException::class
  106. ]
  107. ]
  108. ]
  109. ]
  110. ],
  111. 'class' => AccountManagementInterface::class,
  112. 'description' => 'Interface for managing customers accounts.',
  113. 'routes' => [
  114. '/V1/customers/me/activate' => [
  115. 'PUT' => [
  116. 'method' => 'activateById',
  117. 'parameters' => [
  118. 'customerId' => [
  119. 'force' => true,
  120. 'value' => '%customer_id%'
  121. ]
  122. ]
  123. ]
  124. ]
  125. ]
  126. ];
  127. $actual = $this->serviceMetadata->getRouteMetadata('customerAccountManagementV1');
  128. $this->assertEquals(array_replace_recursive($actual, $expected), $actual);
  129. }
  130. }