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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Unit\Period;
use Piwik\Container\StaticContainer;
use Piwik\Date;
use Piwik\Period\Week;
/**
* Class WeekTest
* @package Piwik\Tests\Unit\Period
* @group WeekTest
*/
class WeekTest extends BasePeriodTest
{
/**
* test week between 2 years
* @group Core
*/
public function testWeekBetween2years()
{
$week = new Week(Date::factory("2006-01-01"));
$correct = array(
"2005-12-26",
"2005-12-27",
"2005-12-28",
"2005-12-29",
"2005-12-30",
"2005-12-31",
"2006-01-01",);
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
}
/**
* test week between 2 months Week Mai 29 To Mai 31 2006
* @group Core
*/
public function testWeekBetween2month()
{
$week = new Week(Date::factory("2006-05-29"));
$correct = array(
"2006-05-29",
"2006-05-30",
"2006-05-31",
"2006-06-01",
"2006-06-02",
"2006-06-03",
"2006-06-04",);
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
}
/**
* test week between feb and march for leap year
* @group Core
*/
public function testWeekFebLeapyear()
{
$correct = array(
'2023-02-27',
'2023-02-28',
'2023-03-01',
'2023-03-02',
'2023-03-03',
'2023-03-04',
'2023-03-05',);
$week = new Week(Date::factory('2023-02-27'));
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
$week = new Week(Date::factory('2023-03-01'));
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
}
/**
* test week between feb and march for no leap year
* @group Core
*/
public function testWeekFebnonLeapyear()
{
$correct = array(
'2024-02-26',
'2024-02-27',
'2024-02-28',
'2024-02-29',
'2024-03-01',
'2024-03-02',
'2024-03-03',);
$week = new Week(Date::factory('2024-02-27'));
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
$week = new Week(Date::factory('2024-03-01'));
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
}
/**
* test week normal middle of the month
* @group Core
*/
public function testWeekMiddleofmonth()
{
$correct = array(
'2024-10-07',
'2024-10-08',
'2024-10-09',
'2024-10-10',
'2024-10-11',
'2024-10-12',
'2024-10-13',);
$week = new Week(Date::factory('2024-10-09'));
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
}
public function getLocalizedShortStrings()
{
return array(
array('en', array('Oct 7 – 13, 2024', 'Nov 25 – Dec 1, 2024', 'Dec 30, 2024 – Jan 5, 2025')),
array('lt', array('2024 spal. 7–13', '2024 lapkr. 25 – gruod. 1', '2024 gruod. 30 – 2025 saus. 5')),
array('zh-cn', array('2024年10月7日至13日', '2024年11月25日至12月1日', '2024年12月30日至2025年01月5日')),
);
}
/**
* @group Core
* @dataProvider getLocalizedShortStrings
*/
public function testGetLocalizedShortString($language, $shouldBe)
{
StaticContainer::get('Piwik\Translation\Translator')->setCurrentLanguage($language);
// a week within a month
$week = new Week(Date::factory('2024-10-09'));
$this->assertEquals($shouldBe[0], $week->getLocalizedShortString());
// a week ending in another month
$week = new Week(Date::factory('2024-12-01'));
$this->assertEquals($shouldBe[1], $week->getLocalizedShortString());
// a week ending in another year
$week = new Week(Date::factory('2024-12-31'));
$this->assertEquals($shouldBe[2], $week->getLocalizedShortString());
}
public function getLocalizedLongStrings()
{
return array(
array('en', array('week October 7 – 13, 2024', 'week November 25 – December 1, 2024', 'week December 30, 2024 – January 5, 2025')),
array('es', array('semana 7–13 de octubre de 2024', 'semana 25 de noviembre–1 de diciembre de 2024', 'semana 30 de diciembre de 2024–5 de enero de 2025')),
array('lt', array('savaitė 2024 spalio 7–13', 'savaitė 2024 lapkričio 25 – gruodžio 1', 'savaitė 2024 gruodžio 30 – 2025 sausio 5')),
array('zh-cn', array('周 2024年10月7日至13日', '周 2024年11月25日至12月1日', '周 2024年12月30日至2025年01月5日')),
);
}
/**
* @group Core
* @dataProvider getLocalizedLongStrings
*/
public function testGetLocalizedLongString($language, $shouldBe)
{
StaticContainer::get('Piwik\Translation\Translator')->setCurrentLanguage($language);
// a week within a month
$week = new Week(Date::factory('2024-10-09'));
$this->assertEquals($shouldBe[0], $week->getLocalizedLongString());
// a week ending in another month
$week = new Week(Date::factory('2024-12-01'));
$this->assertEquals($shouldBe[1], $week->getLocalizedLongString());
// a week ending in another year
$week = new Week(Date::factory('2024-12-31'));
$this->assertEquals($shouldBe[2], $week->getLocalizedLongString());
}
/**
* @group Core
*/
public function testGetPrettyString()
{
$week = new Week(Date::factory('2024-10-09'));
$shouldBe = 'From 2024-10-07 to 2024-10-13';
$this->assertEquals($shouldBe, $week->getPrettyString());
}
}
|