ConfigurableProductManagementTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\ConfigurableProduct\Api;
  8. use Magento\TestFramework\Helper\Bootstrap;
  9. class ConfigurableProductManagementTest extends \Magento\TestFramework\TestCase\WebapiAbstract
  10. {
  11. const SERVICE_NAME = 'configurableProductConfigurableProductManagementV1';
  12. const SERVICE_VERSION = 'V1';
  13. const RESOURCE_PATH = '/V1/configurable-products/variation';
  14. /**
  15. * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_attribute.php
  16. */
  17. public function testGetVariation()
  18. {
  19. $serviceInfo = [
  20. 'rest' => [
  21. 'resourcePath' => self::RESOURCE_PATH,
  22. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT
  23. ],
  24. 'soap' => [
  25. 'service' => self::SERVICE_NAME,
  26. 'serviceVersion' => self::SERVICE_VERSION,
  27. 'operation' => self::SERVICE_NAME . 'GenerateVariation'
  28. ]
  29. ];
  30. /** @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository */
  31. $attributeRepository = Bootstrap::getObjectManager()->get(
  32. \Magento\Catalog\Api\ProductAttributeRepositoryInterface::class
  33. );
  34. $attribute = $attributeRepository->get('test_configurable');
  35. $attributeOptionValue = $attribute->getOptions()[1]->getValue();
  36. $data = [
  37. 'product' => [
  38. 'sku' => 'test',
  39. 'price' => 10
  40. ],
  41. 'options' => [
  42. [
  43. 'attribute_id' => 'test_configurable',
  44. 'values' => [
  45. [
  46. 'value_index' => $attributeOptionValue,
  47. ]
  48. ]
  49. ]
  50. ]
  51. ];
  52. $actual = $this->_webApiCall($serviceInfo, $data);
  53. $expectedItems = [
  54. [
  55. 'sku' => 'test-' . $attributeOptionValue,
  56. 'price' => 10,
  57. 'name' => '-' . $attributeOptionValue,
  58. 'status' => 1,
  59. 'visibility' => \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE,
  60. 'product_links' => [],
  61. 'custom_attributes' => [
  62. [
  63. 'attribute_code' => 'test_configurable',
  64. 'value' => $attributeOptionValue
  65. ]
  66. ],
  67. 'tier_prices' => []
  68. ]
  69. ];
  70. ksort($expectedItems);
  71. ksort($actual);
  72. $this->assertEquals($expectedItems, $actual);
  73. }
  74. }