From dc4c9bfd0b381325ca1f6d7b3a506e1149c0280c Mon Sep 17 00:00:00 2001 From: mattab <matthieu.aubry@gmail.com> Date: Fri, 1 Nov 2013 15:01:21 +1300 Subject: [PATCH] Adding failing test for date range --- plugins/SecurityInfo | 2 +- plugins/TreemapVisualization | 2 +- plugins/VisitorGenerator | 2 +- tests/PHPUnit/Core/Period/RangeTest.php | 88 +++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/plugins/SecurityInfo b/plugins/SecurityInfo index a5e2f32fa4..fd8f764b9b 160000 --- a/plugins/SecurityInfo +++ b/plugins/SecurityInfo @@ -1 +1 @@ -Subproject commit a5e2f32fa4c807c351b0a726ee28a181b56fe7c9 +Subproject commit fd8f764b9b6af55ed821aa6737a88d43ba3e76ac diff --git a/plugins/TreemapVisualization b/plugins/TreemapVisualization index 876fd8f0b7..23bcdfb58d 160000 --- a/plugins/TreemapVisualization +++ b/plugins/TreemapVisualization @@ -1 +1 @@ -Subproject commit 876fd8f0b74f9e1e86541971bb3d9b6f047f19ff +Subproject commit 23bcdfb58df084b6f579c64f5c504c4d108d1e3f diff --git a/plugins/VisitorGenerator b/plugins/VisitorGenerator index b2615047a8..924b69d524 160000 --- a/plugins/VisitorGenerator +++ b/plugins/VisitorGenerator @@ -1 +1 @@ -Subproject commit b2615047a824237433ac55286a12cb2389c9a9e3 +Subproject commit 924b69d524edea4a326216fe6de7a8df7e9a9ddc diff --git a/tests/PHPUnit/Core/Period/RangeTest.php b/tests/PHPUnit/Core/Period/RangeTest.php index 74c350b51b..d386ec2b99 100644 --- a/tests/PHPUnit/Core/Period/RangeTest.php +++ b/tests/PHPUnit/Core/Period/RangeTest.php @@ -417,6 +417,94 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase $this->assertEquals($correct, $range->toString()); } + /** + * @group Core + */ + public function testRangePreviousmonth_onLastDayOfMonth() + { + $end = Date::factory('2013-10-31'); + $range = new Range('month', 'previous10', 'UTC', $end); + $end = $end->subMonth(1); + + $correct = array(); + for ($i = 0; $i < 10; $i++) { + $date = $end->subMonth($i); + $week = new Month($date); + + $correct[] = $week->toString(); + } + $correct = array_reverse($correct); + + $this->assertEquals(10, $range->getNumberOfSubperiods()); + $this->assertEquals($correct, $range->toString()); + } + + /** + * @group Core + */ + public function testRangeLastmonth_onLastDayOfMonth() + { + $end = Date::factory('2013-10-31'); + $range = new Range('month', 'last10', 'UTC', $end); + + $correct = array(); + for ($i = 0; $i < 10; $i++) { + $date = $end->subMonth($i); + $week = new Month($date); + + $correct[] = $week->toString(); + } + $correct = array_reverse($correct); + + $this->assertEquals(10, $range->getNumberOfSubperiods()); + $this->assertEquals($correct, $range->toString()); + } + + /** + * @group Core + */ + public function _testRangePreviousmonth_onFirstOfMonth() + { + $end = Date::factory('2013-11-01'); + $range = new Range('month', 'previous10', 'UTC', $end); + $end = $end->subMonth(1); + + $correct = array(); + for ($i = 0; $i < 10; $i++) { + $date = $end->subMonth($i); + $week = new Month($date); + + $correct[] = $week->toString(); + } + $correct = array_reverse($correct); + + + $this->assertEquals(10, $range->getNumberOfSubperiods()); + $this->assertEquals($correct, $range->toString()); + } + + /** + * @group Core + */ + public function _testRangeLastmonth_onFirstOfMonth() + { + $end = Date::factory('2013-11-01'); + $range = new Range('month', 'last10', 'UTC', $end); + + $correct = array(); + for ($i = 0; $i < 10; $i++) { + $date = $end->subMonth($i); + $week = new Month($date); + + $correct[] = $week->toString(); + } + $correct = array_reverse($correct); + + + $this->assertEquals(10, $range->getNumberOfSubperiods()); + $this->assertEquals($correct, $range->toString()); + } + // test range YEAR /** * @group Core -- GitLab