1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\VisitTime\tests\Unit;
use Piwik\DataTable\Row;
use Piwik\DataTable;
/**
* @group VisitTime
* @group AddSegmentByLabelInUTCTest
* @group Plugins
*/
class AddSegmentByLabelInUTCTest extends \PHPUnit\Framework\TestCase
{
private $filter = 'Piwik\Plugins\VisitTime\DataTable\Filter\AddSegmentByLabelInUTC';
/**
* @var DataTable
*/
private $table;
public function setUp(): void
{
$this->table = new DataTable();
$this->addRow(array('label' => '0'));
$this->addRow(array('label' => '1'));
$this->addRow(array('label' => '2'));
$this->addRow(array('label' => '12'));
$this->addRow(array('label' => '13'));
$this->addRow(array('label' => '14'));
$this->addRow(array('label' => '20'));
}
private function addRow($columns)
{
$this->table->addRow($this->buildRow($columns));
}
private function buildRow($columns)
{
return new Row(array(Row::COLUMNS => $columns));
}
public function test_filter_shouldNotChangeHoursIfTimezoneIsUTCAlready()
{
$this->table->filter($this->filter, array('UTC', 'day', 'today'));
$this->assertSegmentValues(array('0', '1', '2', '12', '13', '14', '20'));
}
public function test_filter_shouldConvertHoursFromTimezoneIntoUTC_Minus1()
{
$this->table->filter($this->filter, array('UTC-1', 'day', 'today'));
$this->assertSegmentValues(array('1', '2', '3', '13', '14', '15', '21'));
}
public function test_filter_shouldConvertHoursFromTimezoneIntoUTC_Plus1()
{
$this->table->filter($this->filter, array('UTC+1', 'day', 'today'));
$this->assertSegmentValuesInUTCplus1();
}
public function test_filter_shouldHandleRangePeriod_Plus1()
{
$this->table->filter($this->filter, array('UTC+1', 'range', '2015-02-02,2015-02-14'));
$this->assertSegmentValuesInUTCplus1();
}
public function test_filter_shouldHandleRangePeriodWithLast7_Plus1()
{
$this->table->filter($this->filter, array('UTC+1', 'range', 'last7'));
$this->assertSegmentValuesInUTCplus1();
}
public function test_filter_shouldHandleDayPeriodWithRange_Plus1()
{
$this->table->filter($this->filter, array('UTC+1', 'day', '2015-02-02,2015-02-14'));
$this->assertSegmentValuesInUTCplus1();
}
public function test_filter_shouldHandleWeekWithLast7_Plus1()
{
$this->table->filter($this->filter, array('UTC+1', 'day', 'last7'));
$this->assertSegmentValuesInUTCplus1();
}
public function test_filter_shouldIgnoreSummaryRow()
{
$row = $this->buildRow(array('label' => 'other'));
$this->table->addSummaryRow($row);
$this->table->filter($this->filter, array('UTC', 'day', 'today'));
$this->assertFalse($row->getMetadata('segmentValue'));
}
private function assertSegmentValuesInUTCplus1()
{
$this->assertSegmentValues(array('23', '0', '1', '11', '12', '13', '19'));
}
private function assertSegmentValues($expectedSegmentValues)
{
$segmentValues = $this->table->getRowsMetadata('segmentValue');
$this->assertSame($expectedSegmentValues, $segmentValues);
}
}
|