RegisterLinkTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\Account;
  7. use Magento\Customer\Model\Context;
  8. /**
  9. * Test class for \Magento\Customer\Block\Account\RegisterLink
  10. */
  11. class RegisterLinkTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  15. */
  16. protected $_objectManager;
  17. protected function setUp()
  18. {
  19. $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  20. }
  21. /**
  22. * @param bool $isAuthenticated
  23. * @param bool $isRegistrationAllowed
  24. * @param bool $result
  25. * @dataProvider dataProviderToHtml
  26. * @return void
  27. */
  28. public function testToHtml($isAuthenticated, $isRegistrationAllowed, $result)
  29. {
  30. $context = $this->_objectManager->getObject(\Magento\Framework\View\Element\Template\Context::class);
  31. $httpContext = $this->getMockBuilder(\Magento\Framework\App\Http\Context::class)
  32. ->disableOriginalConstructor()
  33. ->setMethods(['getValue'])
  34. ->getMock();
  35. $httpContext->expects($this->any())
  36. ->method('getValue')
  37. ->with(Context::CONTEXT_AUTH)
  38. ->will($this->returnValue($isAuthenticated));
  39. $registrationMock = $this->getMockBuilder(\Magento\Customer\Model\Registration::class)
  40. ->disableOriginalConstructor()
  41. ->setMethods(['isAllowed'])
  42. ->getMock();
  43. $registrationMock->expects($this->any())
  44. ->method('isAllowed')
  45. ->will($this->returnValue($isRegistrationAllowed));
  46. /** @var \Magento\Customer\Block\Account\RegisterLink $link */
  47. $link = $this->_objectManager->getObject(
  48. \Magento\Customer\Block\Account\RegisterLink::class,
  49. [
  50. 'context' => $context,
  51. 'httpContext' => $httpContext,
  52. 'registration' => $registrationMock,
  53. ]
  54. );
  55. $this->assertEquals($result, $link->toHtml() === '');
  56. }
  57. /**
  58. * @return array
  59. */
  60. public function dataProviderToHtml()
  61. {
  62. return [
  63. [true, true, true],
  64. [false, false, true],
  65. [true, false, true],
  66. [false, true, false],
  67. ];
  68. }
  69. public function testGetHref()
  70. {
  71. $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  72. $helper = $this->getMockBuilder(
  73. \Magento\Customer\Model\Url::class
  74. )->disableOriginalConstructor()->setMethods(
  75. ['getRegisterUrl']
  76. )->getMock();
  77. $helper->expects($this->any())->method('getRegisterUrl')->will($this->returnValue('register url'));
  78. $context = $this->_objectManager->getObject(\Magento\Framework\View\Element\Template\Context::class);
  79. $block = $this->_objectManager->getObject(
  80. \Magento\Customer\Block\Account\RegisterLink::class,
  81. ['context' => $context, 'customerUrl' => $helper]
  82. );
  83. $this->assertEquals('register url', $block->getHref());
  84. }
  85. }