Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerMetadataManagementTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class CustomerMetadataManagementTest extends \PHPUnit\Framework\TestCase
13 {
15  protected $model;
16 
19 
20  protected function setUp()
21  {
22  $this->attributeResolverMock = $this->getMockBuilder(\Magento\Customer\Model\Metadata\AttributeResolver::class)
23  ->disableOriginalConstructor()
24  ->getMock();
25 
26  $this->model = new CustomerMetadataManagement(
27  $this->attributeResolverMock
28  );
29  }
30 
31  public function testCanBeSearchableInGrid()
32  {
34  $attributeMock = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
35  ->getMockForAbstractClass();
36 
38  $modelMock = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class)
39  ->disableOriginalConstructor()
40  ->getMock();
41 
42  $this->attributeResolverMock->expects($this->once())
43  ->method('getModelByAttribute')
45  ->willReturn($modelMock);
46 
47  $modelMock->expects($this->once())
48  ->method('canBeSearchableInGrid')
49  ->willReturn(true);
50 
51  $this->assertTrue($this->model->canBeSearchableInGrid($attributeMock));
52  }
53 
54  public function testCanBeFilterableInGrid()
55  {
57  $attributeMock = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
58  ->getMockForAbstractClass();
59 
61  $modelMock = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class)
62  ->disableOriginalConstructor()
63  ->getMock();
64 
65  $this->attributeResolverMock->expects($this->once())
66  ->method('getModelByAttribute')
68  ->willReturn($modelMock);
69 
70  $modelMock->expects($this->once())
71  ->method('canBeFilterableInGrid')
72  ->willReturn(true);
73 
74  $this->assertTrue($this->model->canBeFilterableInGrid($attributeMock));
75  }
76 }