7
7
8
8
namespace Magento \Backend \Model \Dashboard ;
9
9
10
+ use Magento \Framework \ObjectManagerInterface ;
10
11
use Magento \TestFramework \Helper \Bootstrap ;
11
12
use PHPUnit \Framework \TestCase ;
13
+ use Magento \Sales \Model \Order ;
14
+ use Magento \Sales \Model \Order \Payment ;
15
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
16
+ use Magento \Framework \Stdlib \DateTime ;
12
17
13
18
/**
14
19
* Verify chart data by different period.
17
22
*/
18
23
class ChartTest extends TestCase
19
24
{
25
+ /**
26
+ * @var ObjectManagerInterface
27
+ */
28
+ private $ objectManager ;
29
+
20
30
/**
21
31
* @var Chart
22
32
*/
@@ -27,7 +37,8 @@ class ChartTest extends TestCase
27
37
*/
28
38
protected function setUp (): void
29
39
{
30
- $ this ->model = Bootstrap::getObjectManager ()->create (Chart::class);
40
+ $ this ->objectManager = Bootstrap::getObjectManager ();
41
+ $ this ->model = $ this ->objectManager ->get (Chart::class);
31
42
}
32
43
33
44
/**
@@ -39,6 +50,20 @@ protected function setUp(): void
39
50
*/
40
51
public function testGetByPeriodWithParam (int $ expectedDataQty , string $ period , string $ chartParam ): void
41
52
{
53
+ $ timezoneLocal = $ this ->objectManager ->get (TimezoneInterface::class)->getConfigTimezone ();
54
+ $ order = $ this ->objectManager ->get (Order::class);
55
+ $ order ->loadByIncrementId ('100000002 ' );
56
+ $ payment = $ this ->objectManager ->get (Payment::class);
57
+ $ payment ->setMethod ('checkmo ' );
58
+ $ payment ->setAdditionalInformation ('last_trans_id ' , '11122 ' );
59
+ $ payment ->setAdditionalInformation ('metadata ' , [
60
+ 'type ' => 'free ' ,
61
+ 'fraudulent ' => false
62
+ ]);
63
+ $ dateTime = new \DateTime ('now ' , new \DateTimeZone ($ timezoneLocal ));
64
+ $ order ->setCreatedAt ($ dateTime ->modify ('-1 hour ' )->format (DateTime::DATETIME_PHP_FORMAT ));
65
+ $ order ->setPayment ($ payment );
66
+ $ order ->save ();
42
67
$ ordersData = $ this ->model ->getByPeriod ($ period , $ chartParam );
43
68
$ ordersCount = array_sum (array_map (function ($ item ) {
44
69
return $ item ['y ' ];
@@ -70,12 +95,12 @@ public function getChartDataProvider(): array
70
95
'quantity '
71
96
],
72
97
[
73
- 4 ,
98
+ 5 ,
74
99
'1y ' ,
75
100
'quantity '
76
101
],
77
102
[
78
- 5 ,
103
+ 6 ,
79
104
'2y ' ,
80
105
'quantity '
81
106
]
0 commit comments