7
7
8
8
namespace Magento \Sales \Model \ResourceModel \Order \Grid ;
9
9
10
+ use Magento \Framework \ObjectManagerInterface ;
11
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
10
12
use Magento \TestFramework \Helper \Bootstrap ;
13
+ use PHPUnit \Framework \TestCase ;
11
14
12
- class CollectionTest extends \ PHPUnit \ Framework \ TestCase
15
+ class CollectionTest extends TestCase
13
16
{
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
+
14
30
/**
15
31
* Tests collection properties.
16
32
*
@@ -19,10 +35,8 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
19
35
*/
20
36
public function testCollectionCreate (): void
21
37
{
22
- $ objectManager = Bootstrap::getObjectManager ();
23
-
24
38
/** @var Collection $gridCollection */
25
- $ gridCollection = $ objectManager ->get (Collection::class);
39
+ $ gridCollection = $ this -> objectManager ->get (Collection::class);
26
40
$ tableDescription = $ gridCollection ->getConnection ()
27
41
->describeTable ($ gridCollection ->getMainTable ());
28
42
@@ -42,4 +56,25 @@ public function testCollectionCreate(): void
42
56
self ::assertStringContainsString ('main_table. ' , $ mappedName );
43
57
}
44
58
}
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
+ }
45
80
}
0 commit comments