Skip to content

Commit

Permalink
Merge pull request #539 from cross-solution/develop
Browse files Browse the repository at this point in the history
Release 0.33.3
  • Loading branch information
cbleek committed Mar 25, 2019
2 parents f165c61 + fa8d1c1 commit 14dfc1e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 13 deletions.
30 changes: 19 additions & 11 deletions module/Jobs/src/Entity/Decorator/JsonLdProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class JsonLdProvider implements JsonLdProviderInterface
/**
* the decorated job entity.
*
* @var \Jobs\Entity\JobInterface
* @var \Jobs\Entity\JobInterface|\Jobs\Entity\Job
*/
private $job;

Expand Down Expand Up @@ -63,7 +63,6 @@ public function toJsonLd()
'@type' => 'JobPosting',
'title' => $this->job->getTitle(),
'description' => $this->getDescription($this->job->getTemplateValues()),
'rate' => $this->getRate(),
'datePosted' => $dateStart,
'identifier' => [
'@type' => 'PropertyValue',
Expand All @@ -82,6 +81,8 @@ public function toJsonLd()
'validThrough' => $dateEnd
];

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

return Json::encode($array);
}

Expand Down Expand Up @@ -138,17 +139,24 @@ private function getDescription(TemplateValuesInterface $values)
return $description;
}

/**
* Generates a rate from salary entity
*
* @return string
*/
private function getRate()
private function generateSalary()
{
$salary = $this->job->getSalary();

return ($salary && !is_null($salary->getValue())) ?
($salary->getValue() . ' ' . $salary->getCurrency() . '/' . $salary->getUnit()) :
/*@translate*/ 'Undefined';
if (!$salary || null === $salary->getValue()) {
return [];
}

return [
'baseSalary' => [
'@type' => 'MonetaryAmount',
'currency' => $salary->getCurrency(),
'value' => [
'@type' => 'QuantitiveValue',
'value' => $salary->getValue(),
'unitText' => $salary->getUnit()
],
],
];
}
}
47 changes: 45 additions & 2 deletions module/Jobs/test/JobsTest/Entity/Decorator/JsonLdProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Jobs\Entity\Job;
use Jobs\Entity\JsonLdProviderInterface;
use Jobs\Entity\Location;
use Jobs\Entity\Salary;
use Organizations\Entity\Organization;
use Organizations\Entity\OrganizationName;

Expand Down Expand Up @@ -43,13 +44,16 @@ class JsonLdProviderTest extends \PHPUnit_Framework_TestCase
'@testInheritance' => ['as_reflection' => true],
'@testConstructSetsJob' => false,
'@testGeneratesJsonLdWithoutOrganizationAndDate' => [
'args' => 'getJobWoOrgAndDate'
'args' => 'getJobWoOrgAndDate',
],
'@testGeneratesJsonLdWithSalary' => [
'args' => 'getJobWithSalary',
]
];

private $inheritance = [ JsonLdProviderInterface::class ];

private function getJob($withOrganization=true, $withDatePublishStart=true)
private function getJob($withOrganization=true, $withDatePublishStart=true, $withSalary=false)
{
$job = new Job();
$organization = new Organization();
Expand All @@ -67,6 +71,10 @@ private function getJob($withOrganization=true, $withDatePublishStart=true)
$locations->add($location);
$job->setLocations($locations);

if ($withSalary) {
$job->getSalary()->setValue(1000)->setCurrency('EUR')->setUnit(Salary::UNIT_DAY);
}

return [$job];
}

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

private function getJobWithSalary()
{
return $this->getJob(false, false, true);
}

public function testConstructSetsJob()
{
$job = new Job();
Expand Down Expand Up @@ -102,4 +115,34 @@ public function testGeneratesJsonLdWithoutOrganizationAndDate()

$this->assertNull($array['datePosted']);
}

public function testGeneratesJsonLdWithoutSalary()
{
$json = $this->target->toJsonLd();

$array = json_decode($json, JSON_OBJECT_AS_ARRAY);

$this->assertArrayNotHasKey('baseSalary', $array);
}

public function testGeneratesJsonLdWithSalary()
{
$json = $this->target->toJsonLd();

$array = json_decode($json, JSON_OBJECT_AS_ARRAY);

$this->assertArrayHasKey('baseSalary', $array);

$expect = [
'@type' => 'MonetaryAmount',
'currency' => 'EUR',
'value' => [
'@type' => 'QuantitiveValue',
'value' => 1000,
'unitText' => Salary::UNIT_DAY,
],
];

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

0 comments on commit 14dfc1e

Please sign in to comment.