Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Municipio\SchemaData\Utils\SchemaToPostTypesResolver\SchemaToPostTypeResolverInterface;
use WpService\Contracts\__;
use WpService\Contracts\_x;
use WpService\Contracts\ApplyFilters;

/**
* Class TaxonomiesFromSchemaType
Expand All @@ -23,7 +24,7 @@ class TaxonomiesFromSchemaType implements TaxonomiesFromSchemaTypeInterface
public function __construct(
private TaxonomyFactoryInterface $taxonomyFactory,
private SchemaToPostTypeResolverInterface $schemaToPostTypeResolver,
private __&_x $wpService,
private __&_x&ApplyFilters $wpService,
) {}

/**
Expand All @@ -34,16 +35,16 @@ public function __construct(
*/
public function create(string $schemaType): array
{
return (
[
'JobPosting' => $this->getJobPostingTaxonomies(),
'Event' => $this->getEventTaxonomies(),
'Project' => $this->getProjectTaxonomies(),
'ExhibitionEvent' => $this->getExhibitionEventTaxonomies(),
'ElementarySchool' => $this->getElementarySchoolTaxonomies(),
'Preschool' => $this->getPreschoolTaxonomies(),
][$schemaType] ?? []
);
$map = [
'JobPosting' => $this->getJobPostingTaxonomies(),
'Event' => $this->getEventTaxonomies(),
'Project' => $this->getProjectTaxonomies(),
'ExhibitionEvent' => $this->getExhibitionEventTaxonomies(),
'ElementarySchool' => $this->getElementarySchoolTaxonomies(),
'Preschool' => $this->getPreschoolTaxonomies(),
][$schemaType] ?? [];

return $this->wpService->applyFilters('Municipio/Schema/Taxonomy/' . $schemaType, $map[$schemaType] ?? [], $schemaType, $this->taxonomyFactory, $this->schemaToPostTypeResolver);
}

/**
Expand Down Expand Up @@ -74,6 +75,7 @@ private function getJobPostingTaxonomies(): array
return [
$this->createTaxonomy('JobPosting', 'relevantOccupation', $this->wpService->__('Job Categories', 'municipio'), $this->wpService->__('Job Category', 'municipio')),
$this->createTaxonomy('JobPosting', 'validThrough', $this->wpService->__('Latest Application Dates', 'municipio'), $this->wpService->__('Latest Application Date', 'municipio')),
$this->createTaxonomy('JobPosting', 'employmentType', $this->wpService->__('Employment Types', 'municipio'), $this->wpService->__('Employment Type', 'municipio')),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPUnit\Framework\TestCase;
use WpService\Contracts\__;
use WpService\Contracts\_x;
use WpService\Contracts\ApplyFilters;

class TaxonomiesFromSchemaTypeTest extends TestCase
{
Expand All @@ -19,7 +20,7 @@ protected function setUp(): void
$this->instance = new TaxonomiesFromSchemaType(
$this->getTaxonomyFactory(),
$this->getSchemaToPostTypeResolver(),
$this->getWpService()
$this->getWpService(),
);
}

Expand All @@ -30,23 +31,24 @@ public function testReturnsEmptyArrayForUnknownSchemaType(): void
$this->assertIsArray($taxonomies);
$this->assertEmpty($taxonomies);
}
#[TestDox("Returns array containing taxonomies for known schema types")]
#[DataProvider("knownSchemaTypesProvider")]

#[TestDox('Returns array containing taxonomies for known schema types')]
#[DataProvider('knownSchemaTypesProvider')]
public function testReturnsTaxonomiesForKnownSchemaTypes(string $schemaType): void
{
// Assert array contains only instances of TaxonomyInterface
$this->assertEachInArrayIsInstanceOf(
$this->instance->create($schemaType),
TaxonomyInterface::class
TaxonomyInterface::class,
);
}

public static function knownSchemaTypesProvider(): array
{
return [
'JobPosting' => ['JobPosting'],
'Event' => ['Event'],
'Project' => ['Project'],
'Event' => ['Event'],
'Project' => ['Project'],
];
}

Expand All @@ -67,18 +69,24 @@ private function getSchemaToPostTypeResolver(): SchemaToPostTypeResolverInterfac
return $this->createMock(SchemaToPostTypeResolverInterface::class);
}

private function getWpService(): __|_x
private function getWpService(): __|_x|ApplyFilters
{
return new class implements __, _x {
return new class implements __, _x, ApplyFilters {
public function __($text, ...$args): string
{
return $text;
}

// phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
public function _x($text, $context, ...$args): string
{
return $text;
}

public function applyFilters(string $tag, $value, ...$args): mixed
{
return $value;
}
};
}
}
Loading