CustomerGroupConfigTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Model;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. class CustomerGroupConfigTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var ObjectManagerHelper
  12. */
  13. private $objectManagerHelper;
  14. /**
  15. * @var \Magento\Customer\Model\CustomerGroupConfig
  16. */
  17. private $customerGroupConfig;
  18. /**
  19. * @var \Magento\Config\Model\Config|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $configMock;
  22. /**
  23. * @var \Magento\Customer\Api\GroupRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $groupRepositoryMock;
  26. /**
  27. * Set up.
  28. *
  29. * @return void
  30. */
  31. public function setUp()
  32. {
  33. $this->configMock = $this->getMockBuilder(\Magento\Config\Model\Config::class)
  34. ->disableOriginalConstructor()
  35. ->getMock();
  36. $this->groupRepositoryMock = $this->getMockBuilder(\Magento\Customer\Api\GroupRepositoryInterface::class)
  37. ->disableOriginalConstructor()
  38. ->getMock();
  39. $this->objectManagerHelper = new ObjectManagerHelper($this);
  40. $this->customerGroupConfig = $this->objectManagerHelper->getObject(
  41. \Magento\Customer\Model\CustomerGroupConfig::class,
  42. [
  43. 'config' => $this->configMock,
  44. 'groupRepository' => $this->groupRepositoryMock
  45. ]
  46. );
  47. }
  48. /**
  49. * @return void
  50. */
  51. public function testSetDefaultCustomerGroup()
  52. {
  53. $customerGroupId = 1;
  54. $customerGroupMock = $this->getMockBuilder(\Magento\Customer\Api\Data\GroupInterface::class)
  55. ->disableOriginalConstructor()
  56. ->getMock();
  57. $this->groupRepositoryMock->expects($this->once())->method('getById')->willReturn($customerGroupMock);
  58. $this->configMock->expects($this->once())->method('setDataByPath')
  59. ->with(\Magento\Customer\Model\GroupManagement::XML_PATH_DEFAULT_ID, $customerGroupId)->willReturnSelf();
  60. $this->configMock->expects($this->once())->method('save');
  61. $this->assertEquals($customerGroupId, $this->customerGroupConfig->setDefaultCustomerGroup($customerGroupId));
  62. }
  63. }