Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UnlockButtonTest.php
Go to the documentation of this file.
1 <?php
7 
9 
14 class UnlockButtonTest extends \PHPUnit\Framework\TestCase
15 {
20 
24  protected $contextMock;
25 
29  protected $customerModelMock;
30 
36  protected $urlBuilderMock;
37 
41  protected $registryMock;
42 
46  protected $block;
47 
48  protected function setUp()
49  {
50  $this->contextMock = $this->createMock(\Magento\Backend\Block\Widget\Context::class);
51  $this->customerRegistryMock = $this->createPartialMock(
52  \Magento\Customer\Model\CustomerRegistry::class,
53  ['retrieve']
54  );
55  $this->customerModelMock = $this->createMock(\Magento\Customer\Model\Customer::class);
56  $this->registryMock = $this->createPartialMock(\Magento\Framework\Registry::class, ['registry']);
57 
58  $this->urlBuilderMock = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
59  ->setMethods(['getUrl'])
60  ->disableOriginalConstructor()
61  ->getMockForAbstractClass();
62  $this->contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilderMock);
63  $objectManagerHelper = new ObjectManagerHelper($this);
64 
65  $this->block = $objectManagerHelper->getObject(
66  \Magento\Customer\Block\Adminhtml\Edit\UnlockButton::class,
67  [
68  'context' => $this->contextMock,
69  'customerRegistry' => $this->customerRegistryMock,
70  'urlBuilder' => $this->urlBuilderMock,
71  'registry' => $this->registryMock
72  ]
73  );
74  }
75 
81  public function testGetButtonData($result, $expectedValue)
82  {
83  $this->registryMock->expects($this->any())->method('registry')->willReturn(1);
84  $this->customerRegistryMock->expects($this->once())->method('retrieve')->willReturn($this->customerModelMock);
85  $this->customerModelMock->expects($this->once())->method('isCustomerLocked')->willReturn($expectedValue);
86  $this->urlBuilderMock->expects($this->any())->method('getUrl')->willReturn('http://website.com/');
87 
88  $this->assertEquals($result, $this->block->getButtonData());
89  }
90 
94  public function getButtonDataProvider()
95  {
96  return [
97  [
98  'result' => [
99  'label' => new \Magento\Framework\Phrase('Unlock'),
100  'class' => 'unlock unlock-customer',
101  'on_click' => "location.href = 'http://website.com/';",
102  'sort_order' => 50,
103  ],
104  'expectedValue' => 'true'
105  ],
106  ['result' => [], 'expectedValue' => false]
107  ];
108  }
109 }