Skip to content

Commit 70ed61a

Browse files
MC-36219: Incorrect order created date in shipment grid table.
1 parent 470eaff commit 70ed61a

File tree

1 file changed

+53
-10
lines changed
  • dev/tests/integration/testsuite/Magento/Sales/Model/ResourceModel/Report/Shipping/Collection

1 file changed

+53
-10
lines changed

dev/tests/integration/testsuite/Magento/Sales/Model/ResourceModel/Report/Shipping/Collection/ShipmentTest.php

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,35 @@
55
*/
66
namespace Magento\Sales\Model\ResourceModel\Report\Shipping\Collection;
77

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+
817
/**
918
* Integration tests for shipments reports collection which is used to obtain shipment reports by shipment date.
1019
*/
11-
class ShipmentTest extends \PHPUnit\Framework\TestCase
20+
class ShipmentTest extends TestCase
1221
{
1322
/**
14-
* @var \Magento\Sales\Model\ResourceModel\Report\Shipping\Collection\Shipment
23+
* @var Shipment
1524
*/
1625
private $collection;
1726

1827
/**
19-
* @var \Magento\Framework\ObjectManagerInterface
28+
* @var ObjectManagerInterface
2029
*/
2130
private $objectManager;
2231

2332
protected function setUp(): void
2433
{
25-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
34+
$this->objectManager = Bootstrap::getObjectManager();
2635
$this->collection = $this->objectManager->create(
27-
\Magento\Sales\Model\ResourceModel\Report\Shipping\Collection\Shipment::class
36+
Shipment::class
2837
);
2938
$this->collection->setPeriod('day')
3039
->setDateRange(null, null)
@@ -43,11 +52,11 @@ public function testGetItems()
4352
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
4453
$order->loadByIncrementId('100000001');
4554
$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)
4857
->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);
5160
$shipmentCreatedAt = $timezone->formatDateTime(
5261
$shipmentCreatedAt,
5362
\IntlDateFormatter::SHORT,
@@ -67,10 +76,44 @@ public function testGetItems()
6776
],
6877
];
6978
$actualResult = [];
70-
/** @var \Magento\Reports\Model\Item $reportItem */
79+
/** @var Item $reportItem */
7180
foreach ($this->collection->getItems() as $reportItem) {
7281
$actualResult[] = array_intersect_key($reportItem->getData(), $expectedResult[0]);
7382
}
7483
$this->assertEquals($expectedResult, $actualResult);
7584
}
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+
}
76119
}

0 commit comments

Comments
 (0)