CustomerGroupConfigTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Api;
  7. use Magento\TestFramework\TestCase\WebapiAbstract;
  8. /**
  9. * Web API tests for CustomerGroupConfig model.
  10. */
  11. class CustomerGroupConfigTest extends WebapiAbstract
  12. {
  13. const SERVICE_NAME = "customerCustomerGroupConfigV1";
  14. const SERVICE_VERSION = "V1";
  15. const RESOURCE_PATH = "/V1/customerGroups";
  16. /**
  17. * @return void
  18. */
  19. public function testSetDefaultGroup()
  20. {
  21. $customerGroupId = 1;
  22. $serviceInfo = [
  23. 'rest' => [
  24. 'resourcePath' => self::RESOURCE_PATH . "/default/$customerGroupId",
  25. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
  26. ],
  27. 'soap' => [
  28. 'service' => self::SERVICE_NAME,
  29. 'serviceVersion' => self::SERVICE_VERSION,
  30. 'operation' => 'customerCustomerGroupConfigV1SetDefaultCustomerGroup',
  31. ],
  32. ];
  33. $requestData = ['id' => $customerGroupId];
  34. $groupData = $this->_webApiCall($serviceInfo, $requestData);
  35. $this->assertEquals($customerGroupId, $groupData, "The default group does not match.");
  36. }
  37. /**
  38. * Web API test for setDefaultGroup() method when there is no customer group exists with provided ID.
  39. *
  40. * @return void
  41. */
  42. public function testSetDefaultGroupNonExistingGroup()
  43. {
  44. $customerGroupId = 10000;
  45. $expectedMessage = 'No such entity with %fieldName = %fieldValue';
  46. $serviceInfo = [
  47. 'rest' => [
  48. 'resourcePath' => self::RESOURCE_PATH . "/default/$customerGroupId",
  49. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
  50. ],
  51. 'soap' => [
  52. 'service' => self::SERVICE_NAME,
  53. 'serviceVersion' => self::SERVICE_VERSION,
  54. 'operation' => 'customerCustomerGroupConfigV1SetDefaultCustomerGroup',
  55. ],
  56. ];
  57. $requestData = ['id' => $customerGroupId];
  58. try {
  59. $this->_webApiCall($serviceInfo, $requestData);
  60. $this->fail("Expected exception");
  61. } catch (\SoapFault $e) {
  62. $this->assertContains(
  63. $expectedMessage,
  64. $e->getMessage(),
  65. "SoapFault does not contain expected message."
  66. );
  67. } catch (\Exception $e) {
  68. $this->assertContains(
  69. $expectedMessage,
  70. $e->getMessage(),
  71. "Exception does not contain expected message."
  72. );
  73. $this->assertContains((string)$customerGroupId, $e->getMessage());
  74. }
  75. }
  76. }