GroupTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Customer\Test\Unit\Model\Config\Source;
  8. use Magento\Customer\Api\GroupManagementInterface;
  9. use Magento\Customer\Model\Config\Source\Group;
  10. use Magento\Customer\Model\Customer\Attribute\Source\GroupSourceLoggedInOnlyInterface;
  11. use Magento\Framework\Convert\DataObject;
  12. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  13. class GroupTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var GroupSourceLoggedInOnlyInterface|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. private $groupSource;
  19. /**
  20. * @var Group
  21. */
  22. protected $model;
  23. /**
  24. * @var \PHPUnit_Framework_MockObject_MockObject
  25. */
  26. protected $groupServiceMock;
  27. /**
  28. * @var \PHPUnit_Framework_MockObject_MockObject
  29. */
  30. protected $converterMock;
  31. protected function setUp()
  32. {
  33. $this->groupServiceMock = $this->createMock(GroupManagementInterface::class);
  34. $this->converterMock = $this->createMock(DataObject::class);
  35. $this->groupSource = $this->getMockBuilder(GroupSourceLoggedInOnlyInterface::class)
  36. ->getMockForAbstractClass();
  37. $this->model = (new ObjectManager($this))->getObject(
  38. Group::class,
  39. [
  40. 'groupManagement' => $this->groupServiceMock,
  41. 'converter' => $this->converterMock,
  42. 'groupSourceForLoggedInCustomers' => $this->groupSource,
  43. ]
  44. );
  45. }
  46. public function testToOptionArray()
  47. {
  48. $expectedValue = ['General', 'Retail'];
  49. $this->groupServiceMock->expects($this->never())->method('getLoggedInGroups');
  50. $this->converterMock->expects($this->never())->method('toOptionArray');
  51. $this->groupSource->expects($this->once())
  52. ->method('toOptionArray')
  53. ->willReturn($expectedValue);
  54. array_unshift($expectedValue, ['value' => '', 'label' => __('-- Please Select --')]);
  55. $this->assertEquals($expectedValue, $this->model->toOptionArray());
  56. }
  57. }