DocumentTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Ui\Component\DataProvider;
  7. use Magento\Customer\Api\Data\GroupInterface;
  8. use Magento\Customer\Api\GroupRepositoryInterface;
  9. use Magento\Framework\Api\AttributeValue;
  10. use Magento\Framework\Api\AttributeValueFactory;
  11. use Magento\Sales\Model\Order\Invoice;
  12. use Magento\Sales\Ui\Component\DataProvider\Document;
  13. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  14. /**
  15. * Class DocumentTest
  16. */
  17. class DocumentTest extends \PHPUnit\Framework\TestCase
  18. {
  19. /**
  20. * @var GroupRepositoryInterface|MockObject
  21. */
  22. private $groupRepository;
  23. /**
  24. * @var AttributeValueFactory|MockObject
  25. */
  26. private $attributeValueFactory;
  27. /**
  28. * @var Document
  29. */
  30. private $document;
  31. protected function setUp()
  32. {
  33. $this->initAttributeValueFactoryMock();
  34. $this->groupRepository = $this->getMockForAbstractClass(GroupRepositoryInterface::class);
  35. $this->document = new Document($this->attributeValueFactory, $this->groupRepository);
  36. }
  37. /**
  38. * @covers \Magento\Sales\Ui\Component\DataProvider\Document::getCustomAttribute
  39. */
  40. public function testGetStateAttribute()
  41. {
  42. $this->document->setData('state', Invoice::STATE_PAID);
  43. $this->groupRepository->expects(static::never())
  44. ->method('getById');
  45. $attribute = $this->document->getCustomAttribute('state');
  46. static::assertEquals('Paid', $attribute->getValue());
  47. }
  48. /**
  49. * @covers \Magento\Sales\Ui\Component\DataProvider\Document::getCustomAttribute
  50. */
  51. public function testGetCustomerGroupAttribute()
  52. {
  53. $this->document->setData('customer_group_id', 1);
  54. $group = $this->getMockForAbstractClass(GroupInterface::class);
  55. $this->groupRepository->expects(static::once())
  56. ->method('getById')
  57. ->willReturn($group);
  58. $group->expects(static::once())
  59. ->method('getCode')
  60. ->willReturn('General');
  61. $attribute = $this->document->getCustomAttribute('customer_group_id');
  62. static::assertEquals('General', $attribute->getValue());
  63. }
  64. /**
  65. * Create mock for attribute value factory
  66. * @return void
  67. */
  68. private function initAttributeValueFactoryMock()
  69. {
  70. $this->attributeValueFactory = $this->getMockBuilder(AttributeValueFactory::class)
  71. ->disableOriginalConstructor()
  72. ->setMethods(['create'])
  73. ->getMock();
  74. $attributeValue = new AttributeValue();
  75. $this->attributeValueFactory->expects(static::once())
  76. ->method('create')
  77. ->willReturn($attributeValue);
  78. }
  79. }