public function testRemove() { $triggerMock = $this->getMock('Magento\\Framework\\DB\\Ddl\\Trigger', [], [], '', false, false); $triggerMock->expects($this->exactly(3))->method('setName')->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('getName')->will($this->returnValue('triggerName')); $triggerMock->expects($this->exactly(3))->method('setTime')->with(\Magento\Framework\DB\Ddl\Trigger::TIME_AFTER)->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('setEvent')->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('setTable')->with($this->tableName)->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('addStatement')->will($this->returnSelf()); $this->triggerFactoryMock->expects($this->exactly(3))->method('create')->will($this->returnValue($triggerMock)); $otherChangelogMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\View\\ChangelogInterface', [], '', false, false, true, []); $otherChangelogMock->expects($this->exactly(3))->method('getName')->will($this->returnValue('other_test_view_cl')); $otherChangelogMock->expects($this->exactly(3))->method('getColumnName')->will($this->returnValue('entity_id')); $otherViewMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\ViewInterface', [], '', false, false, true, []); $otherViewMock->expects($this->exactly(1))->method('getId')->will($this->returnValue('other_id')); $otherViewMock->expects($this->exactly(1))->method('getSubscriptions')->will($this->returnValue([['name' => $this->tableName], ['name' => 'otherTableName']])); $otherViewMock->expects($this->exactly(3))->method('getChangelog')->will($this->returnValue($otherChangelogMock)); $this->viewMock->expects($this->exactly(3))->method('getId')->will($this->returnValue('this_id')); $this->viewMock->expects($this->never())->method('getSubscriptions'); $this->viewCollectionMock->expects($this->exactly(1))->method('getViewsByStateMode')->with(\Magento\Framework\Mview\View\StateInterface::MODE_ENABLED)->will($this->returnValue([$this->viewMock, $otherViewMock])); $this->connectionMock->expects($this->exactly(3))->method('dropTrigger')->with('triggerName')->will($this->returnValue(true)); $triggerMock->expects($this->exactly(3))->method('getStatements')->will($this->returnValue(true)); $this->connectionMock->expects($this->exactly(3))->method('createTrigger')->with($triggerMock); $this->model->remove(); }
/** * Retrieve list of linked views * * @return array */ protected function getLinkedViews() { if (!$this->linkedViews) { $viewList = $this->viewCollection->getViewsByStateMode(\Magento\Framework\Mview\View\StateInterface::MODE_ENABLED); foreach ($viewList as $view) { /** @var \Magento\Framework\Mview\ViewInterface $view */ // Skip the current view if ($view->getId() == $this->getView()->getId()) { continue; } // Search in view subscriptions foreach ($view->getSubscriptions() as $subscription) { if ($subscription['name'] != $this->getTableName()) { continue; } $this->linkedViews[] = $view; } } } return $this->linkedViews; }