Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReloadTest.php
Go to the documentation of this file.
1 <?php
7 
19 
25 class ReloadTest extends \PHPUnit\Framework\TestCase
26 {
30  protected $model;
31 
35  protected $objectManager;
36 
40  protected $contextMock;
41 
45  protected $resultFactoryMock;
46 
50  protected $layoutMock;
51 
55  protected $requestMock;
56 
61 
65  protected $resultMock;
66 
70  protected $productMock;
71 
75  protected $uiComponentMock;
76 
80  protected $processorMock;
81 
82  protected function setUp()
83  {
84  $this->objectManager = new ObjectManager($this);
85 
86  $this->contextMock = $this->getMockBuilder(Context::class)
87  ->disableOriginalConstructor()
88  ->getMock();
89  $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)
90  ->disableOriginalConstructor()
91  ->getMock();
92  $this->layoutMock = $this->getMockBuilder(LayoutInterface::class)
93  ->disableOriginalConstructor()
94  ->getMock();
95  $this->requestMock = $this->getMockBuilder(RequestInterface::class)
96  ->getMockForAbstractClass();
97  $this->productBuilderMock = $this->getMockBuilder(Builder::class)
98  ->disableOriginalConstructor()
99  ->getMock();
100  $this->resultMock = $this->getMockBuilder(ResultInterface::class)
101  ->setMethods(['forward', 'setJsonData', 'getLayout'])
102  ->getMockForAbstractClass();
103  $this->productMock = $this->getMockBuilder(ProductInterface::class)
104  ->getMockForAbstractClass();
105  $this->uiComponentMock = $this->getMockBuilder(UiComponent::class)
106  ->disableOriginalConstructor()
107  ->getMock();
108  $this->processorMock = $this->getMockBuilder(ProcessorInterface::class)
109  ->getMockForAbstractClass();
110 
111  $this->contextMock->expects($this->any())
112  ->method('getRequest')
113  ->willReturn($this->requestMock);
114  $this->resultFactoryMock->expects($this->any())
115  ->method('create')
116  ->willReturn($this->resultMock);
117  $this->contextMock->expects($this->any())
118  ->method('getResultFactory')
119  ->willReturn($this->resultFactoryMock);
120  $this->productBuilderMock->expects($this->any())
121  ->method('build')
122  ->willReturn($this->productMock);
123  $this->layoutMock->expects($this->any())
124  ->method('getBlock')
125  ->willReturn($this->uiComponentMock);
126  $this->layoutMock->expects($this->any())
127  ->method('getUpdate')
128  ->willReturn($this->processorMock);
129  $this->resultMock->expects($this->any())
130  ->method('getLayout')
131  ->willReturn($this->layoutMock);
132 
133  $this->model = $this->objectManager->getObject(Reload::class, [
134  'context' => $this->contextMock,
135  'productBuilder' => $this->productBuilderMock,
136  'layout' => $this->layoutMock,
137  ]);
138  }
139 
140  public function testExecuteToBeRedirect()
141  {
142  $this->requestMock->expects($this->once())
143  ->method('getParam')
144  ->willReturn(false);
145  $this->resultMock->expects($this->once())
146  ->method('forward')
147  ->with('noroute')
148  ->willReturn(true);
149 
150  $this->assertSame(true, $this->model->execute());
151  }
152 
153  public function testExecute()
154  {
155  $this->requestMock->expects($this->once())
156  ->method('getParam')
157  ->willReturn('true');
158 
159  $this->assertInstanceOf(ResultInterface::class, $this->model->execute());
160  }
161 }