Welcome to mirror list, hosted at ThFree Co, Russian Federation.

YearTest.php « Period « Unit « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d6d58959593c3b343b832fd6e42e101aededd485 (plain)
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
<?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\Year;

class YearTest extends BasePeriodTest
{
    /**
     * test normal case
     * @group Core
     */
    public function testYearNormalcase()
    {
        $correct = array(
            '2024-01-01',
            '2024-02-01',
            '2024-03-01',
            '2024-04-01',
            '2024-05-01',
            '2024-06-01',
            '2024-07-01',
            '2024-08-01',
            '2024-09-01',
            '2024-10-01',
            '2024-11-01',
            '2024-12-01',);

        $year = new Year(Date::factory('2024-10-09'));
        $this->assertEquals(12, $year->getNumberOfSubperiods());
        $this->assertEquals($correct, $year->toString());
    }

    /**
     * test past
     * @group Core
     */
    public function testYearPastAndWrongdate()
    {
        $correct = array(
            '2000-01-01',
            '2000-02-01',
            '2000-03-01',
            '2000-04-01',
            '2000-05-01',
            '2000-06-01',
            '2000-07-01',
            '2000-08-01',
            '2000-09-01',
            '2000-10-01',
            '2000-11-01',
            '2000-12-01',
        );

        $year = new Year(Date::factory('2000-02-15'));
        $this->assertEquals(12, $year->getNumberOfSubperiods());
        $this->assertEquals($correct, $year->toString());
    }

    public function getLocalizedShortStrings()
    {
        return array(
            array('en', '2024'),
            array('ko', '2024년'),
            array('zh-cn', '2024年'),
        );
    }

    /**
     * @group Core
     * @group Year
     * @dataProvider getLocalizedShortStrings
     */
    public function testGetLocalizedShortString($language, $shouldBe)
    {
        StaticContainer::get('Piwik\Translation\Translator')->setCurrentLanguage($language);

        $year = new Year(Date::factory('2024-10-09'));
        $this->assertEquals($shouldBe, $year->getLocalizedShortString());
    }

    public function getLocalizedLongStrings()
    {
        return array(
            array('en', '2024'),
            array('ko', '2024년'),
            array('zh-cn', '2024年'),
        );
    }

    /**
     * @group Core
     * @group Year
     * @dataProvider getLocalizedLongStrings
     */

    public function testGetLocalizedLongString($language, $shouldBe)
    {
        StaticContainer::get('Piwik\Translation\Translator')->setCurrentLanguage($language);

        $year = new Year(Date::factory('2024-10-09'));
        $this->assertEquals($shouldBe, $year->getLocalizedLongString());
    }

    /**
     * @group Core
     */
    public function testGetPrettyString()
    {
        $year = new Year(Date::factory('2024-10-09'));
        $shouldBe = '2024';
        $this->assertEquals($shouldBe, $year->getPrettyString());
    }
}