CustomerMetadataManagementTest.php 2.8 KB

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