Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LinkTest.php
Go to the documentation of this file.
1 <?php
7 
8 class LinkTest extends \PHPUnit\Framework\TestCase
9 {
14 
15  protected function setUp()
16  {
17  $this->_objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
18  }
19 
20  public function testGetUrl()
21  {
22  $path = 'checkout';
23  $url = 'http://example.com/';
24 
25  $urlBuilder = $this->getMockForAbstractClass(\Magento\Framework\UrlInterface::class);
26  $urlBuilder->expects($this->once())->method('getUrl')->with($path)->will($this->returnValue($url . $path));
27 
28  $context = $this->_objectManagerHelper->getObject(
29  \Magento\Framework\View\Element\Template\Context::class,
30  ['urlBuilder' => $urlBuilder]
31  );
32  $link = $this->_objectManagerHelper->getObject(\Magento\Checkout\Block\Link::class, ['context' => $context]);
33  $this->assertEquals($url . $path, $link->getHref());
34  }
35 
39  public function testToHtml($canOnepageCheckout, $isOutputEnabled)
40  {
41  $helper = $this->getMockBuilder(
42  \Magento\Checkout\Helper\Data::class
43  )->disableOriginalConstructor()->setMethods(
44  ['canOnepageCheckout', 'isModuleOutputEnabled']
45  )->getMock();
46 
47  $moduleManager = $this->getMockBuilder(
48  \Magento\Framework\Module\Manager::class
49  )->disableOriginalConstructor()->setMethods(
50  ['isOutputEnabled']
51  )->getMock();
52 
54  $block = $this->_objectManagerHelper->getObject(
55  \Magento\Checkout\Block\Link::class,
56  ['moduleManager' => $moduleManager, 'checkoutHelper' => $helper]
57  );
58  $helper->expects($this->any())->method('canOnepageCheckout')->will($this->returnValue($canOnepageCheckout));
59  $moduleManager->expects(
60  $this->any()
61  )->method(
62  'isOutputEnabled'
63  )->with(
64  'Magento_Checkout'
65  )->will(
66  $this->returnValue($isOutputEnabled)
67  );
68  $this->assertEquals('', $block->toHtml());
69  }
70 
74  public function toHtmlDataProvider()
75  {
76  return [[false, true], [true, false], [false, false]];
77  }
78 }
$helper
Definition: iframe.phtml:13
$block
Definition: block.php:8
$moduleManager
Definition: products.php:75