Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractControllerTest.php
Go to the documentation of this file.
1 <?php
8 
12 abstract class AbstractControllerTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $contextMock;
18 
22  protected $fileFactoryMock;
23 
27  protected $requestMock;
28 
32  protected $viewMock;
33 
37  protected $layoutMock;
38 
43 
47  protected $menuBlockMock;
48 
52  protected $switcherBlockMock;
53 
57  protected $menuModelMock;
58 
62  protected $abstractBlockMock;
63 
67  protected function setUp()
68  {
69  $this->requestMock = $this->getMockForAbstractClassBuilder(
70  \Magento\Framework\App\RequestInterface::class,
71  ['isDispatched', 'initForward', 'setDispatched', 'isForwarded']
72  );
73  $this->breadcrumbsBlockMock = $this->getMockForAbstractClassBuilder(
74  \Magento\Framework\View\Element\BlockInterface::class,
75  ['addLink']
76  );
77  $this->menuBlockMock = $this->getMockForAbstractClassBuilder(
78  \Magento\Framework\View\Element\BlockInterface::class,
79  ['setActive', 'getMenuModel']
80  );
81  $this->viewMock = $this->getMockForAbstractClassBuilder(
82  \Magento\Framework\App\ViewInterface::class
83  );
84 
85  $this->layoutMock = $this->getMockBuilder(\Magento\Framework\View\LayoutInterface::class)
86  ->disableOriginalConstructor()
87  ->getMock();
88  $this->switcherBlockMock = $this->getMockBuilder(\Magento\Framework\View\Element\BlockInterface::class)
89  ->disableOriginalConstructor()
90  ->getMock();
91  $this->contextMock = $this->getMockBuilder(\Magento\Backend\App\Action\Context::class)
92  ->disableOriginalConstructor()
93  ->getMock();
94  $this->fileFactoryMock = $this->getMockBuilder(\Magento\Framework\App\Response\Http\FileFactory::class)
95  ->disableOriginalConstructor()
96  ->getMock();
97  $this->menuModelMock = $this->getMockBuilder(\Magento\Backend\Model\Menu::class)
98  ->disableOriginalConstructor()
99  ->getMock();
100  $this->abstractBlockMock = $this->getMockBuilder(\Magento\Framework\View\Element\AbstractBlock::class)
101  ->setMethods(['getCsvFile', 'getExcelFile', 'setSaveParametersInSession', 'getCsv', 'getExcel'])
102  ->disableOriginalConstructor()
103  ->getMock();
104 
105  $this->menuModelMock->expects($this->any())->method('getParentItems')->willReturn([]);
106  $this->menuBlockMock->expects($this->any())->method('getMenuModel')->willReturn($this->menuModelMock);
107  $this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
108  $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
109  $this->contextMock->expects($this->any())->method('getView')->willReturn($this->viewMock);
110 
111  $this->layoutMock->expects($this->any())->method('getBlock')->will(
112  $this->returnValueMap(
113  [
114  ['breadcrumbs', $this->breadcrumbsBlockMock],
115  ['menu', $this->menuBlockMock],
116  ['store_switcher', $this->switcherBlockMock]
117  ]
118  )
119  );
120  $this->layoutMock->expects($this->any())->method('getChildBlock')->willReturn($this->abstractBlockMock);
121  }
122 
129  protected function getMockForAbstractClassBuilder($className, $mockedMethods = [])
130  {
131  return $this->getMockForAbstractClass($className, [], '', false, false, true, $mockedMethods);
132  }
133 }
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31