AddressMetadataManagementTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\Metadata;
  7. use Magento\Customer\Api\AddressMetadataManagementInterface;
  8. use Magento\Customer\Model\Attribute;
  9. use Magento\Customer\Api\Data\AttributeMetadataInterface;
  10. use Magento\Customer\Model\Metadata\AddressMetadataManagement;
  11. class AddressMetadataManagementTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /** @var AddressMetadataManagement */
  14. protected $model;
  15. /** @var \Magento\Customer\Model\Metadata\AttributeResolver|\PHPUnit_Framework_MockObject_MockObject */
  16. protected $attributeResolverMock;
  17. protected function setUp()
  18. {
  19. $this->attributeResolverMock = $this->getMockBuilder(\Magento\Customer\Model\Metadata\AttributeResolver::class)
  20. ->disableOriginalConstructor()
  21. ->getMock();
  22. $this->model = new AddressMetadataManagement(
  23. $this->attributeResolverMock
  24. );
  25. }
  26. public function testCanBeSearchableInGrid()
  27. {
  28. /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMock */
  29. $attributeMock = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
  30. ->getMockForAbstractClass();
  31. /** @var Attribute|\PHPUnit_Framework_MockObject_MockObject $modelMock */
  32. $modelMock = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class)
  33. ->disableOriginalConstructor()
  34. ->getMock();
  35. $this->attributeResolverMock->expects($this->once())
  36. ->method('getModelByAttribute')
  37. ->with(AddressMetadataManagementInterface::ENTITY_TYPE_ADDRESS, $attributeMock)
  38. ->willReturn($modelMock);
  39. $modelMock->expects($this->once())
  40. ->method('canBeSearchableInGrid')
  41. ->willReturn(true);
  42. $this->assertTrue($this->model->canBeSearchableInGrid($attributeMock));
  43. }
  44. public function testCanBeFilterableInGrid()
  45. {
  46. /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMock */
  47. $attributeMock = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
  48. ->getMockForAbstractClass();
  49. /** @var Attribute|\PHPUnit_Framework_MockObject_MockObject $modelMock */
  50. $modelMock = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class)
  51. ->disableOriginalConstructor()
  52. ->getMock();
  53. $this->attributeResolverMock->expects($this->once())
  54. ->method('getModelByAttribute')
  55. ->with(AddressMetadataManagementInterface::ENTITY_TYPE_ADDRESS, $attributeMock)
  56. ->willReturn($modelMock);
  57. $modelMock->expects($this->once())
  58. ->method('canBeFilterableInGrid')
  59. ->willReturn(true);
  60. $this->assertTrue($this->model->canBeFilterableInGrid($attributeMock));
  61. }
  62. }