From 5a1eab97f54b44f57356b4276b9c9df2a8eef51b Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Sun, 5 Oct 2014 13:05:47 +0200 Subject: refs #5940 put tests in correct folders, better testsuite names, some tests still fail and I cannot figure out why --- tests/PHPUnit/Core/ScheduledTime/DailyTest.php | 170 ------------- tests/PHPUnit/Core/ScheduledTime/HourlyTest.php | 90 ------- tests/PHPUnit/Core/ScheduledTime/MonthlyTest.php | 288 ----------------------- tests/PHPUnit/Core/ScheduledTime/WeeklyTest.php | 195 --------------- 4 files changed, 743 deletions(-) delete mode 100644 tests/PHPUnit/Core/ScheduledTime/DailyTest.php delete mode 100644 tests/PHPUnit/Core/ScheduledTime/HourlyTest.php delete mode 100644 tests/PHPUnit/Core/ScheduledTime/MonthlyTest.php delete mode 100644 tests/PHPUnit/Core/ScheduledTime/WeeklyTest.php (limited to 'tests/PHPUnit/Core/ScheduledTime') diff --git a/tests/PHPUnit/Core/ScheduledTime/DailyTest.php b/tests/PHPUnit/Core/ScheduledTime/DailyTest.php deleted file mode 100644 index 1a62019392..0000000000 --- a/tests/PHPUnit/Core/ScheduledTime/DailyTest.php +++ /dev/null @@ -1,170 +0,0 @@ -setHour(-1); - - } catch (Exception $e) { - return; - } - $this->fail('Expected exception not raised'); - } - - /** - * Tests invalid call to setHour on Daily - */ - public function testSetHourScheduledTimeDailyOver24() - { - try { - $dailySchedule = \Piwik\ScheduledTime::factory('daily'); - $dailySchedule->setHour(25); - } catch (Exception $e) { - return; - } - $this->fail('Expected exception not raised'); - } - - /** - * Tests forbidden call to setDay on Daily - */ - public function testSetDayScheduledTimeDaily() - { - try { - $dailySchedule = \Piwik\ScheduledTime::factory('daily'); - $dailySchedule->setDay(1); - } catch (Exception $e) { - return; - } - $this->fail('Expected exception not raised'); - } - - /** - * Tests getRescheduledTime on Daily with unspecified hour - */ - public function testGetRescheduledTimeDailyUnspecifiedHour() - { - /* - * Test 1 - * - * Context : - * - getRescheduledTime called Friday January 1 1971 09:10:00 UTC - * - setHour is not called, defaulting to midnight - * - * Expected : - * getRescheduledTime returns Saturday January 2 1971 00:00:00 UTC - */ - $mock = $this->getDailyMock(self::$_JANUARY_01_1971_09_10_00); - $this->assertEquals(self::$_JANUARY_02_1971_00_00_00, $mock->getRescheduledTime()); - } - - public function test_setTimezone_ShouldConvertRescheduledTime() - { - $oneHourInSeconds = 3600; - - $mock = $this->getDailyMock(self::$_JANUARY_01_1971_09_10_00); - $timeUTC = $mock->getRescheduledTime(); - $this->assertEquals(self::$_JANUARY_02_1971_00_00_00, $timeUTC); - - $mock->setTimezone('Pacific/Auckland'); - $timeAuckland = $mock->getRescheduledTime(); - $this->assertEquals(-13 * $oneHourInSeconds, $timeAuckland - $timeUTC); - - $mock->setTimezone('America/Los_Angeles'); - $timeLosAngeles = $mock->getRescheduledTime(); - $this->assertEquals(8 * $oneHourInSeconds, $timeLosAngeles - $timeUTC); - } - - /** - * Tests getRescheduledTime on Daily with specified hour - */ - public function testGetRescheduledTimeDailySpecifiedHour() - { - /* - * Test 1 - * - * Context : - * - getRescheduledTime called Friday January 1 1971 09:00:00 UTC - * - setHour is set to 9 - * - * Expected : - * getRescheduledTime returns Saturday January 2 1971 09:00:00 UTC - */ - $mock = $this->getDailyMock(self::$_JANUARY_01_1971_09_00_00); - $mock->setHour(9); - $this->assertEquals(self::$_JANUARY_02_1971_09_00_00, $mock->getRescheduledTime()); - - /* - * Test 2 - * - * Context : - * - getRescheduledTime called Friday January 1 1971 12:10:00 UTC - * - setHour is set to 9 - * - * Expected : - * getRescheduledTime returns Saturday January 2 1971 09:00:00 UTC - */ - - $mock = $this->getDailyMock(self::$_JANUARY_01_1971_12_10_00); - $mock->setHour(9); - $this->assertEquals(self::$_JANUARY_02_1971_09_00_00, $mock->getRescheduledTime()); - - /* - * Test 3 - * - * Context : - * - getRescheduledTime called Friday January 1 1971 12:10:00 UTC - * - setHour is set to 0 - * - * Expected : - * getRescheduledTime returns Saturday January 2 1971 00:00:00 UTC - */ - $mock = $this->getDailyMock(self::$_JANUARY_01_1971_12_10_00); - $mock->setHour(0); - $this->assertEquals(self::$_JANUARY_02_1971_00_00_00, $mock->getRescheduledTime()); - } - - /** - * @param $currentTime - * @return \Piwik\ScheduledTime\Daily - */ - private function getDailyMock($currentTime) - { - $mock = $this->getMock('\Piwik\ScheduledTime\Daily', array('getTime')); - $mock->expects($this->any()) - ->method('getTime') - ->will($this->returnValue($currentTime)); - return $mock; - } -} diff --git a/tests/PHPUnit/Core/ScheduledTime/HourlyTest.php b/tests/PHPUnit/Core/ScheduledTime/HourlyTest.php deleted file mode 100644 index 14f4ce3c0e..0000000000 --- a/tests/PHPUnit/Core/ScheduledTime/HourlyTest.php +++ /dev/null @@ -1,90 +0,0 @@ -setHour(0); - } catch (Exception $e) { - return; - } - $this->fail('Expected exception not raised'); - } - - /** - * Tests forbidden call to setDay on Hourly - * @group Core - */ - public function testSetDayScheduledTimeHourly() - { - try { - $hourlySchedule = new Hourly(); - $hourlySchedule->setDay(1); - } catch (Exception $e) { - return; - } - $this->fail('Expected exception not raised'); - } - - /** - * Tests getRescheduledTime on Hourly - * @group Core - */ - 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()); - } -} diff --git a/tests/PHPUnit/Core/ScheduledTime/MonthlyTest.php b/tests/PHPUnit/Core/ScheduledTime/MonthlyTest.php deleted file mode 100644 index 17bde4ee6d..0000000000 --- a/tests/PHPUnit/Core/ScheduledTime/MonthlyTest.php +++ /dev/null @@ -1,288 +0,0 @@ -setHour(-1); - } - - /** - * Tests invalid call to setHour on Monthly - * @expectedException \Exception - */ - public function testSetHourScheduledTimMonthlyOver24() - { - $monthlySchedule = new Monthly(); - $monthlySchedule->setHour(25); - } - - /** - * Tests invalid call to setDay on Monthly - * @expectedException \Exception - */ - public function testSetDayScheduledTimeMonthlyDay0() - { - $monthlySchedule = new Monthly(); - $monthlySchedule->setDay(0); - } - - /** - * Tests invalid call to setDay on Monthly - * @expectedException \Exception - */ - public function testSetDayScheduledTimeMonthlyOver31() - { - $monthlySchedule = new Monthly(); - $monthlySchedule->setDay(32); - } - - /** - * Tests getRescheduledTime on Monthly with unspecified hour and unspecified day - */ - public function testGetRescheduledTimeMonthlyUnspecifiedHourUnspecifiedDay() - { - /* - * Test 1 - * - * Context : - * - getRescheduledTime called Friday January 1 1971 09:00:00 UTC - * - setHour is not called, defaulting to midnight - * - setDay is not called, defaulting to first day of the month - * - * Expected : - * getRescheduledTime returns Monday February 1 1971 00:00:00 UTC - */ - $mock = $this->getMonthlyMock(self::$_JANUARY_01_1971_09_00_00); - $this->assertEquals(self::$_FEBRUARY_01_1971_00_00_00, $mock->getRescheduledTime()); - - /* - * Test 2 - * - * Context : - * - getRescheduledTime called Tuesday January 5 1971 09:00:00 UTC - * - setHour is not called, defaulting to midnight - * - setDay is not called, defaulting to first day of the month - * - * Expected : - * getRescheduledTime returns Monday February 1 1971 00:00:00 UTC - */ - $mock = $this->getMonthlyMock(self::$_JANUARY_05_1971_09_00_00); - $this->assertEquals(self::$_FEBRUARY_01_1971_00_00_00, $mock->getRescheduledTime()); - } - - public function test_setTimezone_ShouldConvertRescheduledTime() - { - $oneHourInSeconds = 3600; - - $mock = $this->getMonthlyMock(self::$_JANUARY_05_1971_09_00_00); - $timeUTC = $mock->getRescheduledTime(); - $this->assertEquals(self::$_FEBRUARY_01_1971_00_00_00, $timeUTC); - - $mock->setTimezone('Pacific/Auckland'); - $timeAuckland = $mock->getRescheduledTime(); - $this->assertEquals(-13 * $oneHourInSeconds, $timeAuckland - $timeUTC); - - $mock->setTimezone('America/Los_Angeles'); - $timeLosAngeles = $mock->getRescheduledTime(); - $this->assertEquals(8 * $oneHourInSeconds, $timeLosAngeles - $timeUTC); - } - - /** - * Tests getRescheduledTime on Monthly with unspecified hour and specified day - * - * _Monthly - * - * @dataProvider getSpecifiedDayData - */ - public function testGetRescheduledTimeMonthlyUnspecifiedHourSpecifiedDay($currentTime, $day, $expected) - { - $mock = $this->getMonthlyMock(self::$$currentTime); - $mock->setDay($day); - $this->assertEquals(self::$$expected, $mock->getRescheduledTime()); - } - - /** - * DataProvider for testGetRescheduledTimeMonthlyUnspecifiedHourSpecifiedDay - * @return array - */ - public function getSpecifiedDayData() - { - return array( - /* - * Test 1 - * - * Context : - * - getRescheduledTime called Friday January 1 1971 09:00:00 UTC - * - setHour is not called, defaulting to midnight - * - setDay is set to 1 - * - * Expected : - * getRescheduledTime returns Monday February 1 1971 00:00:00 UTC - */ - array('_JANUARY_01_1971_09_00_00', 1, '_FEBRUARY_01_1971_00_00_00'), - /* - * Test 2 - * - * Context : - * - getRescheduledTime called Saturday January 2 1971 09:00:00 UTC - * - setHour is not called, defaulting to midnight - * - setDay is set to 2 - * - * Expected : - * getRescheduledTime returns Tuesday February 2 1971 00:00:00 UTC - */ - array('_JANUARY_02_1971_09_00_00', 2, '_FEBRUARY_02_1971_00_00_00'), - /* - * Test 3 - * - * Context : - * - getRescheduledTime called Friday January 15 1971 09:00:00 UTC - * - setHour is not called, defaulting to midnight - * - setDay is set to 2 - * - * Expected : - * getRescheduledTime returns Tuesday February 1 1971 00:00:00 UTC - */ - array('_JANUARY_15_1971_09_00_00', 2, '_FEBRUARY_02_1971_00_00_00'), - /* - * Test 4 - * - * Context : - * - getRescheduledTime called Friday January 15 1971 09:00:00 UTC - * - setHour is not called, defaulting to midnight - * - setDay is set to 31 - * - * Expected : - * getRescheduledTime returns Sunday February 28 1971 00:00:00 UTC - */ - array('_JANUARY_15_1971_09_00_00', 31, '_FEBRUARY_28_1971_00_00_00') - ); - } - - /** - * Returns the data used to test the setDayOfWeek method. - */ - public function getValuesToTestSetDayOfWeek() - { - return array( - array(3, 0, self::$_FEBRUARY_03_1971_09_00_00), - array(0, 2, self::$_FEBRUARY_21_1971_09_00_00), - ); - } - - /** - * Returns the data used to test the setDayOfWeekFromString method. - */ - public function getValuesToTestSetDayOfWeekByString() - { - return array( - array('first wednesday', self::$_FEBRUARY_03_1971_09_00_00), - array('ThIrD sUnDaY', self::$_FEBRUARY_21_1971_09_00_00) - ); - } - - /** - * @dataProvider getValuesToTestSetDayOfWeek - */ - public function testMonthlyDayOfWeek($day, $week, $expectedTime) - { - $mock = $this->getMonthlyMock(self::$_JANUARY_15_1971_09_00_00); - $mock->setDayOfWeek($day, $week); - $this->assertEquals($expectedTime, $mock->getRescheduledTime()); - } - - /** - * @dataProvider getValuesToTestSetDayOfWeekByString - */ - public function testMonthlyDayOfWeekByString($dayOfWeekStr, $expectedTime) - { - $mock = $this->getMonthlyMock(self::$_JANUARY_15_1971_09_00_00); - $mock->setDayOfWeekFromString($dayOfWeekStr); - $this->assertEquals($expectedTime, $mock->getRescheduledTime()); - } - - /** - * _Monthly - * - * @dataProvider getInvalidDayOfWeekData - * @expectedException \Exception - */ - public function testMonthlyDayOfWeekInvalid($day, $week) - { - $mock = $this->getMonthlyMock(self::$_JANUARY_15_1971_09_00_00); - $mock->setDayOfWeek($day, $week); - } - - /** - * DataProvider for testMonthlyDayOfWeekInvalid - * @return array - */ - public function getInvalidDayOfWeekData() - { - return array( - array(-4, 0), - array(8, 0), - array(0x8, 0), - array('9dd', 0), - array(1, -5), - array(1, 5), - array(1, 0x8), - array(1, '9ff'), - ); - } - - /** - * @param $currentTime - * @return \Piwik\ScheduledTime\Monthly - */ - private function getMonthlyMock($currentTime) - { - $mock = $this->getMock('\Piwik\ScheduledTime\Monthly', array('getTime')); - $mock->expects($this->any()) - ->method('getTime') - ->will($this->returnValue($currentTime)); - - return $mock; - } -} - -ScheduledTime_MonthlyTest::$_JANUARY_01_1971_09_00_00 = mktime(9, 00, 00, 1, 1, 1971); -ScheduledTime_MonthlyTest::$_JANUARY_02_1971_09_00_00 = mktime(9, 00, 00, 1, 2, 1971); -ScheduledTime_MonthlyTest::$_JANUARY_05_1971_09_00_00 = mktime(9, 00, 00, 1, 5, 1971); -ScheduledTime_MonthlyTest::$_JANUARY_15_1971_09_00_00 = mktime(9, 00, 00, 1, 15, 1971); -ScheduledTime_MonthlyTest::$_FEBRUARY_01_1971_00_00_00 = mktime(0, 00, 00, 2, 1, 1971); -ScheduledTime_MonthlyTest::$_FEBRUARY_02_1971_00_00_00 = mktime(0, 00, 00, 2, 2, 1971); -ScheduledTime_MonthlyTest::$_FEBRUARY_03_1971_09_00_00 = mktime(0, 00, 00, 2, 3, 1971); -ScheduledTime_MonthlyTest::$_FEBRUARY_21_1971_09_00_00 = mktime(0, 00, 00, 2, 21, 1971); -ScheduledTime_MonthlyTest::$_FEBRUARY_28_1971_00_00_00 = mktime(0, 00, 00, 2, 28, 1971); \ No newline at end of file diff --git a/tests/PHPUnit/Core/ScheduledTime/WeeklyTest.php b/tests/PHPUnit/Core/ScheduledTime/WeeklyTest.php deleted file mode 100644 index 62b6fce8ed..0000000000 --- a/tests/PHPUnit/Core/ScheduledTime/WeeklyTest.php +++ /dev/null @@ -1,195 +0,0 @@ -setHour(-1); - } catch (Exception $e) { - return; - } - $this->fail('Expected exception not raised'); - } - - /** - * Tests invalid call to setHour on Weekly - */ - public function testSetHourScheduledTimeWeeklyOver24() - { - try { - $weeklySchedule = new Weekly(); - $weeklySchedule->setHour(25); - } catch (Exception $e) { - return; - } - $this->fail('Expected exception not raised'); - } - - /** - * Tests invalid call to setDay on Weekly - */ - public function testSetDayScheduledTimeWeeklyDay0() - { - try { - $weeklySchedule = new Weekly(); - $weeklySchedule->setDay(0); - } catch (Exception $e) { - return; - } - $this->fail('Expected exception not raised'); - } - - /** - * Tests invalid call to setDay on Weekly - */ - public function testSetDayScheduledTimeWeeklyOver7() - { - try { - $weeklySchedule = new Weekly(); - $weeklySchedule->setDay(8); - } catch (Exception $e) { - return; - } - $this->fail('Expected exception not raised'); - } - - /** - * Tests getRescheduledTime on Weekly with unspecified hour and unspecified day - */ - public function testGetRescheduledTimeWeeklyUnspecifiedHourUnspecifiedDay() - { - /* - * Test 1 - * - * Context : - * - getRescheduledTime called Friday January 1 1971 09:10:00 UTC - * - setHour is not called, defaulting to midnight - * - setDay is not called, defaulting to monday - * - * Expected : - * getRescheduledTime returns Monday January 4 1971 00:00:00 UTC - */ - $mock = $this->getWeeklyMock(self::$_JANUARY_01_1971_09_10_00); - $this->assertEquals(self::$_JANUARY_04_1971_00_00_00, $mock->getRescheduledTime()); - } - - /** - * Tests getRescheduledTime on Weekly with specified hour and unspecified day - */ - public function testGetRescheduledTimeWeeklySpecifiedHourUnspecifiedDay() - { - /* - * Test 1 - * - * Context : - * - getRescheduledTime called Friday January 1 1971 09:10:00 UTC - * - setHour is set to 9 - * - setDay is not called, defaulting to monday - * - * Expected : - * getRescheduledTime returns Monday January 4 1971 09:00:00 UTC - */ - $mock = $this->getWeeklyMock(self::$_JANUARY_01_1971_09_10_00); - $mock->setHour(9); - $this->assertEquals(self::$_JANUARY_04_1971_09_00_00, $mock->getRescheduledTime()); - } - - /** - * Returns data used in testGetRescheduledTimeWeeklyUnspecifiedHourSpecifiedDay test. - */ - public function getSetDayParametersToTest() - { - return array( - array(1, self::$_JANUARY_11_1971_00_00_00), - array(5, self::$_JANUARY_08_1971_00_00_00), - array('monday', self::$_JANUARY_11_1971_00_00_00), - array('Monday', self::$_JANUARY_11_1971_00_00_00), - array('FRIDAY', self::$_JANUARY_08_1971_00_00_00), - array('FrIdAy', self::$_JANUARY_08_1971_00_00_00) - ); - } - - public function test_setTimezone_ShouldConvertRescheduledTime() - { - $oneHourInSeconds = 3600; - - $mock = $this->getWeeklyMock(self::$_JANUARY_01_1971_09_10_00); - $timeUTC = $mock->getRescheduledTime(); - $this->assertEquals(self::$_JANUARY_04_1971_00_00_00, $timeUTC); - - $mock->setTimezone('Pacific/Auckland'); - $timeAuckland = $mock->getRescheduledTime(); - $this->assertEquals(-13 * $oneHourInSeconds, $timeAuckland - $timeUTC); - - $mock->setTimezone('America/Los_Angeles'); - $timeLosAngeles = $mock->getRescheduledTime(); - $this->assertEquals(8 * $oneHourInSeconds, $timeLosAngeles - $timeUTC); - } - - /** - * Tests getRescheduledTime on Weekly with unspecified hour and specified day - * - * Context : - * - getRescheduledTime called Monday January 4 1971 09:00:00 UTC - * - setHour is not called, defaulting to midnight - * - setDay is set to $dayToSet - * - * @dataProvider getSetDayParametersToTest - */ - public function testGetRescheduledTimeWeeklyUnspecifiedHourSpecifiedDay($dayToSet, $expectedRescheduledTime) - { - $mock = $this->getWeeklyMock(self::$_JANUARY_04_1971_09_00_00); - $mock->setDay($dayToSet); - - $this->assertEquals($expectedRescheduledTime, $mock->getRescheduledTime()); - } - - /** - * @param $currentTime - * @return \Piwik\ScheduledTime\Weekly - */ - private function getWeeklyMock($currentTime) - { - $mock = $this->getMock('\Piwik\ScheduledTime\Weekly', array('getTime')); - $mock->expects($this->any()) - ->method('getTime') - ->will($this->returnValue($currentTime)); - return $mock; - } -} - -ScheduledTime_WeeklyTest::$_JANUARY_01_1971_09_10_00 = mktime(9, 10, 00, 1, 1, 1971); -ScheduledTime_WeeklyTest::$_JANUARY_04_1971_00_00_00 = mktime(0, 00, 00, 1, 4, 1971); -ScheduledTime_WeeklyTest::$_JANUARY_04_1971_09_00_00 = mktime(9, 00, 00, 1, 4, 1971); -ScheduledTime_WeeklyTest::$_JANUARY_05_1971_09_00_00 = mktime(9, 00, 00, 1, 5, 1971); -ScheduledTime_WeeklyTest::$_JANUARY_11_1971_00_00_00 = mktime(0, 00, 00, 1, 11, 1971); -ScheduledTime_WeeklyTest::$_JANUARY_15_1971_00_00_00 = mktime(0, 00, 00, 1, 15, 1971); -ScheduledTime_WeeklyTest::$_JANUARY_08_1971_00_00_00 = mktime(0, 00, 00, 1, 8, 1971); \ No newline at end of file -- cgit v1.2.3