Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ContentsTest.php
Go to the documentation of this file.
1 <?php
7 
11 class ContentsTest extends \PHPUnit\Framework\TestCase
12 {
14  protected $controller;
15 
17  protected $view;
18 
20  protected $objectManager;
21 
23  protected $session;
24 
26  protected $response;
27 
29  protected $storage;
30 
31  protected function setUp()
32  {
33  $this->view = $this->createMock(\Magento\Framework\App\ViewInterface::class);
34  $this->objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
35  $this->session = $this->createMock(\Magento\Backend\Model\Session::class);
36  $this->response = $this->createMock(\Magento\Framework\App\Response\Http::class);
37  $this->storage = $this->createMock(\Magento\Theme\Helper\Storage::class);
38 
39  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
40  $this->controller = $helper->getObject(
41  \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\Contents::class,
42  [
43  'objectManager' => $this->objectManager,
44  'view' => $this->view,
45  'session' => $this->session,
46  'response' => $this->response,
47  'storage' => $this->storage
48  ]
49  );
50  }
51 
52  public function testExecute()
53  {
54  $layout = $this->getMockForAbstractClass(\Magento\Framework\View\LayoutInterface::class, [], '', false);
55  $storage = $this->createMock(\Magento\Theme\Model\Wysiwyg\Storage::class);
56  $block = $this->getMockForAbstractClass(
57  \Magento\Framework\View\Element\BlockInterface::class,
58  [],
59  '',
60  false,
61  false,
62  true,
63  ['setStorage']
64  );
65 
66  $this->view->expects($this->once())
67  ->method('loadLayout')
68  ->with('empty');
69  $this->view->expects($this->once())
70  ->method('getLayout')
71  ->willReturn($layout);
72  $layout->expects($this->once())
73  ->method('getBlock')
74  ->with('wysiwyg_files.files')
75  ->willReturn($block);
76  $block->expects($this->once())
77  ->method('setStorage')
78  ->with($storage);
79  $this->objectManager->expects($this->at(0))
80  ->method('get')
81  ->with(\Magento\Theme\Model\Wysiwyg\Storage::class)
82  ->willReturn($storage);
83  $this->storage->expects($this->once())
84  ->method('getCurrentPath')
85  ->willThrowException(new \Exception('Message'));
86 
87  $jsonData = $this->createMock(\Magento\Framework\Json\Helper\Data::class);
88  $jsonData->expects($this->once())
89  ->method('jsonEncode')
90  ->with(['error' => true, 'message' => 'Message'])
91  ->willReturn('{"error":"true","message":"Message"}');
92 
93  $this->objectManager->expects($this->at(1))
94  ->method('get')
95  ->with(\Magento\Framework\Json\Helper\Data::class)
96  ->willReturn($jsonData);
97 
98  $this->response->expects($this->once())
99  ->method('representJson');
100 
101  $this->controller->execute();
102  }
103 }
$helper
Definition: iframe.phtml:13
$block
Definition: block.php:8