Skip to content

Commit

Permalink
Refactor HistoricEventsInterface to allow testing
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed Oct 23, 2024
1 parent d7c2f5c commit 3ee4c7e
Show file tree
Hide file tree
Showing 26 changed files with 190 additions and 52 deletions.
5 changes: 2 additions & 3 deletions app/Module/AustrianHistoricEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

namespace Fisharebest\Webtrees\Module;

use Fisharebest\Webtrees\I18N;
use Illuminate\Support\Collection;

/**
Expand Down Expand Up @@ -52,9 +51,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'de':
return new Collection([
"1 EVEN Feldzug Karls des Großen gegen die Awaren\n2 DATE 791\n2 TYPE Österreichische Geschichte\n2 SOUR [Wikipedia:Geschichte Österreichs](https://de.wikipedia.org/wiki/Geschichte_%C3%96sterreichs#Fr%C3%BChmittelalter_(bis_976))\n3 CONT Im Jahr 791 führte Karl der Große einen ersten misslungenen Feldzug gegen die Awaren, konnte sie aber dennoch bis zum Wienerwald zurückdrängen und fränkische Stützpunkte in Comagena (Tulln) und Aelium Cetium (St. Pölten) errichten.",
Expand Down
4 changes: 2 additions & 2 deletions app/Module/AustrianPresidents.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'de':
return new Collection([
"1 EVEN Karl Seitz\n2 TYPE Präsident des Staatsdirektoriums\n2 DATE FROM 30 OCT 1918 TO 09 DEC 1920",
Expand Down
5 changes: 2 additions & 3 deletions app/Module/BritishMonarchs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

namespace Fisharebest\Webtrees\Module;

use Fisharebest\Webtrees\I18N;
use Illuminate\Support\Collection;

/**
Expand Down Expand Up @@ -52,9 +51,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'en-AU':
case 'en-GB':
case 'en-US':
Expand Down
4 changes: 2 additions & 2 deletions app/Module/BritishPrimeMinisters.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'en-AU':
case 'en-GB':
case 'en-US':
Expand Down
4 changes: 2 additions & 2 deletions app/Module/BritishSocialHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'en-AU':
case 'en-GB':
case 'en-US':
Expand Down
4 changes: 2 additions & 2 deletions app/Module/CzechMonarchsAndPresidents.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'cs':
return new Collection([
/** @link https://cs.wikipedia.org/wiki/Seznam_představitelů_českého_státu */
Expand Down
4 changes: 2 additions & 2 deletions app/Module/DutchMonarchs.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'nl':
return new Collection([
"1 EVEN Lodewijk I, de Lamme Koning (Lodewijk Napoleon Bonaparte)\n2 TYPE Koning van Holland\n2 DATE FROM 05 JUN 1806 TO 01 JUL 1810\n2 NOTE Koninkrijk Holland (1806 - 1810), vazalstaat van het Eerste Franse Keizerrijk",
Expand Down
4 changes: 2 additions & 2 deletions app/Module/DutchPrimeMinisters.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'nl':
return new Collection([
"1 EVEN Gerrit graaf Schimmelpenninck\n2 TYPE Voorzitter van de ministerraad\n2 DATE FROM 25 MAR 1848 TO 21 NOV 1848\n2 NOTE kabinet-Schimmelpenninck",
Expand Down
4 changes: 2 additions & 2 deletions app/Module/FrenchHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'fr':
case 'fr-CA':
return new Collection([
Expand Down
6 changes: 3 additions & 3 deletions app/Module/LowCountriesRulers.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'nl':
return new Collection([
"1 EVEN Koningen, graven en potestaten van Friesland\n2 TYPE vorstendom, graafschap, potestaat\n2 DATE FROM 600 TO 1515",
Expand Down Expand Up @@ -104,7 +104,7 @@ public function historicEventsAll(): Collection
"1 EVEN Koningen der Nederlanden\n2 TYPE koninkrijk\n2 DATE FROM 1831",
"1 EVEN Staten-Generaal van het Koninkrijk der Nederlanden\n2 TYPE koninkrijk\n2 DATE FROM 1848",
"1 EVEN Raad van State\n2 TYPE koninkrijk\n2 DATE FROM 1889 TO 1890",
"1 EVEN Koningin-regentes van Nederland\n2 TYPE koninkrijk\\n2 DATE FROM 1890 TO 1898",
"1 EVEN Koningin-regentes van Nederland\n2 TYPE koninkrijk\n2 DATE FROM 1890 TO 1898",
"1 EVEN Prins-regent van België\n2 TYPE koninkrijk\n2 DATE FROM 1944 TO 1950",
]);

Expand Down
2 changes: 1 addition & 1 deletion app/Module/ModuleHistoricEventsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface ModuleHistoricEventsInterface extends ModuleInterface
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection;
public function historicEventsAll(string $language_tag): Collection;

/**
* @return Collection<int,Fact>
Expand Down
4 changes: 2 additions & 2 deletions app/Module/ModuleHistoricEventsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function description(): string
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
return new Collection();
}
Expand All @@ -48,7 +48,7 @@ public function historicEventsForIndividual(Individual $individual): Collection
$min_date = $individual->getEstimatedBirthDate();
$max_date = $individual->getEstimatedDeathDate();

return $this->historicEventsAll()
return $this->historicEventsAll(I18N::languageTag())
->map(static fn (string $gedcom): Fact => new Fact($gedcom, $individual, 'histo'))
->filter(static fn (Fact $fact): bool => Date::compare($fact->date(), $min_date) >= 0)
->filter(static fn (Fact $fact): bool => Date::compare($fact->date(), $max_date) <= 0);
Expand Down
4 changes: 2 additions & 2 deletions app/Module/NewZealandPrimeMinisters.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'en-AU':
case 'en-GB':
case 'en-US':
Expand Down
4 changes: 2 additions & 2 deletions app/Module/USPresidents.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function isEnabledByDefault(): bool
/**
* @return Collection<int,string>
*/
public function historicEventsAll(): Collection
public function historicEventsAll(string $language_tag): Collection
{
switch (I18N::languageTag()) {
switch ($language_tag) {
case 'en-AU':
case 'en-GB':
case 'en-US':
Expand Down
13 changes: 11 additions & 2 deletions tests/app/Module/AustrianHistoricEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@

namespace Fisharebest\Webtrees\Module;

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(AustrianHistoricEvents::class)]
class AustrianHistoricEventsTest extends TestCase
{
public function testClass(): void
public function testEventsHaveValidDate(): void
{
self::assertTrue(class_exists(AustrianHistoricEvents::class));
$module = new AustrianHistoricEvents();

$individual = $this->createMock(Individual::class);

foreach ($module->historicEventsAll(language_tag: 'de') as $gedcom) {
$fact = new Fact(gedcom: $gedcom, parent: $individual, id: 'test');
self::assertTrue(condition: $fact->date()->isOK(), message: 'No date found in: ' . $gedcom);
}
}
}
13 changes: 11 additions & 2 deletions tests/app/Module/AustrianPresidentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@

namespace Fisharebest\Webtrees\Module;

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(AustrianPresidents::class)]
class AustrianPresidentsTest extends TestCase
{
public function testClass(): void
public function testEventsHaveValidDate(): void
{
self::assertTrue(class_exists(AustrianPresidents::class));
$module = new AustrianPresidents();

$individual = $this->createMock(Individual::class);

foreach ($module->historicEventsAll(language_tag: 'de') as $gedcom) {
$fact = new Fact(gedcom: $gedcom, parent: $individual, id: 'test');
self::assertTrue(condition: $fact->date()->isOK(), message: 'No date found in: ' . $gedcom);
}
}
}
13 changes: 11 additions & 2 deletions tests/app/Module/BritishMonarchsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@

namespace Fisharebest\Webtrees\Module;

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(BritishMonarchs::class)]
class BritishMonarchsTest extends TestCase
{
public function testClass(): void
public function testEventsHaveValidDate(): void
{
self::assertTrue(class_exists(BritishMonarchs::class));
$module = new BritishMonarchs();

$individual = $this->createMock(Individual::class);

foreach ($module->historicEventsAll(language_tag: 'en-GB') as $gedcom) {
$fact = new Fact(gedcom: $gedcom, parent: $individual, id: 'test');
self::assertTrue(condition: $fact->date()->isOK(), message: 'No date found in: ' . $gedcom);
}
}
}
13 changes: 11 additions & 2 deletions tests/app/Module/BritishPrimeMinistersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@

namespace Fisharebest\Webtrees\Module;

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(BritishPrimeMinisters::class)]
class BritishPrimeMinistersTest extends TestCase
{
public function testClass(): void
public function testEventsHaveValidDate(): void
{
self::assertTrue(class_exists(BritishPrimeMinisters::class));
$module = new BritishPrimeMinisters();

$individual = $this->createMock(Individual::class);

foreach ($module->historicEventsAll(language_tag: 'en-GB') as $gedcom) {
$fact = new Fact(gedcom: $gedcom, parent: $individual, id: 'test');
self::assertTrue(condition: $fact->date()->isOK(), message: 'No date found in: ' . $gedcom);
}
}
}
13 changes: 11 additions & 2 deletions tests/app/Module/BritishSocialHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@

namespace Fisharebest\Webtrees\Module;

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(BritishSocialHistory::class)]
class BritishSocialHistoryTest extends TestCase
{
public function testClass(): void
public function testEventsHaveValidDate(): void
{
self::assertTrue(class_exists(BritishSocialHistory::class));
$module = new BritishSocialHistory();

$individual = $this->createMock(Individual::class);

foreach ($module->historicEventsAll(language_tag: 'en-GB') as $gedcom) {
$fact = new Fact(gedcom: $gedcom, parent: $individual, id: 'test');
self::assertTrue(condition: $fact->date()->isOK(), message: 'No date found in: ' . $gedcom);
}
}
}
13 changes: 11 additions & 2 deletions tests/app/Module/CzechMonarchsAndPresidentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@

namespace Fisharebest\Webtrees\Module;

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(CzechMonarchsAndPresidents::class)]
class CzechMonarchsAndPresidentsTest extends TestCase
{
public function testClass(): void
public function testEventsHaveValidDate(): void
{
self::assertTrue(class_exists(CzechMonarchsAndPresidents::class));
$module = new CzechMonarchsAndPresidents();

$individual = $this->createMock(Individual::class);

foreach ($module->historicEventsAll(language_tag: 'cs') as $gedcom) {
$fact = new Fact(gedcom: $gedcom, parent: $individual, id: 'test');
self::assertTrue(condition: $fact->date()->isOK(), message: 'No date found in: ' . $gedcom);
}
}
}
13 changes: 11 additions & 2 deletions tests/app/Module/DutchMonarchsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@

namespace Fisharebest\Webtrees\Module;

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(DutchMonarchs::class)]
class DutchMonarchsTest extends TestCase
{
public function testClass(): void
public function testEventsHaveValidDate(): void
{
self::assertTrue(class_exists(DutchMonarchs::class));
$module = new DutchMonarchs();

$individual = $this->createMock(Individual::class);

foreach ($module->historicEventsAll(language_tag: 'nl') as $gedcom) {
$fact = new Fact(gedcom: $gedcom, parent: $individual, id: 'test');
self::assertTrue(condition: $fact->date()->isOK(), message: 'No date found in: ' . $gedcom);
}
}
}
Loading

0 comments on commit 3ee4c7e

Please sign in to comment.