AuthorizationLinkTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /**
  8. * Test class for \Magento\Customer\Block\Account\AuthorizationLink
  9. */
  10. class AuthorizationLinkTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  14. */
  15. protected $_objectManager;
  16. /**
  17. * \Magento\Framework\App\Http\Context
  18. */
  19. protected $httpContext;
  20. /**
  21. * @var \Magento\Customer\Model\Url
  22. */
  23. protected $_customerUrl;
  24. /**
  25. * @var \Magento\Customer\Block\Account\AuthorizationLink
  26. */
  27. protected $_block;
  28. protected function setUp()
  29. {
  30. $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  31. $this->httpContext = $this->getMockBuilder(\Magento\Framework\App\Http\Context::class)
  32. ->disableOriginalConstructor()
  33. ->setMethods(['getValue'])
  34. ->getMock();
  35. $this->_customerUrl = $this->getMockBuilder(\Magento\Customer\Model\Url::class)
  36. ->disableOriginalConstructor()
  37. ->setMethods(['getLogoutUrl', 'getLoginUrl'])
  38. ->getMock();
  39. $context = $this->_objectManager->getObject(\Magento\Framework\View\Element\Template\Context::class);
  40. $this->_block = $this->_objectManager->getObject(
  41. \Magento\Customer\Block\Account\AuthorizationLink::class,
  42. [
  43. 'context' => $context,
  44. 'httpContext' => $this->httpContext,
  45. 'customerUrl' => $this->_customerUrl,
  46. ]
  47. );
  48. }
  49. public function testGetLabelLoggedIn()
  50. {
  51. $this->httpContext->expects($this->once())
  52. ->method('getValue')
  53. ->will($this->returnValue(true));
  54. $this->assertEquals('Sign Out', $this->_block->getLabel());
  55. }
  56. public function testGetLabelLoggedOut()
  57. {
  58. $this->httpContext->expects($this->once())
  59. ->method('getValue')
  60. ->will($this->returnValue(false));
  61. $this->assertEquals('Sign In', $this->_block->getLabel());
  62. }
  63. public function testGetHrefLoggedIn()
  64. {
  65. $this->httpContext->expects($this->once())
  66. ->method('getValue')
  67. ->will($this->returnValue(true));
  68. $this->_customerUrl->expects($this->once())->method('getLogoutUrl')->will($this->returnValue('logout url'));
  69. $this->assertEquals('logout url', $this->_block->getHref());
  70. }
  71. public function testGetHrefLoggedOut()
  72. {
  73. $this->httpContext->expects($this->once())
  74. ->method('getValue')
  75. ->will($this->returnValue(false));
  76. $this->_customerUrl->expects($this->once())->method('getLoginUrl')->will($this->returnValue('login url'));
  77. $this->assertEquals('login url', $this->_block->getHref());
  78. }
  79. }