Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ShowUpdateResultTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class ShowUpdateResultTest extends \PHPUnit\Framework\TestCase
14 {
16  protected $context;
17 
19  protected $layout;
20 
22  protected $session;
23 
25  protected $request;
26 
32  protected function getSession()
33  {
34  $session = $this->createPartialMock(
35  \Magento\Backend\Model\Session::class,
36  ['hasCompositeProductResult', 'getCompositeProductResult', 'unsCompositeProductResult']
37  );
38  $session->expects($this->once())
39  ->method('hasCompositeProductResult')
40  ->willReturn(true);
41  $session->expects($this->once())
42  ->method('unsCompositeProductResult');
43  $session->expects($this->atLeastOnce())
44  ->method('getCompositeProductResult')
45  ->willReturn(new \Magento\Framework\DataObject());
46 
47  return $session;
48  }
49 
55  protected function getContext()
56  {
57  $productActionMock = $this->createMock(\Magento\Catalog\Model\Product\Action::class);
58  $objectManagerMock = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
59  $objectManagerMock->expects($this->any())
60  ->method('get')
61  ->willReturn($productActionMock);
62 
63  $eventManager = $this->getMockBuilder(\Magento\Framework\Event\Manager::class)
64  ->setMethods(['dispatch'])
65  ->disableOriginalConstructor()
66  ->getMockForAbstractClass();
67 
68  $eventManager->expects($this->any())
69  ->method('dispatch')
70  ->willReturnSelf();
71 
72  $this->request = $this->createPartialMock(
73  \Magento\Framework\App\Request\Http::class,
74  ['getParam', 'getPost', 'getFullActionName', 'getPostValue']
75  );
76 
77  $responseInterfaceMock = $this->createPartialMock(
78  \Magento\Framework\App\ResponseInterface::class,
79  ['setRedirect', 'sendResponse']
80  );
81 
82  $managerInterfaceMock = $this->createMock(\Magento\Framework\Message\ManagerInterface::class);
83  $this->session = $this->getSession();
84  $actionFlagMock = $this->createMock(\Magento\Framework\App\ActionFlag::class);
85  $helperDataMock = $this->createMock(\Magento\Backend\Helper\Data::class);
86  $this->context = $this->createPartialMock(\Magento\Backend\App\Action\Context::class, [
87  'getRequest',
88  'getResponse',
89  'getObjectManager',
90  'getEventManager',
91  'getMessageManager',
92  'getSession',
93  'getActionFlag',
94  'getHelper',
95  'getTitle',
96  'getView',
97  'getResultRedirectFactory'
98  ]);
99 
100  $this->context->expects($this->any())
101  ->method('getEventManager')
102  ->willReturn($eventManager);
103  $this->context->expects($this->any())
104  ->method('getRequest')
105  ->willReturn($this->request);
106  $this->context->expects($this->any())
107  ->method('getResponse')
108  ->willReturn($responseInterfaceMock);
109  $this->context->expects($this->any())
110  ->method('getObjectManager')
111  ->willReturn($objectManagerMock);
112 
113  $this->context->expects($this->any())
114  ->method('getMessageManager')
115  ->willReturn($managerInterfaceMock);
116  $this->context->expects($this->any())
117  ->method('getSession')
118  ->willReturn($this->session);
119  $this->context->expects($this->any())
120  ->method('getActionFlag')
121  ->willReturn($actionFlagMock);
122  $this->context->expects($this->any())
123  ->method('getHelper')
124  ->willReturn($helperDataMock);
125 
126  return $this->context;
127  }
128 
129  public function testExecute()
130  {
131  $productCompositeHelper = $this->createMock(\Magento\Catalog\Helper\Product\Composite::class);
132  $productCompositeHelper->expects($this->once())
133  ->method('renderUpdateResult');
134 
135  $productBuilder = $this->createMock(\Magento\Catalog\Controller\Adminhtml\Product\Builder::class);
136  $context = $this->getContext();
137 
139  $controller = new ShowUpdateResult($context, $productBuilder, $productCompositeHelper);
140  $controller->execute();
141  }
142 }
$controller
Definition: info.phtml:14