. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Factories; use Fisharebest\Webtrees\Date\FrenchDate; use Fisharebest\Webtrees\Date\GregorianDate; use Fisharebest\Webtrees\Date\HijriDate; use Fisharebest\Webtrees\Date\JalaliDate; use Fisharebest\Webtrees\Date\JewishDate; use Fisharebest\Webtrees\Date\JulianDate; use Fisharebest\Webtrees\Date\RomanDate; use Fisharebest\Webtrees\TestCase; /** * Test harness for the class CalendarDateFactory * * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory */ class CalendarDateFactoryTest extends TestCase { /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testEmptyDate(): void { $factory = new CalendarDateFactory(); $date = $factory->make(''); static::assertSame(GregorianDate::ESCAPE, $date->format('%@')); static::assertSame(0, $date->year); static::assertSame(0, $date->month); static::assertSame(0, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testValidCalendarEscape(): void { $factory = new CalendarDateFactory(); $calendar_escapes = [ FrenchDate::ESCAPE, GregorianDate::ESCAPE, HijriDate::ESCAPE, JalaliDate::ESCAPE, JewishDate::ESCAPE, JulianDate::ESCAPE, RomanDate::ESCAPE, ]; foreach ($calendar_escapes as $calendar_escape) { $date = $factory->make($calendar_escape); static::assertSame($calendar_escape, $date->format('%@')); static::assertSame(0, $date->year); static::assertSame(0, $date->month); static::assertSame(0, $date->day); } } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testInvalidCalendarEscapeIgnored(): void { $factory = new CalendarDateFactory(); $date = $factory->make('@#DSTARDATE@'); static::assertSame('@#DGREGORIAN@', $date->format('%@')); static::assertSame(0, $date->year); static::assertSame(0, $date->month); static::assertSame(0, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testDayMonthAndYear(): void { $factory = new CalendarDateFactory(); $date = $factory->make('01 JAN 1970'); static::assertSame('@#DGREGORIAN@', $date->format('%@')); static::assertSame(1970, $date->year); static::assertSame(1, $date->month); static::assertSame(1, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testMonthAndYear(): void { $factory = new CalendarDateFactory(); $date = $factory->make('JAN 1970'); static::assertSame('@#DGREGORIAN@', $date->format('%@')); static::assertSame(1970, $date->year); static::assertSame(1, $date->month); static::assertSame(0, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testYear(): void { $factory = new CalendarDateFactory(); $date = $factory->make('1970'); static::assertSame('@#DGREGORIAN@', $date->format('%@')); static::assertSame(1970, $date->year); static::assertSame(0, $date->month); static::assertSame(0, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testExtractedYear(): void { $factory = new CalendarDateFactory(); $date = $factory->make('THE MID 1960S'); static::assertSame('@#DGREGORIAN@', $date->format('%@')); static::assertSame(1960, $date->year); static::assertSame(0, $date->month); static::assertSame(0, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testExtractedMonthAndYear(): void { $factory = new CalendarDateFactory(); $date = $factory->make('PERHAPS FEB OR MAR IN 1960 or 1961'); static::assertSame('@#DGREGORIAN@', $date->format('%@')); static::assertSame(1960, $date->year); static::assertSame(2, $date->month); static::assertSame(0, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testExtractedDayMonthAndYear(): void { $factory = new CalendarDateFactory(); $date = $factory->make('PERHAPS 11 OR 12 FEB OR MAR IN 1960 or 1961'); static::assertSame('@#DGREGORIAN@', $date->format('%@')); static::assertSame(1960, $date->year); static::assertSame(2, $date->month); static::assertSame(11, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testExtractedMonth(): void { $factory = new CalendarDateFactory(); $date = $factory->make('PERHAPS FEB OR MAR'); static::assertSame('@#DGREGORIAN@', $date->format('%@')); static::assertSame(0, $date->year); static::assertSame(2, $date->month); static::assertSame(0, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testExtractedDayAndMonth(): void { $factory = new CalendarDateFactory(); $date = $factory->make('PERHAPS 11 OR 12 FEB OR MAR'); static::assertSame('@#DGREGORIAN@', $date->format('%@')); static::assertSame(0, $date->year); static::assertSame(2, $date->month); static::assertSame(11, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testUnambiguousOverrideWithHebrewMonth(): void { $factory = new CalendarDateFactory(); $date = $factory->make('@#DGREGORIAN@ 10 NSN 5432'); static::assertSame('@#DHEBREW@', $date->format('%@')); static::assertSame(5432, $date->year); static::assertSame(8, $date->month); static::assertSame(10, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testUnambiguousOverrideWithFrenchMonth(): void { $factory = new CalendarDateFactory(); $date = $factory->make('@#DGREGORIAN@ 10 PLUV 11'); static::assertSame('@#DFRENCH R@', $date->format('%@')); static::assertSame(11, $date->year); static::assertSame(5, $date->month); static::assertSame(10, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testUnambiguousOverrideWithHijriMonth(): void { $factory = new CalendarDateFactory(); $date = $factory->make('@#DGREGORIAN@ 10 SHAAB 1234'); static::assertSame('@#DHIJRI@', $date->format('%@')); static::assertSame(1234, $date->year); static::assertSame(8, $date->month); static::assertSame(10, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testUnambiguousOverrideWithJalaliMonth(): void { $factory = new CalendarDateFactory(); $date = $factory->make('@#DGREGORIAN@ 10 BAHMA 1234'); static::assertSame('@#DJALALI@', $date->format('%@')); static::assertSame(1234, $date->year); static::assertSame(11, $date->month); static::assertSame(10, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testUnambiguousOverrideWithJulianBCYear(): void { $factory = new CalendarDateFactory(); $date = $factory->make('@#DGREGORIAN@ 10 AUG 44 B.C.'); static::assertSame('@#DJULIAN@', $date->format('%@')); static::assertSame(-44, $date->year); static::assertSame(8, $date->month); static::assertSame(10, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::make */ public function testUnambiguousYearWithNoCalendar(): void { $factory = new CalendarDateFactory(); $date = $factory->make('3456'); static::assertSame('@#DHEBREW@', $date->format('%@')); static::assertSame(3456, $date->year); static::assertSame(0, $date->month); static::assertSame(0, $date->day); } /** * @covers \Fisharebest\Webtrees\Factories\CalendarDateFactory::supportedCalendars */ public function testSupportedCalendars(): void { $factory = new CalendarDateFactory(); $calendars = $factory->supportedCalendars(); static::assertNotEmpty($calendars); } }