From 70980e5d45a4935504deeeaed05439f9fb6f7bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gedas=20Luko=C5=A1ius?= Date: Tue, 17 Oct 2017 01:13:58 +0300 Subject: [PATCH 1/6] Add provider for official Estonia holidays --- src/Yasumi/Provider/Estonia.php | 113 ++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/Yasumi/Provider/Estonia.php diff --git a/src/Yasumi/Provider/Estonia.php b/src/Yasumi/Provider/Estonia.php new file mode 100644 index 000000000..8aa2badd3 --- /dev/null +++ b/src/Yasumi/Provider/Estonia.php @@ -0,0 +1,113 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Holiday; + +/** + * Provider for all holidays in Estonia. + * + * @author Gedas Lukošius + */ +class Estonia extends AbstractProvider +{ + use CommonHolidays, ChristianHolidays; + + const DECLARATION_OF_INDEPENDENCE_YEAR = 1918; + + const VICTORY_DAY_START_YEAR = 1934; + + const RESTORATION_OF_INDEPENDENCE_YEAR = 1991; + + /** + * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + const ID = 'EE'; + + /** + * Initialize holidays for Estonia. + * + * @throws \InvalidArgumentException + */ + public function initialize() + { + $this->timezone = 'Europe/Tallinn'; + + // Official + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addIndependenceDay(); + $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale)); + $this->addVictoryDay(); + $this->addHoliday($this->stJohnsDay($this->year, $this->timezone, $this->locale)); + $this->addRestorationOfIndependenceDay(); + $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); + } + + /** + * @throws \InvalidArgumentException + */ + private function addIndependenceDay() + { + if ($this->year >= self::DECLARATION_OF_INDEPENDENCE_YEAR) { + $this->addHoliday(new Holiday( + 'independenceDay', + [ + 'en_US' => 'Independence Day', + 'et_EE' => 'Iseseisvuspäev' + ], + new \DateTime("{$this->year}-02-24", new \DateTimeZone($this->timezone)) + )); + } + } + + /** + * @throws \InvalidArgumentException + */ + private function addVictoryDay() + { + if ($this->year >= self::VICTORY_DAY_START_YEAR) { + $this->addHoliday(new Holiday( + 'victoryDay', + [ + 'en_US' => 'Victory Day', + 'et_EE' => 'Võidupüha' + ], + new \DateTime("{$this->year}-06-23", new \DateTimeZone($this->timezone)) + )); + } + } + + /** + * @throws \InvalidArgumentException + */ + private function addRestorationOfIndependenceDay() + { + if ($this->year >= self::RESTORATION_OF_INDEPENDENCE_YEAR) { + $this->addHoliday(new Holiday( + 'restorationOfIndependenceDay', + [ + 'en_US' => 'Day of Restoration of Independence', + 'et_EE' => 'Tasiseseisvumispäev' + ], + new \DateTime("{$this->year}-08-20", new \DateTimeZone($this->timezone)) + )); + } + } +} From 37ed47c8dcf5d42ca58a85aa21da12186a3ac34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gedas=20Luko=C5=A1ius?= Date: Tue, 17 Oct 2017 01:23:24 +0300 Subject: [PATCH 2/6] Add translations for official Estonia holidays --- src/Yasumi/data/translations/christmasDay.php | 1 + src/Yasumi/data/translations/christmasEve.php | 1 + src/Yasumi/data/translations/easter.php | 1 + src/Yasumi/data/translations/goodFriday.php | 1 + src/Yasumi/data/translations/internationalWorkersDay.php | 1 + src/Yasumi/data/translations/newYearsDay.php | 1 + src/Yasumi/data/translations/pentecost.php | 1 + src/Yasumi/data/translations/secondChristmasDay.php | 1 + src/Yasumi/data/translations/stJohnsDay.php | 1 + 9 files changed, 9 insertions(+) diff --git a/src/Yasumi/data/translations/christmasDay.php b/src/Yasumi/data/translations/christmasDay.php index cbe3a6f81..5f121fbfd 100755 --- a/src/Yasumi/data/translations/christmasDay.php +++ b/src/Yasumi/data/translations/christmasDay.php @@ -25,6 +25,7 @@ 'en_US' => 'Christmas', 'en_ZA' => 'Christmas Day', 'es_ES' => 'Navidad', + 'et_EE' => 'Esimene jõulupüha', 'fi_FI' => 'Joulupäivä', 'fr_CH' => 'Noël', 'fr_FR' => 'Noël', diff --git a/src/Yasumi/data/translations/christmasEve.php b/src/Yasumi/data/translations/christmasEve.php index 6ab6a8235..11a255991 100755 --- a/src/Yasumi/data/translations/christmasEve.php +++ b/src/Yasumi/data/translations/christmasEve.php @@ -16,6 +16,7 @@ 'cy_GB' => 'Noswyl Nadolig', 'de_CH' => 'Heiliger Abend', 'en_US' => 'Christmas Eve', + 'et_EE' => 'Jõululaupäev', 'fr_CH' => 'Réveillon de Noël', 'it_CH' => 'Vigilia di Natale', 'pt_PT' => 'Véspera de Natal', diff --git a/src/Yasumi/data/translations/easter.php b/src/Yasumi/data/translations/easter.php index 051fa43f7..52134e8e9 100644 --- a/src/Yasumi/data/translations/easter.php +++ b/src/Yasumi/data/translations/easter.php @@ -20,6 +20,7 @@ 'el_GR' => 'Κυριακή του Πάσχα', 'en_IE' => 'Easter Sunday', 'en_US' => 'Easter Sunday', + 'et_EE' => 'Ülestõusmispühade 1. püha', 'fi_FI' => 'Pääsiäispäivä', 'fr_CH' => 'Pâques', 'ga_IE' => 'Domhnach Cásca', diff --git a/src/Yasumi/data/translations/goodFriday.php b/src/Yasumi/data/translations/goodFriday.php index afafb5c5a..78be4987b 100644 --- a/src/Yasumi/data/translations/goodFriday.php +++ b/src/Yasumi/data/translations/goodFriday.php @@ -25,6 +25,7 @@ 'en_US' => 'Good Friday', 'en_ZA' => 'Good Friday', 'es_ES' => 'Viernes Santo', + 'et_EE' => 'Suur Reede', 'fi_FI' => 'Pitkäperjantai', 'fr_CH' => 'Vendredi Saint', 'fr_FR' => 'Vendredi saint', diff --git a/src/Yasumi/data/translations/internationalWorkersDay.php b/src/Yasumi/data/translations/internationalWorkersDay.php index 19efff19c..3a6388bf5 100755 --- a/src/Yasumi/data/translations/internationalWorkersDay.php +++ b/src/Yasumi/data/translations/internationalWorkersDay.php @@ -20,6 +20,7 @@ 'en_US' => 'International Workers\' Day', 'en_ZA' => 'Workers\' Day', 'es_ES' => 'Día del Trabajador', + 'et_EE' => 'Kevadpüha', 'fi_FI' => 'Vappu', 'fr_CH' => 'Fête du Travail', 'fr_FR' => 'Fête du Travail', diff --git a/src/Yasumi/data/translations/newYearsDay.php b/src/Yasumi/data/translations/newYearsDay.php index b07049974..09142076f 100755 --- a/src/Yasumi/data/translations/newYearsDay.php +++ b/src/Yasumi/data/translations/newYearsDay.php @@ -26,6 +26,7 @@ 'en_US' => 'New Year\'s Day', 'en_ZA' => 'New Year\'s Day', 'es_ES' => 'Año Nuevo', + 'et_EE' => 'Uusaasta', 'fi_FI' => 'Uudenvuodenpäivä', 'fr_CH' => 'Nouvel An', 'fr_FR' => 'Jour de l\'An', diff --git a/src/Yasumi/data/translations/pentecost.php b/src/Yasumi/data/translations/pentecost.php index 81e21e65f..0844eb10c 100755 --- a/src/Yasumi/data/translations/pentecost.php +++ b/src/Yasumi/data/translations/pentecost.php @@ -19,6 +19,7 @@ 'el_GR' => 'Πεντηκοστή', 'en_IE' => 'Whitsunday', 'en_US' => 'Whitsunday', + 'et_EE' => 'Nelipühade 1. püha', 'fi_FI' => 'Helluntaipäivä', 'fr_CH' => 'Pentecôte', 'ga_IE' => 'Domhnach Cincíse', diff --git a/src/Yasumi/data/translations/secondChristmasDay.php b/src/Yasumi/data/translations/secondChristmasDay.php index 7f329f1ce..f316ccd74 100755 --- a/src/Yasumi/data/translations/secondChristmasDay.php +++ b/src/Yasumi/data/translations/secondChristmasDay.php @@ -22,6 +22,7 @@ 'en_NZ' => 'Boxing Day', 'en_US' => 'Second Christmas Day', 'en_ZA' => 'Day of Goodwill', + 'et_EE' => 'Teine Jõulupüha', 'fi_FI' => '2. joulupäivä', 'hu_HU' => 'Karácsony másnapja', 'nb_NO' => 'Andre juledag', diff --git a/src/Yasumi/data/translations/stJohnsDay.php b/src/Yasumi/data/translations/stJohnsDay.php index 89a0e4e0b..a6961b639 100644 --- a/src/Yasumi/data/translations/stJohnsDay.php +++ b/src/Yasumi/data/translations/stJohnsDay.php @@ -15,6 +15,7 @@ 'el_GR' => 'Σύναξις Προφήτου Προδρόμου και Βαπτιστού Ιωάννου', 'en_US' => 'St. John\'s Day', 'es_ES' => 'Sant Joan', + 'et_EE' => 'Jaanipäev', 'fi_FI' => 'Juhannuspäivä', 'sv_SE' => 'midsommardagen', ]; From f17de632c7ea02d785379de4b466ed0644448c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gedas=20Luko=C5=A1ius?= Date: Wed, 20 Dec 2017 09:25:31 +0200 Subject: [PATCH 3/6] Add test dates generator for Pentecost holiday and additional generator with modified Easter holiday test dates --- tests/YasumiBase.php | 50 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/tests/YasumiBase.php b/tests/YasumiBase.php index e00bf828c..35e73f6a3 100644 --- a/tests/YasumiBase.php +++ b/tests/YasumiBase.php @@ -273,17 +273,9 @@ public function generateRandomEasterDates($timezone = 'UTC', $iterations = 10, $ */ public function generateRandomEasterMondayDates($timezone = 'UTC', $iterations = 10, $range = 1000) { - $data = []; - - for ($i = 1; $i <= $iterations; ++$i) { - $year = Faker::create()->dateTimeBetween("-$range years", "+$range years")->format('Y'); - $date = $this->calculateEaster($year, $timezone); + return $this->generateRandomModifiedEasterDates(function (DateTime $date) { $date->add(new DateInterval('P1D')); - - $data[] = [$year, $date->format('Y-m-d')]; - } - - return $data; + }, $timezone, $iterations, $range); } /** @@ -298,13 +290,49 @@ public function generateRandomEasterMondayDates($timezone = 'UTC', $iterations = * @throws \Exception */ public function generateRandomGoodFridayDates($timezone = 'UTC', $iterations = 10, $range = 1000) + { + return $this->generateRandomModifiedEasterDates(function (DateTime $date) { + $date->sub(new DateInterval('P2D')); + }, $timezone, $iterations, $range); + } + + /** + * Returns a list of random Pentecost test dates used for assertion of holidays. + * + * @param string $timezone name of the timezone for which the dates need to be generated + * @param int $iterations number of iterations (i.e. samples) that need to be generated (default: 10) + * @param int $range year range from which dates will be generated (default: 1000) + * + * @return array list of random Pentecost test dates used for assertion of holidays. + * + * @throws \Exception + */ + public function generateRandomPentecostDates($timezone = 'UTC', $iterations = 10, $range = 1000) + { + return $this->generateRandomModifiedEasterDates(function (DateTime $date) { + $date->add(new DateInterval('P49D')); + }, $timezone, $iterations, $range); + } + + /** + * Returns a list of random modified Easter day test dates for assertion of holidays. + * + * @param callable $cb callback(DateTime $date) to modify $date by custom rules + * @param string $timezone name of the timezone for which the dates need to be generated + * @param int $iterations number of iterations (i.e. samples) that need to be generated (default: 10) + * @param int $range year range from which dates will be generated (default: 1000) + * + * @return array list of random modified Easter day test dates for assertion of holidays. + */ + public function generateRandomModifiedEasterDates(callable $cb, $timezone = 'UTC', $iterations = 10, $range = 1000) { $data = []; for ($i = 1; $i <= $iterations; ++$i) { $year = Faker::create()->dateTimeBetween("-$range years", "+$range years")->format('Y'); $date = $this->calculateEaster($year, $timezone); - $date->sub(new DateInterval('P2D')); + + $cb($date); $data[] = [$year, $date->format('Y-m-d')]; } From cafd08b05f28a27bf64919973b2d961175f853eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gedas=20Luko=C5=A1ius?= Date: Wed, 20 Dec 2017 09:51:31 +0200 Subject: [PATCH 4/6] Change Christmas Eve type to official for Estonia --- src/Yasumi/Provider/Estonia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Yasumi/Provider/Estonia.php b/src/Yasumi/Provider/Estonia.php index 8aa2badd3..7919e30f0 100644 --- a/src/Yasumi/Provider/Estonia.php +++ b/src/Yasumi/Provider/Estonia.php @@ -55,7 +55,7 @@ public function initialize() $this->addVictoryDay(); $this->addHoliday($this->stJohnsDay($this->year, $this->timezone, $this->locale)); $this->addRestorationOfIndependenceDay(); - $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); } From 20c0c244a97e705051101ad9219cdc481c1a6c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gedas=20Luko=C5=A1ius?= Date: Wed, 20 Dec 2017 09:52:39 +0200 Subject: [PATCH 5/6] Add tests for Estonia holidays --- phpunit.xml | 5 + tests/Estonia/ChristmasDayTest.php | 70 ++++++++++++++ tests/Estonia/ChristmasEveDayTest.php | 70 ++++++++++++++ tests/Estonia/EasterDayTest.php | 77 ++++++++++++++++ tests/Estonia/EstoniaBaseTestCase.php | 41 +++++++++ tests/Estonia/EstoniaTest.php | 91 +++++++++++++++++++ tests/Estonia/GoodFridayDayTest.php | 79 ++++++++++++++++ tests/Estonia/IndependenceDayTest.php | 90 ++++++++++++++++++ tests/Estonia/InternationalWorkersDayTest.php | 70 ++++++++++++++ tests/Estonia/NewYearsDayTest.php | 70 ++++++++++++++ tests/Estonia/PentecostTest.php | 79 ++++++++++++++++ .../RestorationOfIndependenceDayTest.php | 90 ++++++++++++++++++ tests/Estonia/SecondChristmasDayTest.php | 70 ++++++++++++++ tests/Estonia/StJohnsDayTest.php | 70 ++++++++++++++ tests/Estonia/VictoryDayTest.php | 90 ++++++++++++++++++ 15 files changed, 1062 insertions(+) create mode 100644 tests/Estonia/ChristmasDayTest.php create mode 100644 tests/Estonia/ChristmasEveDayTest.php create mode 100644 tests/Estonia/EasterDayTest.php create mode 100644 tests/Estonia/EstoniaBaseTestCase.php create mode 100644 tests/Estonia/EstoniaTest.php create mode 100644 tests/Estonia/GoodFridayDayTest.php create mode 100644 tests/Estonia/IndependenceDayTest.php create mode 100644 tests/Estonia/InternationalWorkersDayTest.php create mode 100644 tests/Estonia/NewYearsDayTest.php create mode 100644 tests/Estonia/PentecostTest.php create mode 100644 tests/Estonia/RestorationOfIndependenceDayTest.php create mode 100644 tests/Estonia/SecondChristmasDayTest.php create mode 100644 tests/Estonia/StJohnsDayTest.php create mode 100644 tests/Estonia/VictoryDayTest.php diff --git a/phpunit.xml b/phpunit.xml index 91f6db606..213e41766 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -68,6 +68,11 @@ ./tests/Denmark + + + ./tests/Estonia + + ./tests/Finland diff --git a/tests/Estonia/ChristmasDayTest.php b/tests/Estonia/ChristmasDayTest.php new file mode 100644 index 000000000..658fc5ec9 --- /dev/null +++ b/tests/Estonia/ChristmasDayTest.php @@ -0,0 +1,70 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for Christmas day in Estonia. + * + * @author Gedas Lukošius + */ +class ChristmasDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'christmasDay'; + + /** + * @return array + */ + public function holidayDataProvider() + { + return $this->generateRandomDates(12, 25, self::TIMEZONE); + } + + /** + * @dataProvider holidayDataProvider + * + * @param int $year + * @param \DateTime $expected + */ + public function testHoliday($year, \DateTime $expected) + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(), + [self::LOCALE => 'Esimene jõulupüha'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Estonia/ChristmasEveDayTest.php b/tests/Estonia/ChristmasEveDayTest.php new file mode 100644 index 000000000..dc172d95d --- /dev/null +++ b/tests/Estonia/ChristmasEveDayTest.php @@ -0,0 +1,70 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for Christmas Eve day in Estonia. + * + * @author Gedas Lukošius + */ +class ChristmasEveDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'christmasEve'; + + /** + * @return array + */ + public function holidayDataProvider() + { + return $this->generateRandomDates(12, 24, self::TIMEZONE); + } + + /** + * @dataProvider holidayDataProvider + * + * @param int $year + * @param \DateTime $expected + */ + public function testHoliday($year, \DateTime $expected) + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(), + [self::LOCALE => 'Jõululaupäev'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Estonia/EasterDayTest.php b/tests/Estonia/EasterDayTest.php new file mode 100644 index 000000000..e54edf60b --- /dev/null +++ b/tests/Estonia/EasterDayTest.php @@ -0,0 +1,77 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for Easter day in Estonia. + * + * @author Gedas Lukošius + */ +class EasterDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'easter'; + + /** + * @return array + */ + public function holidayDataProvider() + { + return $this->generateRandomEasterDates(self::TIMEZONE); + } + + /** + * Test defined holiday in the test + * + * @dataProvider holidayDataProvider + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + */ + public function testHoliday($year, $expected) + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(), + [self::LOCALE => 'Ülestõusmispühade 1. püha'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Estonia/EstoniaBaseTestCase.php b/tests/Estonia/EstoniaBaseTestCase.php new file mode 100644 index 000000000..aeb4b2f1d --- /dev/null +++ b/tests/Estonia/EstoniaBaseTestCase.php @@ -0,0 +1,41 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Estonia holiday provider. + * + * @author Gedas Lukošius + */ +abstract class EstoniaBaseTestCase extends \PHPUnit_Framework_TestCase +{ + use YasumiBase; + + /** + * Name of the country to be tested + */ + const REGION = 'Estonia'; + + /** + * Timezone in which this provider has holidays defined + */ + const TIMEZONE = 'Europe/Tallinn'; + + /** + * Locale that is considered common for this provider + */ + const LOCALE = 'et_EE'; +} diff --git a/tests/Estonia/EstoniaTest.php b/tests/Estonia/EstoniaTest.php new file mode 100644 index 000000000..69d47ae14 --- /dev/null +++ b/tests/Estonia/EstoniaTest.php @@ -0,0 +1,91 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\Provider\Estonia; + +/** + * Class for testing holidays in Estonia. + * + * @author Gedas Lukošius + */ +class EstoniaTest extends EstoniaBaseTestCase +{ + /** + * Tests if all official holidays in Estonia are defined by the provider class + */ + public function testOfficialHolidays() + { + $holidays = [ + 'christmasDay', + 'christmasEve', + 'easter', + 'goodFriday', + 'internationalWorkersDay', + 'newYearsDay', + 'pentecost', + 'secondChristmasDay', + 'stJohnsDay', + ]; + + $year = $this->generateRandomYear(); + + if ($year >= Estonia::DECLARATION_OF_INDEPENDENCE_YEAR) { + $holidays[] = 'independenceDay'; + } + + if ($year >= Estonia::VICTORY_DAY_START_YEAR) { + $holidays[] = 'victoryDay'; + } + + if ($year >= Estonia::RESTORATION_OF_INDEPENDENCE_YEAR) { + $holidays[] = 'restorationOfIndependenceDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Estonia are defined by the provider class + */ + public function testObservedHolidays() + { + $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Estonia are defined by the provider class + */ + public function testSeasonalHolidays() + { + $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Estonia are defined by the provider class + */ + public function testBankHolidays() + { + $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Estonia are defined by the provider class + */ + public function testOtherHolidays() + { + $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Estonia/GoodFridayDayTest.php b/tests/Estonia/GoodFridayDayTest.php new file mode 100644 index 000000000..e46283817 --- /dev/null +++ b/tests/Estonia/GoodFridayDayTest.php @@ -0,0 +1,79 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for Estonia's Good Friday day. + * + * @author Gedas Lukošius + */ +class GoodFridayDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'goodFriday'; + + /** + * @return array + * + * @throws \Exception + */ + public function holidayDataProvider() + { + return $this->generateRandomGoodFridayDates(self::TIMEZONE); + } + + /** + * Test defined holiday in the test + * + * @dataProvider holidayDataProvider + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + */ + public function testHoliday($year, $expected) + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(), + [self::LOCALE => 'Suur Reede'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Estonia/IndependenceDayTest.php b/tests/Estonia/IndependenceDayTest.php new file mode 100644 index 000000000..2977efd15 --- /dev/null +++ b/tests/Estonia/IndependenceDayTest.php @@ -0,0 +1,90 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\Provider\Estonia; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for Estonia's independence day. + * + * @author Gedas Lukošius + */ +class IndependenceDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'independenceDay'; + + /** + * Test if holiday is not defined before restoration + */ + public function testHolidayBeforeRestoration() + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(1000, Estonia::DECLARATION_OF_INDEPENDENCE_YEAR - 1) + ); + } + + /** + * Test if holiday is defined after restoration + */ + public function testHolidayAfterRestoration() + { + $year = $this->generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-02-24", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR), + [self::LOCALE => 'Iseseisvuspäev'] + ); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR), + ['en_US' => 'Independence Day'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Estonia/InternationalWorkersDayTest.php b/tests/Estonia/InternationalWorkersDayTest.php new file mode 100644 index 000000000..2ea4042ab --- /dev/null +++ b/tests/Estonia/InternationalWorkersDayTest.php @@ -0,0 +1,70 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for International Workers' Day in Estonia. + * + * @author Gedas Lukošius + */ +class InternationalWorkersDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'internationalWorkersDay'; + + /** + * @return array + */ + public function holidayDataProvider() + { + return $this->generateRandomDates(5, 1, self::TIMEZONE); + } + + /** + * @dataProvider holidayDataProvider + * + * @param int $year + * @param \DateTime $expected + */ + public function testHoliday($year, \DateTime $expected) + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(), + [self::LOCALE => 'Kevadpüha'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Estonia/NewYearsDayTest.php b/tests/Estonia/NewYearsDayTest.php new file mode 100644 index 000000000..969b67460 --- /dev/null +++ b/tests/Estonia/NewYearsDayTest.php @@ -0,0 +1,70 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for New Year's Day in Estonia. + * + * @author Gedas Lukošius + */ +class NewYearsDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'newYearsDay'; + + /** + * @return array + */ + public function holidayDataProvider() + { + return $this->generateRandomDates(1, 1, self::TIMEZONE); + } + + /** + * @dataProvider holidayDataProvider + * + * @param int $year + * @param \DateTime $expected + */ + public function testHoliday($year, \DateTime $expected) + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(), + [self::LOCALE => 'Uusaasta'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Estonia/PentecostTest.php b/tests/Estonia/PentecostTest.php new file mode 100644 index 000000000..52f7a7b56 --- /dev/null +++ b/tests/Estonia/PentecostTest.php @@ -0,0 +1,79 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for Pentecost in Estonia. + * + * @author Gedas Lukošius + */ +class PentecostTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'pentecost'; + + /** + * @return array + * + * @throws \Exception + */ + public function holidayDataProvider() + { + return $this->generateRandomPentecostDates(self::TIMEZONE); + } + + /** + * Test defined holiday in the test + * + * @dataProvider holidayDataProvider + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + */ + public function testHoliday($year, $expected) + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(), + [self::LOCALE => 'Nelipühade 1. püha'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Estonia/RestorationOfIndependenceDayTest.php b/tests/Estonia/RestorationOfIndependenceDayTest.php new file mode 100644 index 000000000..5d43e7005 --- /dev/null +++ b/tests/Estonia/RestorationOfIndependenceDayTest.php @@ -0,0 +1,90 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\Provider\Estonia; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for Estonia's Restoration of Independence day. + * + * @author Gedas Lukošius + */ +class RestorationOfIndependenceDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'restorationOfIndependenceDay'; + + /** + * Test if holiday is not defined before restoration + */ + public function testHolidayBeforeRestoration() + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(1000, Estonia::RESTORATION_OF_INDEPENDENCE_YEAR - 1) + ); + } + + /** + * Test if holiday is defined after restoration + */ + public function testHolidayAfterRestoration() + { + $year = $this->generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-08-20", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR), + [self::LOCALE => 'Tasiseseisvumispäev'] + ); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR), + ['en_US' => 'Day of Restoration of Independence'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Estonia/SecondChristmasDayTest.php b/tests/Estonia/SecondChristmasDayTest.php new file mode 100644 index 000000000..17696428e --- /dev/null +++ b/tests/Estonia/SecondChristmasDayTest.php @@ -0,0 +1,70 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for Second Christmas day in Estonia. + * + * @author Gedas Lukošius + */ +class SecondChristmasDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'secondChristmasDay'; + + /** + * @return array + */ + public function holidayDataProvider() + { + return $this->generateRandomDates(12, 26, self::TIMEZONE); + } + + /** + * @dataProvider holidayDataProvider + * + * @param int $year + * @param \DateTime $expected + */ + public function testHoliday($year, \DateTime $expected) + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(), + [self::LOCALE => 'Teine Jõulupüha'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Estonia/StJohnsDayTest.php b/tests/Estonia/StJohnsDayTest.php new file mode 100644 index 000000000..fc76739a5 --- /dev/null +++ b/tests/Estonia/StJohnsDayTest.php @@ -0,0 +1,70 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for St. John's Day in Estonia. + * + * @author Gedas Lukošius + */ +class StJohnsDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'stJohnsDay'; + + /** + * @return array + */ + public function holidayDataProvider() + { + return $this->generateRandomDates(6, 24, self::TIMEZONE); + } + + /** + * @dataProvider holidayDataProvider + * + * @param int $year + * @param \DateTime $expected + */ + public function testHoliday($year, \DateTime $expected) + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(), + [self::LOCALE => 'Jaanipäev'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Estonia/VictoryDayTest.php b/tests/Estonia/VictoryDayTest.php new file mode 100644 index 000000000..1b2fd2e07 --- /dev/null +++ b/tests/Estonia/VictoryDayTest.php @@ -0,0 +1,90 @@ + + */ + +namespace Yasumi\tests\Estonia; + +use Yasumi\Holiday; +use Yasumi\Provider\Estonia; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for Estonia's Victory day. + * + * @author Gedas Lukošius + */ +class VictoryDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + const HOLIDAY = 'victoryDay'; + + /** + * Test if holiday is not defined before restoration + */ + public function testHolidayBeforeRestoration() + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(1000, Estonia::VICTORY_DAY_START_YEAR - 1) + ); + } + + /** + * Test if holiday is defined after restoration + */ + public function testHolidayAfterRestoration() + { + $year = $this->generateRandomYear(Estonia::VICTORY_DAY_START_YEAR); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-06-23", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * {@inheritdoc} + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(Estonia::VICTORY_DAY_START_YEAR), + [self::LOCALE => 'Võidupüha'] + ); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(Estonia::VICTORY_DAY_START_YEAR), + ['en_US' => 'Victory Day'] + ); + } + + /** + * {@inheritdoc} + */ + public function testHolidayType() + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(Estonia::VICTORY_DAY_START_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} From aa0a2989c9ef94b4b3d6cc43eeb5ba163d9a3072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gedas=20Luko=C5=A1ius?= Date: Wed, 20 Dec 2017 16:00:51 +0200 Subject: [PATCH 6/6] Cleanup naming --- tests/Estonia/IndependenceDayTest.php | 8 ++++---- tests/Estonia/RestorationOfIndependenceDayTest.php | 8 ++++---- tests/Estonia/VictoryDayTest.php | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Estonia/IndependenceDayTest.php b/tests/Estonia/IndependenceDayTest.php index 2977efd15..2f6c11979 100644 --- a/tests/Estonia/IndependenceDayTest.php +++ b/tests/Estonia/IndependenceDayTest.php @@ -30,9 +30,9 @@ class IndependenceDayTest extends EstoniaBaseTestCase implements YasumiTestCaseI const HOLIDAY = 'independenceDay'; /** - * Test if holiday is not defined before restoration + * Test if holiday is not defined before */ - public function testHolidayBeforeRestoration() + public function testHolidayBefore() { $this->assertNotHoliday( self::REGION, @@ -42,9 +42,9 @@ public function testHolidayBeforeRestoration() } /** - * Test if holiday is defined after restoration + * Test if holiday is defined after */ - public function testHolidayAfterRestoration() + public function testHolidayAfter() { $year = $this->generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR); diff --git a/tests/Estonia/RestorationOfIndependenceDayTest.php b/tests/Estonia/RestorationOfIndependenceDayTest.php index 5d43e7005..2e0369f9f 100644 --- a/tests/Estonia/RestorationOfIndependenceDayTest.php +++ b/tests/Estonia/RestorationOfIndependenceDayTest.php @@ -30,9 +30,9 @@ class RestorationOfIndependenceDayTest extends EstoniaBaseTestCase implements Ya const HOLIDAY = 'restorationOfIndependenceDay'; /** - * Test if holiday is not defined before restoration + * Test if holiday is not defined before */ - public function testHolidayBeforeRestoration() + public function testHolidayBefore() { $this->assertNotHoliday( self::REGION, @@ -42,9 +42,9 @@ public function testHolidayBeforeRestoration() } /** - * Test if holiday is defined after restoration + * Test if holiday is defined after */ - public function testHolidayAfterRestoration() + public function testHolidayAfter() { $year = $this->generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR); diff --git a/tests/Estonia/VictoryDayTest.php b/tests/Estonia/VictoryDayTest.php index 1b2fd2e07..9af18c4f7 100644 --- a/tests/Estonia/VictoryDayTest.php +++ b/tests/Estonia/VictoryDayTest.php @@ -30,9 +30,9 @@ class VictoryDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterf const HOLIDAY = 'victoryDay'; /** - * Test if holiday is not defined before restoration + * Test if holiday is not defined before */ - public function testHolidayBeforeRestoration() + public function testHolidayBefore() { $this->assertNotHoliday( self::REGION, @@ -42,9 +42,9 @@ public function testHolidayBeforeRestoration() } /** - * Test if holiday is defined after restoration + * Test if holiday is defined after */ - public function testHolidayAfterRestoration() + public function testHolidayAfter() { $year = $this->generateRandomYear(Estonia::VICTORY_DAY_START_YEAR);