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

YearTest.php « Period « Core « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 191790424e3de1e097b22e9aa636b5a3d2ab840a (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
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
use Piwik\Date;
use Piwik\Translate;

/**
 * Testing Period_Year
 */
class Period_YearTest extends PHPUnit_Framework_TestCase
{
    /**
     * test normal case
     * @group Core
     * @group Period
     * @group Period_Year
     */
    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 Piwik_Period_Year(Date::factory('2024-10-09'));
        $this->assertEquals(12, $year->getNumberOfSubperiods());
        $this->assertEquals($correct, $year->toString());
    }

    /**
     * test past
     * @group Core
     * @group Period
     * @group Period_Year
     */
    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 Piwik_Period_Year(Date::factory('2000-02-15'));
        $this->assertEquals(12, $year->getNumberOfSubperiods());
        $this->assertEquals($correct, $year->toString());
    }

    /**
     * @group Core
     * @group Period
     * @group Period_Year
     */
    public function testGetLocalizedShortString()
    {
        Translate::getInstance()->loadEnglishTranslation();
        $year = new Piwik_Period_Year(Date::factory('2024-10-09'));
        $shouldBe = '2024';
        $this->assertEquals($shouldBe, $year->getLocalizedShortString());
    }

    /**
     * @group Core
     * @group Period
     * @group Period_Year
     */
    public function testGetLocalizedLongString()
    {
        Translate::getInstance()->loadEnglishTranslation();
        $year = new Piwik_Period_Year(Date::factory('2024-10-09'));
        $shouldBe = '2024';
        $this->assertEquals($shouldBe, $year->getLocalizedLongString());
    }

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