5
5
*/
6
6
namespace Magento \Sales \Model \ResourceModel \Report \Shipping \Collection ;
7
7
8
+ use Magento \Framework \ObjectManagerInterface ;
9
+ use Magento \Framework \Stdlib \DateTime \DateTime ;
10
+ use Magento \Framework \Stdlib \DateTime \DateTimeFactory ;
11
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
12
+ use Magento \Reports \Model \Item ;
13
+ use Magento \Sales \Model \ResourceModel \Order \Shipment \Grid \Collection as ShipmentGridCollection ;
14
+ use Magento \TestFramework \Helper \Bootstrap ;
15
+ use PHPUnit \Framework \TestCase ;
16
+
8
17
/**
9
18
* Integration tests for shipments reports collection which is used to obtain shipment reports by shipment date.
10
19
*/
11
- class ShipmentTest extends \ PHPUnit \ Framework \ TestCase
20
+ class ShipmentTest extends TestCase
12
21
{
13
22
/**
14
- * @var \Magento\Sales\Model\ResourceModel\Report\Shipping\Collection\ Shipment
23
+ * @var Shipment
15
24
*/
16
25
private $ collection ;
17
26
18
27
/**
19
- * @var \Magento\Framework\ ObjectManagerInterface
28
+ * @var ObjectManagerInterface
20
29
*/
21
30
private $ objectManager ;
22
31
23
32
protected function setUp (): void
24
33
{
25
- $ this ->objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
34
+ $ this ->objectManager = Bootstrap::getObjectManager ();
26
35
$ this ->collection = $ this ->objectManager ->create (
27
- \ Magento \ Sales \ Model \ ResourceModel \ Report \ Shipping \ Collection \ Shipment::class
36
+ Shipment::class
28
37
);
29
38
$ this ->collection ->setPeriod ('day ' )
30
39
->setDateRange (null , null )
@@ -43,11 +52,11 @@ public function testGetItems()
43
52
$ order = $ this ->objectManager ->create (\Magento \Sales \Model \Order::class);
44
53
$ order ->loadByIncrementId ('100000001 ' );
45
54
$ shipmentCreatedAt = $ order ->getShipmentsCollection ()->getFirstItem ()->getCreatedAt ();
46
- /** @var \Magento\Framework\Stdlib\DateTime\ DateTime $dateTime */
47
- $ dateTime = $ this ->objectManager ->create (\ Magento \ Framework \ Stdlib \ DateTime \ DateTimeFactory::class)
55
+ /** @var DateTime $dateTime */
56
+ $ dateTime = $ this ->objectManager ->create (DateTimeFactory::class)
48
57
->create ();
49
- /** @var \Magento\Framework\Stdlib\DateTime\ TimezoneInterface $timezone */
50
- $ timezone = $ this ->objectManager ->create (\ Magento \ Framework \ Stdlib \ DateTime \ TimezoneInterface::class);
58
+ /** @var TimezoneInterface $timezone */
59
+ $ timezone = $ this ->objectManager ->create (TimezoneInterface::class);
51
60
$ shipmentCreatedAt = $ timezone ->formatDateTime (
52
61
$ shipmentCreatedAt ,
53
62
\IntlDateFormatter::SHORT ,
@@ -67,10 +76,44 @@ public function testGetItems()
67
76
],
68
77
];
69
78
$ actualResult = [];
70
- /** @var \Magento\Reports\Model\ Item $reportItem */
79
+ /** @var Item $reportItem */
71
80
foreach ($ this ->collection ->getItems () as $ reportItem ) {
72
81
$ actualResult [] = array_intersect_key ($ reportItem ->getData (), $ expectedResult [0 ]);
73
82
}
74
83
$ this ->assertEquals ($ expectedResult , $ actualResult );
75
84
}
85
+
86
+ /**
87
+ * Checks that order_created_at field does not change after sales_shipment_grid row update
88
+ *
89
+ * @magentoDataFixture Magento/Sales/_files/order_shipping.php
90
+ * @return void
91
+ */
92
+ public function testOrderShipmentGridOrderCreatedAt (): void
93
+ {
94
+ $ incrementId = '100000001 ' ;
95
+ /** @var \Magento\Sales\Model\Order $order */
96
+ $ order = $ this ->objectManager ->create (\Magento \Sales \Model \Order::class);
97
+ $ order ->loadByIncrementId ($ incrementId );
98
+ /** @var ShipmentGridCollection $grid */
99
+ $ grid = $ this ->objectManager ->get (ShipmentGridCollection::class);
100
+ $ grid ->getSelect ()
101
+ ->where ('order_increment_id ' , $ incrementId );
102
+ $ itemId = $ grid ->getFirstItem ()
103
+ ->getEntityId ();
104
+ $ connection = $ grid ->getResource ()
105
+ ->getConnection ();
106
+ $ tableName = $ grid ->getMainTable ();
107
+ $ connection ->update (
108
+ $ tableName ,
109
+ ['customer_name ' => 'Test ' ],
110
+ $ connection ->quoteInto ('entity_id = ? ' , $ itemId )
111
+ );
112
+ $ updatedRow = $ connection ->select ()
113
+ ->where ('entity_id = ? ' , $ itemId )
114
+ ->from ($ tableName , ['order_created_at ' ]);
115
+ $ orderCreatedAt = $ connection ->fetchOne ($ updatedRow );
116
+
117
+ $ this ->assertEquals ($ order ->getCreatedAt (), $ orderCreatedAt );
118
+ }
76
119
}
0 commit comments