Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AuthorizationLinkTest.php
Go to the documentation of this file.
1 <?php
7 
11 class AuthorizationLinkTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $_objectManager;
17 
21  protected $httpContext;
22 
26  protected $_customerUrl;
27 
31  protected $_block;
32 
33  protected function setUp()
34  {
35  $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36  $this->httpContext = $this->getMockBuilder(\Magento\Framework\App\Http\Context::class)
37  ->disableOriginalConstructor()
38  ->setMethods(['getValue'])
39  ->getMock();
40  $this->_customerUrl = $this->getMockBuilder(\Magento\Customer\Model\Url::class)
41  ->disableOriginalConstructor()
42  ->setMethods(['getLogoutUrl', 'getLoginUrl'])
43  ->getMock();
44 
45  $context = $this->_objectManager->getObject(\Magento\Framework\View\Element\Template\Context::class);
46  $this->_block = $this->_objectManager->getObject(
47  \Magento\Customer\Block\Account\AuthorizationLink::class,
48  [
49  'context' => $context,
50  'httpContext' => $this->httpContext,
51  'customerUrl' => $this->_customerUrl,
52  ]
53  );
54  }
55 
56  public function testGetLabelLoggedIn()
57  {
58  $this->httpContext->expects($this->once())
59  ->method('getValue')
60  ->will($this->returnValue(true));
61 
62  $this->assertEquals('Sign Out', $this->_block->getLabel());
63  }
64 
65  public function testGetLabelLoggedOut()
66  {
67  $this->httpContext->expects($this->once())
68  ->method('getValue')
69  ->will($this->returnValue(false));
70 
71  $this->assertEquals('Sign In', $this->_block->getLabel());
72  }
73 
74  public function testGetHrefLoggedIn()
75  {
76  $this->httpContext->expects($this->once())
77  ->method('getValue')
78  ->will($this->returnValue(true));
79 
80  $this->_customerUrl->expects($this->once())->method('getLogoutUrl')->will($this->returnValue('logout url'));
81 
82  $this->assertEquals('logout url', $this->_block->getHref());
83  }
84 
85  public function testGetHrefLoggedOut()
86  {
87  $this->httpContext->expects($this->once())
88  ->method('getValue')
89  ->will($this->returnValue(false));
90 
91  $this->_customerUrl->expects($this->once())->method('getLoginUrl')->will($this->returnValue('login url'));
92 
93  $this->assertEquals('login url', $this->_block->getHref());
94  }
95 }