Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OnepageTest.php
Go to the documentation of this file.
1 <?php
7 
8 class OnepageTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $model;
14 
19 
23  protected $storeManagerMock;
24 
28  protected $formKeyMock;
29 
34 
38  private $serializer;
39 
40  protected function setUp()
41  {
42  $contextMock = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
43  $this->formKeyMock = $this->createMock(\Magento\Framework\Data\Form\FormKey::class);
44  $this->configProviderMock = $this->createMock(\Magento\Checkout\Model\CompositeConfigProvider::class);
45 
46  $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
47  $contextMock->expects($this->once())->method('getStoreManager')->willReturn($this->storeManagerMock);
48  $this->layoutProcessorMock = $this->createMock(
49  \Magento\Checkout\Block\Checkout\LayoutProcessorInterface::class
50  );
51 
52  $this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
53 
54  $this->model = new \Magento\Checkout\Block\Onepage(
55  $contextMock,
56  $this->formKeyMock,
57  $this->configProviderMock,
58  [$this->layoutProcessorMock],
59  [],
60  $this->serializer
61  );
62  }
63 
64  public function testGetBaseUrl()
65  {
66  $baseUrl = 'http://magento.com';
67  $storeMock = $this->createMock(\Magento\Store\Model\Store::class);
68 
69  $storeMock->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
70  $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
71 
72  $this->assertEquals($baseUrl, $this->model->getBaseUrl());
73  }
74 
75  public function testGetCheckoutConfig()
76  {
77  $checkoutConfig = ['checkout', 'config'];
78  $this->configProviderMock->expects($this->once())->method('getConfig')->willReturn($checkoutConfig);
79 
80  $this->assertEquals($checkoutConfig, $this->model->getCheckoutConfig());
81  }
82 
83  public function testGetFormKey()
84  {
85  $formKey = 'form_key';
86  $this->formKeyMock->expects($this->once())->method('getFormKey')->willReturn($formKey);
87 
88  $this->assertEquals($formKey, $this->model->getFormKey());
89  }
90 
91  public function testGetJsLayout()
92  {
93  $processedLayout = ['layout' => ['processed' => true]];
94  $jsonLayout = '{"layout":{"processed":true}}';
95  $this->layoutProcessorMock->expects($this->once())->method('process')->with([])->willReturn($processedLayout);
96 
97  $this->assertEquals($jsonLayout, $this->model->getJsLayout());
98  }
99 
101  {
102  $checkoutConfig = ['checkout', 'config'];
103  $this->configProviderMock->expects($this->once())->method('getConfig')->willReturn($checkoutConfig);
104 
105  $this->assertEquals(json_encode($checkoutConfig), $this->model->getSerializedCheckoutConfig());
106  }
107 }