Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GiftOptionsTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class GiftOptionsTest extends \PHPUnit\Framework\TestCase
11 {
13  protected $context;
14 
17 
20 
22  protected $model;
23 
25  protected $jsonEncoderMock;
26 
28  protected $jsLayout = ['root' => 'node'];
29 
30  protected function setUp()
31  {
32  $this->context = $this->createMock(\Magento\Backend\Block\Template\Context::class);
33  $this->jsonEncoderMock = $this->createMock(\Magento\Framework\Json\Encoder::class);
34  $this->compositeConfigProvider = $this->createMock(\Magento\GiftMessage\Model\CompositeConfigProvider::class);
35  $this->layoutProcessorMock = $this->getMockForAbstractClass(
36  \Magento\Checkout\Block\Checkout\LayoutProcessorInterface::class,
37  [],
38  '',
39  false
40  );
41  $this->model = new GiftOptions(
42  $this->context,
43  $this->jsonEncoderMock,
44  $this->compositeConfigProvider,
45  [$this->layoutProcessorMock],
46  ['jsLayout' => $this->jsLayout]
47  );
48  }
49 
50  public function testGetJsLayout()
51  {
52  $this->layoutProcessorMock->expects($this->once())
53  ->method('process')
54  ->with($this->jsLayout)
55  ->willReturnArgument(0);
56  $this->jsonEncoderMock->expects($this->once())
57  ->method('encode')
58  ->with($this->jsLayout)
59  ->willReturnArgument(0);
60  $this->assertEquals($this->jsLayout, $this->model->getJsLayout());
61  }
62 
63  public function testGetGiftOptionsConfigJson()
64  {
65  $this->compositeConfigProvider->expects($this->once())
66  ->method('getConfig')
67  ->willReturn($this->jsLayout);
68  $this->jsonEncoderMock->expects($this->once())
69  ->method('encode')
70  ->with($this->jsLayout)
71  ->willReturnArgument(0);
72  $this->assertEquals($this->jsLayout, $this->model->getGiftOptionsConfigJson());
73  }
74 }