Skip to content

Commit

Permalink
Merge pull request #644: Default values for JSON-LD
Browse files Browse the repository at this point in the history
* pr-644:
  fix: unit tests.
  fix: use default values in JsonLDProvider
  make jsonld configurable
  • Loading branch information
TiSiE committed Apr 7, 2021
2 parents 71a600a + d5d02f7 commit f9363f3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
33 changes: 32 additions & 1 deletion module/Jobs/src/Entity/Decorator/JsonLdProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function setOptions(array $options): void
$this->options = array_intersect_key($new, $this->options);
}

public function toJsonLd()
public function toJsonLd($default=[])
{
$organization = $this->job->getOrganization();
$organizationName = $organization ? $organization->getOrganizationName()->getName() : $this->job->getCompany();
Expand Down Expand Up @@ -95,6 +95,8 @@ public function toJsonLd()

$array += $this->generateSalary();

$array = array_replace_recursive($this->getDefault(), $default, $array);

return Json::encode($array);
}

Expand Down Expand Up @@ -188,4 +190,33 @@ private function generateSalary()
],
];
}

private function getDefault(){
return [
'@context'=>'http://schema.org/',
'@type' => 'JobPosting',
'identifier' => [
'@type' => 'PropertyValue',
],
'hiringOrganization' => [
'@type' => 'Organization',
],
'jobLocation' => [
'@type' => 'Place',
'address' => [
'@type' => 'PostalAddress',
'addressCountry' => 'DE',
]
],
'baseSalary' => [
'@type' => 'MonetaryAmount',
'currency' => 'EUR',
'value' => [
'@type' => 'QuantitiveValue',
'value' => 'node',
'unitText' => 'YEAR'
]
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,18 @@ public function testGeneratesJsonLdWithoutSalary()

$array = json_decode($json, JSON_OBJECT_AS_ARRAY);

$this->assertArrayNotHasKey('baseSalary', $array);
$expect = [
'@type' => 'MonetaryAmount',
'currency' => 'EUR',
'value' => [
'@type' => 'QuantitiveValue',
'value' => 'node',
'unitText' => 'YEAR'
]
];

$this->assertArrayHasKey('baseSalary', $array);
$this->assertEquals($expect, $array['baseSalary']);
}

public function testGeneratesJsonLdWithSalary()
Expand Down

0 comments on commit f9363f3

Please sign in to comment.