@@ -117,6 +117,62 @@ public function testRemoveTriggersNoChanges(): void
117
117
$ this ->model ->removeTriggers ();
118
118
}
119
119
120
+ public function testRemoveTriggersNotLinked (): void
121
+ {
122
+ $ DBTriggers = [
123
+ 'trg_catalog_category_entity_int_after_insert ' => [
124
+ 'TRIGGER_NAME ' => 'trg_catalog_category_entity_int_after_insert ' ,
125
+ 'ACTION_STATEMENT ' => 'BEGIN statement; END ' ,
126
+ 'EVENT_OBJECT_TABLE ' => 'catalog_category_entity_int '
127
+ ],
128
+ 'not_linked_trg_catalog_category_entity_int_after_insert ' => [
129
+ 'TRIGGER_NAME ' => 'trg_catalog_category_entity_int_after_insert ' ,
130
+ 'ACTION_STATEMENT ' => 'BEGIN statement; END ' ,
131
+ 'EVENT_OBJECT_TABLE ' => 'catalog_category_entity_int '
132
+ ]
133
+ ];
134
+
135
+ $ connectionMock = $ this ->getConnectionMock ();
136
+ $ connectionMock ->expects ($ this ->once ())
137
+ ->method ('fetchAssoc ' )
138
+ ->willReturn ($ DBTriggers );
139
+
140
+ $ this ->resource ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ connectionMock );
141
+
142
+ $ triggerMock = $ this ->getMockBuilder (Trigger::class)
143
+ ->disableOriginalConstructor ()
144
+ ->onlyMethods (['getName ' , 'getStatements ' ])
145
+ ->getMockForAbstractClass ();
146
+ $ triggerMock ->expects ($ this ->atLeastOnce ())
147
+ ->method ('getName ' )
148
+ ->willReturn ('trg_catalog_category_entity_int_after_insert ' );
149
+ $ triggerMock ->expects ($ this ->once ())->method ('getStatements ' )->willReturn (['statement; ' ]);
150
+
151
+ $ subscriptionMock = $ this ->createMock (Subscription::class);
152
+ $ subscriptionMock ->expects ($ this ->once ())->method ('getTriggers ' )->willReturn ([$ triggerMock ]);
153
+ $ subscriptionMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ subscriptionMock );
154
+
155
+ $ viewMock = $ this ->createMock (View::class);
156
+ $ viewMock ->expects ($ this ->once ())
157
+ ->method ('getSubscriptions ' )
158
+ ->willReturn (['subscriptionConfig ' => []]);
159
+ $ viewMock ->expects ($ this ->once ())->method ('initSubscriptionInstance ' )->willReturn ($ subscriptionMock );
160
+
161
+ $ viewCollectionMock = $ this ->getMockForAbstractClass (CollectionInterface::class);
162
+ $ viewCollectionMock ->expects ($ this ->once ())->method ('getViewsByStateMode ' )->willReturn ([$ viewMock ]);
163
+
164
+ $ this ->viewCollectionFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ viewCollectionMock );
165
+
166
+ $ subscriptionMock ->expects ($ this ->never ())->method ('saveTrigger ' );
167
+ $ viewMock ->expects ($ this ->once ())->method ('unsubscribe ' );
168
+
169
+ $ this ->viewFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ viewMock );
170
+ $ state = $ this ->createMock (\Magento \Indexer \Model \Mview \View \State::class);
171
+ $ viewMock ->expects ($ this ->once ())->method ('getActionClass ' )->willReturn (true );
172
+ $ viewMock ->expects ($ this ->exactly (2 ))->method ('getState ' )->willReturn ($ state );
173
+ $ this ->model ->removeTriggers ();
174
+ }
175
+
120
176
/**
121
177
* Prepare connection mock
122
178
*
0 commit comments