Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class DataTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $data;
17 
21  protected $contextMock;
22 
26  protected $itemFactoryMock;
27 
31  protected function setUp()
32  {
33  $this->contextMock = $this->getMockBuilder(\Magento\Framework\App\Helper\Context::class)
34  ->disableOriginalConstructor()
35  ->getMock();
36  $this->itemFactoryMock = $this->getMockBuilder(\Magento\Reports\Model\ItemFactory::class)
37  ->setMethods(['create'])
38  ->disableOriginalConstructor()
39  ->getMock();
40 
41  $this->data = new Data(
42  $this->contextMock,
43  $this->itemFactoryMock
44  );
45  }
46 
55  public function testGetIntervals($from, $to, $period, $results)
56  {
57  $this->assertEquals($this->data->getIntervals($from, $to, $period), $results);
58  }
59 
68  public function testPrepareIntervalsCollection($from, $to, $period, $results)
69  {
70  $collection = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
71  ->disableOriginalConstructor()
72  ->setMethods(['addItem'])
73  ->getMock();
74 
75  $item = $this->getMockBuilder(\Magento\Reports\Model\Item::class)
76  ->disableOriginalConstructor()
77  ->setMethods(['setPeriod', 'setIsEmpty'])
78  ->getMock();
79 
80  $this->itemFactoryMock->expects($this->exactly(count($results)))
81  ->method('create')
82  ->willReturn($item);
83  $item->expects($this->exactly(count($results)))
84  ->method('setIsEmpty');
85  $collection->expects($this->exactly(count($results)))
86  ->method('addItem');
87 
88  foreach ($results as $key => $result) {
89  $item->expects($this->at($key + $key))
90  ->method('setPeriod')
91  ->with($result);
92  }
93 
94  $this->data->prepareIntervalsCollection($collection, $from, $to, $period);
95  }
96 
100  public function intervalsDataProvider()
101  {
102  return [
103  [
104  'from' => '2000-01-15 10:00:00',
105  'to' => '2000-01-15 11:00:00',
107  'results' => ['2000-01-15']
108  ],
109  [
110  'from' => '2000-01-15 10:00:00',
111  'to' => '2000-01-17 10:00:00',
113  'results' => ['2000-01']
114  ],
115  [
116  'from' => '2000-01-15 10:00:00',
117  'to' => '2000-02-15 10:00:00',
119  'results' => ['2000']
120  ],
121  [
122  'from' => '2000-01-15 10:00:00',
123  'to' => '2000-01-16 11:00:00',
125  'results' => ['2000-01-15', '2000-01-16']
126  ],
127  [
128  'from' => '2000-01-15 10:00:00',
129  'to' => '2000-02-17 10:00:00',
131  'results' => ['2000-01', '2000-02']
132  ],
133  [
134  'from' => '2000-01-15 10:00:00',
135  'to' => '2003-02-15 10:00:00',
137  'results' => ['2000', '2001', '2002', '2003']
138  ],
139  [
140  'from' => '',
141  'to' => '',
143  'results' => []
144  ]
145  ];
146  }
147 }
$results
Definition: popup.phtml:13
testGetIntervals($from, $to, $period, $results)
Definition: DataTest.php:55
const REPORT_PERIOD_TYPE_MONTH
Definition: Data.php:23
testPrepareIntervalsCollection($from, $to, $period, $results)
Definition: DataTest.php:68