77
88namespace Magento \Sales \Model \ResourceModel \Order \Grid ;
99
10+ use Magento \Framework \ObjectManagerInterface ;
11+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
1012use Magento \TestFramework \Helper \Bootstrap ;
13+ use PHPUnit \Framework \TestCase ;
1114
12- class CollectionTest extends \ PHPUnit \ Framework \ TestCase
15+ class CollectionTest extends TestCase
1316{
17+ /**
18+ * @var ObjectManagerInterface
19+ */
20+ private $ objectManager ;
21+
22+ /**
23+ * @inheritDoc
24+ */
25+ protected function setUp (): void
26+ {
27+ $ this ->objectManager = Bootstrap::getObjectManager ();
28+ }
29+
1430 /**
1531 * Tests collection properties.
1632 *
@@ -19,10 +35,8 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
1935 */
2036 public function testCollectionCreate (): void
2137 {
22- $ objectManager = Bootstrap::getObjectManager ();
23-
2438 /** @var Collection $gridCollection */
25- $ gridCollection = $ objectManager ->get (Collection::class);
39+ $ gridCollection = $ this -> objectManager ->get (Collection::class);
2640 $ tableDescription = $ gridCollection ->getConnection ()
2741 ->describeTable ($ gridCollection ->getMainTable ());
2842
@@ -42,4 +56,25 @@ public function testCollectionCreate(): void
4256 self ::assertStringContainsString ('main_table. ' , $ mappedName );
4357 }
4458 }
59+
60+ /**
61+ * Verifies that filter condition date is being converted to config timezone before select sql query
62+ *
63+ * @return void
64+ */
65+ public function testAddFieldToFilter (): void
66+ {
67+ $ filterDate = "2021-01-19 00:00:00 " ;
68+ /** @var TimezoneInterface $timeZone */
69+ $ timeZone = $ this ->objectManager ->get (TimezoneInterface::class);
70+ /** @var Collection $gridCollection */
71+ $ gridCollection = $ this ->objectManager ->get (Collection::class);
72+ $ convertedDate = $ timeZone ->convertConfigTimeToUtc ($ filterDate );
73+
74+ $ collection = $ gridCollection ->addFieldToFilter ('created_at ' , ['qteq ' => $ filterDate ]);
75+ $ expectedSelect = "SELECT `main_table`.* FROM `sales_order_grid` AS `main_table` " .
76+ "WHERE (((`main_table`.`created_at` = ' {$ convertedDate }'))) " ;
77+
78+ $ this ->assertEquals ($ expectedSelect , $ collection ->getSelectSql (true ));
79+ }
4580}
0 commit comments