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

HourlyTest.php « ScheduledTime « Core « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b0c808fe5e494632c9553fc04d452944198b2990 (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
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
class ScheduledTime_HourlyTest extends PHPUnit_Framework_TestCase
{
    private static $_JANUARY_01_1971_09_00_00;
    private static $_JANUARY_01_1971_09_10_00;
    private static $_JANUARY_01_1971_10_00_00;

    public static function setUpBeforeClass()
    {
        parent::setUpBeforeClass();
        self::$_JANUARY_01_1971_09_00_00 = mktime(9, 00, 00, 1, 1, 1971);
        self::$_JANUARY_01_1971_09_10_00 = mktime(9, 10, 00, 1, 1, 1971);
        self::$_JANUARY_01_1971_10_00_00 = mktime(10, 00, 00, 1, 1, 1971);
    }

    /**
     * Tests forbidden call to setHour on Piwik_ScheduledTime_Hourly
     * @group Core
     * @group ScheduledTime
     * @group ScheduledTime_Hourly
     */
    public function testSetHourScheduledTimeHourly()
    {
        try {
            $hourlySchedule = new Piwik_ScheduledTime_Hourly();
            $hourlySchedule->setHour(0);
        } catch (Exception $e) {
            return;
        }
        $this->fail('Expected exception not raised');
    }

    /**
     * Tests forbidden call to setDay on Piwik_ScheduledTime_Hourly
     * @group Core
     * @group ScheduledTime
     * @group ScheduledTime_Hourly
     */
    public function testSetDayScheduledTimeHourly()
    {
        try {
            $hourlySchedule = new Piwik_ScheduledTime_Hourly();
            $hourlySchedule->setDay(1);
        } catch (Exception $e) {
            return;
        }
        $this->fail('Expected exception not raised');
    }

    /**
     * Tests getRescheduledTime on Piwik_ScheduledTime_Hourly
     * @group Core
     * @group ScheduledTime
     * @group ScheduledTime_Hourly
     */
    public function testGetRescheduledTimeHourly()
    {
        /*
         * Test 1
         *
         * Context :
         *  - getRescheduledTime called Friday January 1 1971 09:00:00 GMT
         *
         * Expected :
         *  getRescheduledTime returns Friday January 1 1971 10:00:00 GMT
         */
        $mock = $this->getMock('Piwik_ScheduledTime_Hourly', array('getTime'));
        $mock->expects($this->any())
            ->method('getTime')
            ->will($this->returnValue(self::$_JANUARY_01_1971_09_00_00));
        $this->assertEquals(self::$_JANUARY_01_1971_10_00_00, $mock->getRescheduledTime());

        /*
         * Test 2
         *
         * Context :
         *  - getRescheduledTime called Friday January 1 1971 09:10:00 GMT
         *
         * Expected :
         *  getRescheduledTime returns Friday January 1 1971 10:00:00 GMT
         */
        $mock = $this->getMock('Piwik_ScheduledTime_Hourly', array('getTime'));
        $mock->expects($this->any())
            ->method('getTime')
            ->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
        $this->assertEquals(self::$_JANUARY_01_1971_10_00_00, $mock->getRescheduledTime());
    }
}