@@ -202,4 +202,55 @@ public function testGetTracksCollection()
202
202
[$ secondShipmentTrack ->getEntityId ()]
203
203
);
204
204
}
205
+
206
+ /**
207
+ * Check that getTracksCollection() returns only shipment related tracks.
208
+ *
209
+ * For the Block and Template responsible for sending email notification, when multiple items order
210
+ * has multiple shipments and every shipment has a separate tracking, shipment should contain
211
+ * only tracking info related to given shipment.
212
+ *
213
+ * @magentoDataFixture Magento/Sales/_files/order_with_two_order_items_with_simple_product.php
214
+ */
215
+ public function testBlock ()
216
+ {
217
+ $ order = $ this ->getOrder ('100000001 ' );
218
+
219
+ $ shipments = [];
220
+ foreach ($ order ->getItems () as $ item ) {
221
+ $ items [$ item ->getId ()] = $ item ->getQtyOrdered ();
222
+ /** @var ShipmentTrackInterface $track */
223
+ $ track = $ this ->objectManager ->create (ShipmentTrackInterface::class);
224
+ $ track ->setNumber ('Test Number ' )
225
+ ->setTitle ('Test Title ' )
226
+ ->setCarrierCode ('Test CODE ' );
227
+ /** @var \Magento\Sales\Model\Order\Shipment $shipment */
228
+ $ shipment = $ this ->objectManager ->get (ShipmentFactory::class)
229
+ ->create ($ order , $ items );
230
+ $ shipment ->addTrack ($ track );
231
+ $ this ->shipmentRepository ->save ($ shipment );
232
+ $ shipments [] = $ shipment ;
233
+ }
234
+
235
+ // we extract only the latest shipment
236
+ $ shipment = array_pop ($ shipments );
237
+
238
+ $ block = $ this ->objectManager ->create (
239
+ \Magento \Sales \Block \Order \Email \Shipment \Items::class,
240
+ [
241
+ 'data ' => [
242
+ 'order ' => $ order ,
243
+ 'shipment ' => $ shipment ,
244
+ ]
245
+ ]
246
+ );
247
+
248
+ $ tracks = $ block ->getShipment ()->getTracksCollection ()->getItems ();
249
+ $ this ->assertEquals (1 , count ($ tracks ),
250
+ 'There should be only one Tracking item in collection ' );
251
+
252
+ $ track = array_pop ($ tracks );
253
+ $ this ->assertEquals ($ shipment ->getId (), $ track ->getParentId (),
254
+ 'Check that the Tracking belongs to the Shipment ' );
255
+ }
205
256
}
0 commit comments