diff --git a/phpunit.xml b/phpunit.xml index 23996b71e..1fef40a68 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -99,6 +99,11 @@ ./tests/Greece + + + ./tests/NewZealand + + diff --git a/src/Yasumi/Provider/NewZealand.php b/src/Yasumi/Provider/NewZealand.php new file mode 100644 index 000000000..fc398b5e9 --- /dev/null +++ b/src/Yasumi/Provider/NewZealand.php @@ -0,0 +1,218 @@ + + */ +namespace Yasumi\Provider; + +use DateTime; +use DateTimeZone; +use DateInterval; +use Yasumi\Holiday; + +/** + * Provider for all holidays in New Zealand. + */ +class NewZealand extends AbstractProvider +{ + use CommonHolidays, ChristianHolidays; + + /** + * Initialize holidays for New Zealand. + */ + public function initialize() + { + $this->timezone = 'Pacific/Auckland'; + + // National Holidays + $this->calculateNewYearHolidays(); + $this->calculateWaitangiDay(); + $this->calculateAnzacDay(); + $this->calculateQueensBirthday(); + $this->calculateLabourDay(); + + // Add Christian holidays + $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); + $this->calculateChristmasHolidays(); + } + + /** + * Waitangi Day + * + * Waitangi Day (named after Waitangi, where the Treaty of Waitangi was first signed) + * commemorates a significant day in the history of New Zealand. It is observed as a public holiday each + * year on 6 February to celebrate the signing of the Treaty of Waitangi, New Zealand's founding document, + * on that date in 1840. In recent legislation, if 6 February falls on a Saturday or Sunday, + * the Monday that immediately follows becomes a public holiday. + * + * @link https://en.wikipedia.org/wiki/Waitangi_Day + * @link http://employment.govt.nz/er/holidaysandleave/publicholidays/mondayisation.asp + */ + public function calculateWaitangiDay() + { + if ($this->year < 1974) { + return; + } + + $date = new DateTime("$this->year-02-6", new DateTimeZone($this->timezone)); + + if ($this->year >= 2015 && !$this->isWorkingDay($date)) { + $date->modify('next monday'); + } + + $this->addHoliday(new Holiday('waitangiDay', [], $date, $this->locale)); + } + + /** + * Christmas Day / Boxing Day + * + * Christmas day, and Boxing day are public holidays in New Zealand, + * they are subject to mondayisation rules. + * + * @link http://www.timeanddate.com/holidays/new-zealand/boxing-day + * @link http://www.timeanddate.com/holidays/new-zealand/christmas-day + * @link http://employment.govt.nz/er/holidaysandleave/publicholidays/mondayisation.asp + */ + public function calculateChristmasHolidays() + { + $christmasDay = new DateTime("$this->year-12-25", new DateTimeZone($this->timezone)); + $boxingDay = new DateTime("$this->year-12-26", new DateTimeZone($this->timezone)); + + switch ($christmasDay->format('w')) { + case 0: + $christmasDay->add(new DateInterval('P2D')); + break; + case 5: + $boxingDay->add(new DateInterval('P2D')); + break; + case 6: + $christmasDay->add(new DateInterval('P2D')); + $boxingDay->add(new DateInterval('P2D')); + break; + } + + $this->addHoliday(new Holiday('christmasDay', [], $christmasDay, $this->locale)); + $this->addHoliday(new Holiday('secondChristmasDay', [], $boxingDay, $this->locale)); + } + + /** + * Holidays associated with the start of the modern Gregorian calendar + * + * New Zealanders celebrate New Years Day and The Day After New Years Day, + * if either of these holidays occur on a weekend, the dates need to be adjusted. + * + * @link https://en.wikipedia.org/wiki/Public_holidays_in_New_Zealand#Statutory_holidays + * @link http://www.timeanddate.com/holidays/new-zealand/new-year-day + * @link http://www.timeanddate.com/holidays/new-zealand/day-after-new-years-day + * @link http://employment.govt.nz/er/holidaysandleave/publicholidays/mondayisation.asp + */ + public function calculateNewYearHolidays() + { + $newYearsDay = new DateTime("$this->year-01-01", new DateTimeZone($this->timezone)); + $dayAfterNewYearsDay = new DateTime("$this->year-01-02", new DateTimeZone($this->timezone)); + + switch ($newYearsDay->format('w')) { + case 0: + $newYearsDay->add(new DateInterval('P1D')); + $dayAfterNewYearsDay->add(new DateInterval('P1D')); + break; + case 5: + $dayAfterNewYearsDay->add(new DateInterval('P2D')); + break; + case 6: + $newYearsDay->add(new DateInterval('P2D')); + $dayAfterNewYearsDay->add(new DateInterval('P2D')); + break; + } + + $this->addHoliday(new Holiday('newYearsDay', [], $newYearsDay, $this->locale)); + $this->addHoliday(new Holiday('dayAfterNewYearsDay', [], $dayAfterNewYearsDay, $this->locale)); + } + + /** + * ANZAC Day + * + * Anzac Day is a national day of remembrance in Australia and New Zealand that broadly commemorates all Australians + * and New Zealanders "who served and died in all wars, conflicts, and peacekeeping operations" + * Observed on 25 April each year. + * + * @link https://en.wikipedia.org/wiki/Anzac_Day + * @link http://employment.govt.nz/er/holidaysandleave/publicholidays/mondayisation.asp + */ + public function calculateAnzacDay() + { + if ($this->year < 1921) { + return; + } + + $date = new DateTime("$this->year-04-25", new DateTimeZone($this->timezone)); + + if ($this->year >= 2015 && !$this->isWorkingDay($date)) { + $date->modify('next monday'); + } + + $this->addHoliday(new Holiday('anzacDay', [], $date, $this->locale)); + } + + /** + * Queens Birthday + * + * The official head of state of New Zealand is the Monarch of the Commonwealth Realms. + * The monarch's birthday is officially celebrated in many parts of New Zealand. + * On her accession in 1952 Queen Elizabeth II was proclaimed in New Zealand ‘Queen of this Realm and all her + * other Realms’. Her representative in New Zealand, the governor general, has symbolic and ceremonial roles + * and is not involved in the day-to-day running of the government, which is the domain of the prime minister. + * + * Her actual birthday is on April 21, but it's celebrated as a public holiday on the first Monday of June. + * + * @link http://www.timeanddate.com/holidays/new-zealand/queen-birthday + */ + public function calculateQueensBirthday() + { + if ($this->year < 1952) { + return; + } + + $this->addHoliday(new Holiday( + 'queensBirthday', + [], + new DateTime("first monday of june $this->year", new DateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * During the 19th century, workers in New Zealand tried to claim the right for an 8-hour working day. + * In 1840 carpenter Samuel Parnell fought for this right in Wellington, NZ, and won. + * Labour Day was first celebrated in New Zealand on October 28, 1890, when thousands of workers paraded in the + * main city centres. + * Government employees were given the day off to attend the parades and many businesses closed for at least part + * of the day. + * + * The first official Labour Day public holiday in New Zealand was celebrated on the + * second Wednesday in October in 1900. The holiday was moved to the fourth Monday of October in 1910 + * has remained on this date since then. + * + * @link http://www.timeanddate.com/holidays/new-zealand/labour-day + */ + public function calculateLabourDay() + { + if ($this->year < 1900) { + return; + } + + $date = new DateTime( + (($this->year < 1910) ? 'second wednesday of october' : 'fourth monday of october') . " $this->year", + new DateTimeZone($this->timezone) + ); + + $this->addHoliday(new Holiday('labourDay', [], $date, $this->locale)); + } +} diff --git a/src/Yasumi/data/translations/anzacDay.php b/src/Yasumi/data/translations/anzacDay.php new file mode 100644 index 000000000..01d5916e9 --- /dev/null +++ b/src/Yasumi/data/translations/anzacDay.php @@ -0,0 +1,16 @@ + + */ + +// Translation for ANZAC Day +return [ + 'en_US' => 'ANZAC Day', +]; diff --git a/src/Yasumi/data/translations/dayAfterNewYearsDay.php b/src/Yasumi/data/translations/dayAfterNewYearsDay.php new file mode 100644 index 000000000..d0b73f136 --- /dev/null +++ b/src/Yasumi/data/translations/dayAfterNewYearsDay.php @@ -0,0 +1,16 @@ + + */ + +// Translation for Day after New Year's Day +return [ + 'en_US' => 'Day after New Year\'s Day', +]; diff --git a/src/Yasumi/data/translations/waitangiDay.php b/src/Yasumi/data/translations/waitangiDay.php new file mode 100644 index 000000000..d0ed31c43 --- /dev/null +++ b/src/Yasumi/data/translations/waitangiDay.php @@ -0,0 +1,16 @@ + + */ + +// Translation for Waitangi Day +return [ + 'en_US' => 'Waitangi Day', +]; diff --git a/tests/NewZealand/AnzacDayTest.php b/tests/NewZealand/AnzacDayTest.php new file mode 100644 index 000000000..a1ed32f28 --- /dev/null +++ b/tests/NewZealand/AnzacDayTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use DateTime; +use DateTimeZone; + +/** + * Class for testing ANZAC day in the New Zealand. + */ +class AnzacDayTest extends NewZealandBaseTestCase +{ + /** + * The name of the holiday + */ + const HOLIDAY = 'anzacDay'; + + /** + * Tests ANZAC Day + * + * @dataProvider HolidayDataProvider + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param DateTime $expected the expected date + */ + public function testHoliday($year, $expected) + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, + new DateTime($expected, new DateTimeZone(self::TIMEZONE))); + } + + /** + * Tests that Labour Day is not present before 1921 + */ + public function testNotHoliday() + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, 1920); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(1921), + ['en_US' => 'ANZAC Day'] + ); + } + + /** + * Returns a list of test dates + * + * @return array list of test dates for the holiday defined in this test + */ + public function HolidayDataProvider() + { + $data = []; + + for ($i = 0; $i < 100; $i++) { + $year = $this->generateRandomYear(1921, 2100); + $date = new DateTime("$year-04-25", new DateTimeZone(self::TIMEZONE)); + + // in 2015 some policy was introduced to make sure this holiday was celebrated during the working week. + if ($year >= 2015 && in_array($date->format('w'), [0, 6])) { + $date->modify('next monday'); + } + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } +} diff --git a/tests/NewZealand/BoxingDayTest.php b/tests/NewZealand/BoxingDayTest.php new file mode 100644 index 000000000..81d01365f --- /dev/null +++ b/tests/NewZealand/BoxingDayTest.php @@ -0,0 +1,65 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use DateTime; +use DateTimeZone; +use DateInterval; + +/** + * Class for testing Boxing Day in the New Zealand. + */ +class BoxingDayTest extends NewZealandBaseTestCase +{ + /** + * The name of the holiday + */ + const HOLIDAY = 'secondChristmasDay'; + + /** + * Tests Boxing Day + * + * @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))); + } + + /** + * Returns a list of test dates + * + * @return array list of test dates for the holiday defined in this test + */ + public function HolidayDataProvider() + { + $data = []; + + for ($y = 0; $y < 50; $y++) { + $year = $this->generateRandomYear(1800, 2100); + $date = new DateTime("$year-12-26", new DateTimeZone(self::TIMEZONE)); + + if (in_array($date->format('w'), [0, 6])) { + $date->add(new DateInterval('P2D')); + } + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } +} diff --git a/tests/NewZealand/ChristmasDayTest.php b/tests/NewZealand/ChristmasDayTest.php new file mode 100644 index 000000000..937dca39c --- /dev/null +++ b/tests/NewZealand/ChristmasDayTest.php @@ -0,0 +1,65 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use DateTime; +use DateTimeZone; +use DateInterval; + +/** + * Class for testing Christmas Day in the New Zealand. + */ +class ChristmasDayTest extends NewZealandBaseTestCase +{ + /** + * The name of the holiday + */ + const HOLIDAY = 'christmasDay'; + + /** + * Tests Christmas Day + * + * @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))); + } + + /** + * Returns a list of test dates + * + * @return array list of test dates for the holiday defined in this test + */ + public function HolidayDataProvider() + { + $data = []; + + for ($y = 0; $y < 50; $y ++) { + $year = $this->generateRandomYear(1800, 2100); + $date = new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)); + + if (in_array($date->format('w'), [0, 6])) { + $date->add(new DateInterval('P2D')); + } + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } +} diff --git a/tests/NewZealand/DayAfterNewYearsDayTest.php b/tests/NewZealand/DayAfterNewYearsDayTest.php new file mode 100644 index 000000000..9e6e8eeda --- /dev/null +++ b/tests/NewZealand/DayAfterNewYearsDayTest.php @@ -0,0 +1,83 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use DateTime; +use DateTimeZone; +use DateInterval; + +/** + * Class for testing Day After New Years Day in the New Zealand. + */ +class DayAfterNewYearsDayTest extends NewZealandBaseTestCase +{ + /** + * The name of the holiday + */ + const HOLIDAY = 'dayAfterNewYearsDay'; + + /** + * Tests Day After New Years Day + * + * @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))); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(1921), + ['en_US' => 'Day after New Year\'s Day'] + ); + } + + /** + * Returns a list of test dates + * + * @return array list of test dates for the holiday defined in this test + */ + public function HolidayDataProvider() + { + $data = []; + + for ($y = 0; $y < 50; $y ++) { + $year = $this->generateRandomYear(1800, 2100); + $date = new DateTime("$year-01-02", new DateTimeZone(self::TIMEZONE)); + + switch ($date->format('w')) { + case 0: + case 6: + $date->add(new DateInterval('P2D')); + break; + case 1: + $date->add(new DateInterval('P1D')); + } + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } +} diff --git a/tests/NewZealand/EasterMondayTest.php b/tests/NewZealand/EasterMondayTest.php new file mode 100644 index 000000000..083e30f6e --- /dev/null +++ b/tests/NewZealand/EasterMondayTest.php @@ -0,0 +1,62 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use DateTime; +use DateTimeZone; +use DateInterval; + +/** + * Class for testing Easter Monday in New Zealand. + */ +class EasterMondayTest extends NewZealandBaseTestCase +{ + /** + * The name of the holiday + */ + const HOLIDAY = 'easterMonday'; + + /** + * Tests Easter Monday + * + * @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))); + } + + /** + * Returns a list of test dates + * + * @return array list of test dates for the holiday defined in this test + */ + public function HolidayDataProvider() + { + $data = []; + + for ($y = 0; $y < 50; $y ++) { + $year = $this->generateRandomYear(1800, 3000); + $date = new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)); + $date->add(new DateInterval('P' . (easter_days($year)+1) . 'D')); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } +} diff --git a/tests/NewZealand/GoodFridayTest.php b/tests/NewZealand/GoodFridayTest.php new file mode 100644 index 000000000..28edf69c8 --- /dev/null +++ b/tests/NewZealand/GoodFridayTest.php @@ -0,0 +1,62 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use DateTime; +use DateTimeZone; +use DateInterval; + +/** + * Class for testing Good Friday in New Zealand. + */ +class GoodFridayTest extends NewZealandBaseTestCase +{ + /** + * The name of the holiday + */ + const HOLIDAY = 'goodFriday'; + + /** + * Tests Good Friday + * + * @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))); + } + + /** + * Returns a list of test dates + * + * @return array list of test dates for the holiday defined in this test + */ + public function HolidayDataProvider() + { + $data = []; + + for ($y = 0; $y < 50; $y ++) { + $year = $this->generateRandomYear(1800, 3000); + $date = new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)); + $date->add(new DateInterval('P' . easter_days($year) . 'D')); + $date->modify('previous friday'); + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } +} diff --git a/tests/NewZealand/LabourDayTest.php b/tests/NewZealand/LabourDayTest.php new file mode 100644 index 000000000..46cc3a1d7 --- /dev/null +++ b/tests/NewZealand/LabourDayTest.php @@ -0,0 +1,71 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use DateTime; +use DateTimeZone; + +/** + * Class for testing Labour Day in the New Zealand. + */ +class LabourDayTest extends NewZealandBaseTestCase +{ + /** + * The name of the holiday + */ + const HOLIDAY = 'labourDay'; + + /** + * Tests Labour Day + * + * @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))); + } + + /** + * Tests that Labour Day is not present before 1900 + */ + public function testNotHoliday() + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, 1899); + } + + /** + * Returns a list of test dates + * + * @return array list of test dates for the holiday defined in this test + */ + public function HolidayDataProvider() + { + $data = []; + + for ($y = 0; $y < 100; $y ++) { + $year = $this->generateRandomYear(1900, 2100); + $expected = new DateTime( + (($year < 1910) ? 'second wednesday of october' : 'fourth monday of october') . " $year", + new DateTimeZone(self::TIMEZONE) + ); + + $data[] = [$year, $expected->format('Y-m-d')]; + } + + return $data; + } +} diff --git a/tests/NewZealand/NewYearsDayTest.php b/tests/NewZealand/NewYearsDayTest.php new file mode 100644 index 000000000..9c60b4c80 --- /dev/null +++ b/tests/NewZealand/NewYearsDayTest.php @@ -0,0 +1,70 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use DateTime; +use DateTimeZone; +use DateInterval; + +/** + * Class for testing New Years Day in the New Zealand. + */ +class NewYearsDayTest extends NewZealandBaseTestCase +{ + /** + * The name of the holiday + */ + const HOLIDAY = 'newYearsDay'; + + /** + * Tests New Years Day + * + * @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))); + } + + /** + * Returns a list of test dates + * + * @return array list of test dates for the holiday defined in this test + */ + public function HolidayDataProvider() + { + $data = []; + + for ($y = 0; $y < 50; $y ++) { + $year = $this->generateRandomYear(1800, 2100); + $date = new DateTime("$year-01-01", new DateTimeZone(self::TIMEZONE)); + + switch ($date->format('w')) { + case 0: + $date->add(new DateInterval('P1D')); + break; + case 6: + $date->add(new DateInterval('P2D')); + break; + } + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } +} diff --git a/tests/NewZealand/NewZealandBaseTestCase.php b/tests/NewZealand/NewZealandBaseTestCase.php new file mode 100644 index 000000000..36a442b67 --- /dev/null +++ b/tests/NewZealand/NewZealandBaseTestCase.php @@ -0,0 +1,34 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use PHPUnit_Framework_TestCase; +use Yasumi\Tests\YasumiBase; + +/** + * Base class for test cases of the NewZealand holiday provider. + */ +abstract class NewZealandBaseTestCase extends PHPUnit_Framework_TestCase +{ + use YasumiBase; + + /** + * Name of the region (e.g. country / state) to be tested + */ + const REGION = 'NewZealand'; + + /** + * Timezone in which this provider has holidays defined + */ + const TIMEZONE = 'Pacific/Auckland'; +} diff --git a/tests/NewZealand/NewZealandTest.php b/tests/NewZealand/NewZealandTest.php new file mode 100644 index 000000000..3af01f08e --- /dev/null +++ b/tests/NewZealand/NewZealandTest.php @@ -0,0 +1,84 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use Yasumi\Holiday; + +/** + * Class for testing holidays in New Zealand. + */ +class NewZealandTest extends NewZealandBaseTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected $year; + + /** + * Tests if all national holidays in New Zealand are defined by the provider class + */ + public function testNationalHolidays() + { + $this->assertDefinedHolidays([ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'christmasDay', + 'secondChristmasDay', + 'waitangiDay', + 'anzacDay', + 'queensBirthday', + 'labourDay', + ], self::REGION, $this->year, Holiday::TYPE_NATIONAL); + } + + /** + * Tests if all observed holidays in New Zealand are defined by the provider class + */ + public function testObservedHolidays() + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in New Zealand are defined by the provider class + */ + public function testSeasonalHolidays() + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in New Zealand are defined by the provider class + */ + public function testBankHolidays() + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in New Zealand are defined by the provider class + */ + public function testOtherHolidays() + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * Initial setup of this Test Case + */ + protected function setUp() + { + $this->year = $this->generateRandomYear(1987); + } +} diff --git a/tests/NewZealand/QueensBirthdayTest.php b/tests/NewZealand/QueensBirthdayTest.php new file mode 100644 index 000000000..44873bb85 --- /dev/null +++ b/tests/NewZealand/QueensBirthdayTest.php @@ -0,0 +1,66 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use DateTime; +use DateTimeZone; + +/** + * Class for testing Queens Birthday in the New Zealand. + */ +class QueensBirthdayTest extends NewZealandBaseTestCase +{ + /** + * The name of the holiday + */ + const HOLIDAY = 'queensBirthday'; + + /** + * Tests Queens Birthday + * + * @dataProvider HolidayDataProvider + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param DateTime $expected the expected date + */ + public function testHoliday($year, $expected) + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Tests that Holiday is not present before 1952 + */ + public function testNotHoliday() + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, 1951); + } + + /** + * Returns a list of test dates + * + * @return array list of test dates for the holiday defined in this test + */ + public function HolidayDataProvider() + { + $data = []; + + for ($y = 1; $y <= 100; $y ++) { + $year = $this->generateRandomYear(1952, 2100); + $expected = new DateTime("first monday of june $year", new DateTimeZone(self::TIMEZONE)); + $data[] = [$year, $expected]; + } + + return $data; + } +} diff --git a/tests/NewZealand/WaitangiDayTest.php b/tests/NewZealand/WaitangiDayTest.php new file mode 100644 index 000000000..f957deb90 --- /dev/null +++ b/tests/NewZealand/WaitangiDayTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use DateTime; +use DateTimeZone; + +/** + * Class for testing Waitangi day in the New Zealand. + */ +class WaitangiDayTest extends NewZealandBaseTestCase +{ + /** + * The name of the holiday + */ + const HOLIDAY = 'waitangiDay'; + + /** + * Tests Waitangi Day + * + * @dataProvider HolidayDataProvider + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param DateTime $expected the expected date + */ + public function testHoliday($year, $expected) + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, + new DateTime($expected, new DateTimeZone(self::TIMEZONE))); + } + + /** + * Tests that Holiday is not present before 1974 + */ + public function testNotHoliday() + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, 1973); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation() + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(1974), + ['en_US' => 'Waitangi Day'] + ); + } + + /** + * Returns a list of test dates + * + * @return array list of test dates for the holiday defined in this test + */ + public function HolidayDataProvider() + { + $data = []; + + for ($i = 0; $i < 100; $i++) { + $year = $this->generateRandomYear(1974, 2100); + $date = new DateTime("$year-02-06", new DateTimeZone(self::TIMEZONE)); + + // in 2015 some policy was introduced to make sure this holiday was celebrated during the working week. + if ($year >= 2015 && in_array($date->format('w'), [0, 6])) { + $date->modify('next monday'); + } + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } +}