Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PropertyLockerTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class PropertyLockerTest extends \PHPUnit\Framework\TestCase
11 {
13  protected $object;
14 
16  protected $attributeMock;
17 
19  protected $formMock;
20 
23 
24  protected function setUp()
25  {
26  $this->attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
27  ->setMethods(['getId'])
28  ->disableOriginalConstructor()
29  ->getMock();
30 
31  $registryMock = $this->getMockBuilder(\Magento\Framework\Registry::class)
32  ->setMethods(['registry'])
33  ->disableOriginalConstructor()
34  ->getMock();
35  $registryMock->expects($this->atLeastOnce())->method('registry')->willReturn($this->attributeMock);
36 
37  $this->attributeConfigMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Config::class)
38  ->setMethods(['getLockedFields'])
39  ->disableOriginalConstructor()
40  ->getMock();
41 
42  $this->formMock = $this->getMockBuilder(\Magento\Framework\Data\Form::class)
43  ->setMethods(['getElement'])
44  ->disableOriginalConstructor()
45  ->getMock();
46 
47  $this->object = new PropertyLocker($registryMock, $this->attributeConfigMock);
48  }
49 
53  public function testLock()
54  {
55  $lockedFields = [
56  'is_searchable' => 'is_searchable',
57  'is_filterable' => 'is_filterable'
58  ];
59  $this->attributeMock->expects($this->once())->method('getId')->willReturn(1);
60  $this->attributeConfigMock->expects($this->once())->method('getLockedFields')->willReturn($lockedFields);
61 
62  $elementMock = $this->getMockBuilder(\Magento\Framework\Data\Form\Element\AbstractElement::class)
63  ->setMethods(['setDisabled', 'setReadonly'])
64  ->disableOriginalConstructor()
65  ->getMockForAbstractClass();
66  $elementMock->expects($this->exactly(2))->method('setDisabled');
67  $elementMock->expects($this->exactly(2))->method('setReadonly');
68  $this->formMock->expects($this->exactly(2))->method('getElement')->willReturn($elementMock);
69  $this->object->lock($this->formMock);
70  }
71 }