UnlockButtonTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Block\Adminhtml\Edit;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. /**
  9. * Class UnlockButtonTest
  10. * @package Magento\Customer\Block\Adminhtml\Edit
  11. */
  12. class UnlockButtonTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Customer\Model\CustomerRegistry
  16. */
  17. protected $customerRegistryMock;
  18. /**
  19. * @var \Magento\Backend\Block\Widget\Context
  20. */
  21. protected $contextMock;
  22. /**
  23. * @var \Magento\Customer\Model\Customer
  24. */
  25. protected $customerModelMock;
  26. /**
  27. * Url Builder
  28. *
  29. * @var \Magento\Framework\UrlInterface
  30. */
  31. protected $urlBuilderMock;
  32. /**
  33. * @var \Magento\Framework\Registry
  34. */
  35. protected $registryMock;
  36. /**
  37. * @var \Magento\Customer\Block\Adminhtml\Edit\UnlockButton
  38. */
  39. protected $block;
  40. protected function setUp()
  41. {
  42. $this->contextMock = $this->createMock(\Magento\Backend\Block\Widget\Context::class);
  43. $this->customerRegistryMock = $this->createPartialMock(
  44. \Magento\Customer\Model\CustomerRegistry::class,
  45. ['retrieve']
  46. );
  47. $this->customerModelMock = $this->createMock(\Magento\Customer\Model\Customer::class);
  48. $this->registryMock = $this->createPartialMock(\Magento\Framework\Registry::class, ['registry']);
  49. $this->urlBuilderMock = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
  50. ->setMethods(['getUrl'])
  51. ->disableOriginalConstructor()
  52. ->getMockForAbstractClass();
  53. $this->contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilderMock);
  54. $objectManagerHelper = new ObjectManagerHelper($this);
  55. $this->block = $objectManagerHelper->getObject(
  56. \Magento\Customer\Block\Adminhtml\Edit\UnlockButton::class,
  57. [
  58. 'context' => $this->contextMock,
  59. 'customerRegistry' => $this->customerRegistryMock,
  60. 'urlBuilder' => $this->urlBuilderMock,
  61. 'registry' => $this->registryMock
  62. ]
  63. );
  64. }
  65. /**
  66. * @param array $result
  67. * @param bool $expectedValue
  68. * @dataProvider getButtonDataProvider
  69. */
  70. public function testGetButtonData($result, $expectedValue)
  71. {
  72. $this->registryMock->expects($this->any())->method('registry')->willReturn(1);
  73. $this->customerRegistryMock->expects($this->once())->method('retrieve')->willReturn($this->customerModelMock);
  74. $this->customerModelMock->expects($this->once())->method('isCustomerLocked')->willReturn($expectedValue);
  75. $this->urlBuilderMock->expects($this->any())->method('getUrl')->willReturn('http://website.com/');
  76. $this->assertEquals($result, $this->block->getButtonData());
  77. }
  78. /**
  79. * @return array
  80. */
  81. public function getButtonDataProvider()
  82. {
  83. return [
  84. [
  85. 'result' => [
  86. 'label' => new \Magento\Framework\Phrase('Unlock'),
  87. 'class' => 'unlock unlock-customer',
  88. 'on_click' => "location.href = 'http://website.com/';",
  89. 'sort_order' => 50,
  90. ],
  91. 'expectedValue' => 'true'
  92. ],
  93. ['result' => [], 'expectedValue' => false]
  94. ];
  95. }
  96. }