Skip to content

Commit 14dfc1e

Browse files
authored
Merge pull request #539 from cross-solution/develop
Release 0.33.3
2 parents f165c61 + fa8d1c1 commit 14dfc1e

File tree

2 files changed

+64
-13
lines changed

2 files changed

+64
-13
lines changed

module/Jobs/src/Entity/Decorator/JsonLdProvider.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class JsonLdProvider implements JsonLdProviderInterface
3131
/**
3232
* the decorated job entity.
3333
*
34-
* @var \Jobs\Entity\JobInterface
34+
* @var \Jobs\Entity\JobInterface|\Jobs\Entity\Job
3535
*/
3636
private $job;
3737

@@ -63,7 +63,6 @@ public function toJsonLd()
6363
'@type' => 'JobPosting',
6464
'title' => $this->job->getTitle(),
6565
'description' => $this->getDescription($this->job->getTemplateValues()),
66-
'rate' => $this->getRate(),
6766
'datePosted' => $dateStart,
6867
'identifier' => [
6968
'@type' => 'PropertyValue',
@@ -82,6 +81,8 @@ public function toJsonLd()
8281
'validThrough' => $dateEnd
8382
];
8483

84+
$array += $this->generateSalary();
85+
8586
return Json::encode($array);
8687
}
8788

@@ -138,17 +139,24 @@ private function getDescription(TemplateValuesInterface $values)
138139
return $description;
139140
}
140141

141-
/**
142-
* Generates a rate from salary entity
143-
*
144-
* @return string
145-
*/
146-
private function getRate()
142+
private function generateSalary()
147143
{
148144
$salary = $this->job->getSalary();
149145

150-
return ($salary && !is_null($salary->getValue())) ?
151-
($salary->getValue() . ' ' . $salary->getCurrency() . '/' . $salary->getUnit()) :
152-
/*@translate*/ 'Undefined';
146+
if (!$salary || null === $salary->getValue()) {
147+
return [];
148+
}
149+
150+
return [
151+
'baseSalary' => [
152+
'@type' => 'MonetaryAmount',
153+
'currency' => $salary->getCurrency(),
154+
'value' => [
155+
'@type' => 'QuantitiveValue',
156+
'value' => $salary->getValue(),
157+
'unitText' => $salary->getUnit()
158+
],
159+
],
160+
];
153161
}
154162
}

module/Jobs/test/JobsTest/Entity/Decorator/JsonLdProviderTest.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Jobs\Entity\Job;
1717
use Jobs\Entity\JsonLdProviderInterface;
1818
use Jobs\Entity\Location;
19+
use Jobs\Entity\Salary;
1920
use Organizations\Entity\Organization;
2021
use Organizations\Entity\OrganizationName;
2122

@@ -43,13 +44,16 @@ class JsonLdProviderTest extends \PHPUnit_Framework_TestCase
4344
'@testInheritance' => ['as_reflection' => true],
4445
'@testConstructSetsJob' => false,
4546
'@testGeneratesJsonLdWithoutOrganizationAndDate' => [
46-
'args' => 'getJobWoOrgAndDate'
47+
'args' => 'getJobWoOrgAndDate',
4748
],
49+
'@testGeneratesJsonLdWithSalary' => [
50+
'args' => 'getJobWithSalary',
51+
]
4852
];
4953

5054
private $inheritance = [ JsonLdProviderInterface::class ];
5155

52-
private function getJob($withOrganization=true, $withDatePublishStart=true)
56+
private function getJob($withOrganization=true, $withDatePublishStart=true, $withSalary=false)
5357
{
5458
$job = new Job();
5559
$organization = new Organization();
@@ -67,6 +71,10 @@ private function getJob($withOrganization=true, $withDatePublishStart=true)
6771
$locations->add($location);
6872
$job->setLocations($locations);
6973

74+
if ($withSalary) {
75+
$job->getSalary()->setValue(1000)->setCurrency('EUR')->setUnit(Salary::UNIT_DAY);
76+
}
77+
7078
return [$job];
7179
}
7280

@@ -75,6 +83,11 @@ private function getJobWoOrgAndDate()
7583
return $this->getJob(false, false);
7684
}
7785

86+
private function getJobWithSalary()
87+
{
88+
return $this->getJob(false, false, true);
89+
}
90+
7891
public function testConstructSetsJob()
7992
{
8093
$job = new Job();
@@ -102,4 +115,34 @@ public function testGeneratesJsonLdWithoutOrganizationAndDate()
102115

103116
$this->assertNull($array['datePosted']);
104117
}
118+
119+
public function testGeneratesJsonLdWithoutSalary()
120+
{
121+
$json = $this->target->toJsonLd();
122+
123+
$array = json_decode($json, JSON_OBJECT_AS_ARRAY);
124+
125+
$this->assertArrayNotHasKey('baseSalary', $array);
126+
}
127+
128+
public function testGeneratesJsonLdWithSalary()
129+
{
130+
$json = $this->target->toJsonLd();
131+
132+
$array = json_decode($json, JSON_OBJECT_AS_ARRAY);
133+
134+
$this->assertArrayHasKey('baseSalary', $array);
135+
136+
$expect = [
137+
'@type' => 'MonetaryAmount',
138+
'currency' => 'EUR',
139+
'value' => [
140+
'@type' => 'QuantitiveValue',
141+
'value' => 1000,
142+
'unitText' => Salary::UNIT_DAY,
143+
],
144+
];
145+
146+
$this->assertEquals($expect, $array['baseSalary']);
147+
}
105148
}

0 commit comments

Comments
 (0)