Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RegisterLinkTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class RegisterLinkTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $_objectManager;
19 
20  protected function setUp()
21  {
22  $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
23  }
24 
32  public function testToHtml($isAuthenticated, $isRegistrationAllowed, $result)
33  {
34  $context = $this->_objectManager->getObject(\Magento\Framework\View\Element\Template\Context::class);
35 
36  $httpContext = $this->getMockBuilder(\Magento\Framework\App\Http\Context::class)
37  ->disableOriginalConstructor()
38  ->setMethods(['getValue'])
39  ->getMock();
40  $httpContext->expects($this->any())
41  ->method('getValue')
42  ->with(Context::CONTEXT_AUTH)
43  ->will($this->returnValue($isAuthenticated));
44 
45  $registrationMock = $this->getMockBuilder(\Magento\Customer\Model\Registration::class)
46  ->disableOriginalConstructor()
47  ->setMethods(['isAllowed'])
48  ->getMock();
49  $registrationMock->expects($this->any())
50  ->method('isAllowed')
51  ->will($this->returnValue($isRegistrationAllowed));
52 
54  $link = $this->_objectManager->getObject(
55  \Magento\Customer\Block\Account\RegisterLink::class,
56  [
57  'context' => $context,
58  'httpContext' => $httpContext,
59  'registration' => $registrationMock,
60  ]
61  );
62 
63  $this->assertEquals($result, $link->toHtml() === '');
64  }
65 
69  public function dataProviderToHtml()
70  {
71  return [
72  [true, true, true],
73  [false, false, true],
74  [true, false, true],
75  [false, true, false],
76  ];
77  }
78 
79  public function testGetHref()
80  {
81  $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
82  $helper = $this->getMockBuilder(
83  \Magento\Customer\Model\Url::class
84  )->disableOriginalConstructor()->setMethods(
85  ['getRegisterUrl']
86  )->getMock();
87 
88  $helper->expects($this->any())->method('getRegisterUrl')->will($this->returnValue('register url'));
89 
90  $context = $this->_objectManager->getObject(\Magento\Framework\View\Element\Template\Context::class);
91 
92  $block = $this->_objectManager->getObject(
93  \Magento\Customer\Block\Account\RegisterLink::class,
94  ['context' => $context, 'customerUrl' => $helper]
95  );
96  $this->assertEquals('register url', $block->getHref());
97  }
98 }
$helper
Definition: iframe.phtml:13
$block
Definition: block.php:8