コード例 #1
0
 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();
 }
コード例 #2
0
 /**
  * Remove subscription
  *
  * @return \Magento\Framework\Mview\View\SubscriptionInterface
  */
 public function remove()
 {
     foreach (Trigger::getListOfEvents() as $event) {
         $triggerName = $this->getAfterEventTriggerName($event);
         /** @var Trigger $trigger */
         $trigger = $this->triggerFactory->create()->setName($triggerName)->setTime(Trigger::TIME_AFTER)->setEvent($event)->setTable($this->resource->getTableName($this->getTableName()));
         // Add statements for linked views
         foreach ($this->getLinkedViews() as $view) {
             /** @var \Magento\Framework\Mview\ViewInterface $view */
             $trigger->addStatement($this->buildStatement($event, $view->getChangelog()));
         }
         $this->connection->dropTrigger($trigger->getName());
         // Re-create trigger if trigger used by linked views
         if ($trigger->getStatements()) {
             $this->connection->createTrigger($trigger);
         }
     }
     return $this;
 }