This repository has been archived by the owner on Aug 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
III-2200: Json document transformer to return the embedded json-ld
- Loading branch information
1 parent
7d39946
commit c94e3fd
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/JsonDocument/JsonLdEmbeddingJsonDocumentTransformer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\Search\ElasticSearch\JsonDocument; | ||
|
||
use CultuurNet\UDB3\ReadModel\JsonDocument; | ||
use CultuurNet\UDB3\Search\JsonDocument\JsonDocumentTransformerInterface; | ||
|
||
class JsonLdEmbeddingJsonDocumentTransformer implements JsonDocumentTransformerInterface | ||
{ | ||
/** | ||
* @param JsonDocument $jsonDocument | ||
* @return JsonDocument | ||
*/ | ||
public function transform(JsonDocument $jsonDocument) | ||
{ | ||
$body = $jsonDocument->getBody(); | ||
|
||
return new JsonDocument( | ||
$jsonDocument->getId(), | ||
$body->originalEmbeddedJsonLd | ||
); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
tests/JsonDocument/JsonLdEmbeddingJsonDocumentTransformerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\Search\ElasticSearch\JsonDocument; | ||
|
||
use CultuurNet\UDB3\ReadModel\JsonDocument; | ||
|
||
class JsonLdEmbeddingJsonDocumentTransformerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var JsonLdEmbeddingJsonDocumentTransformer | ||
*/ | ||
private $transformer; | ||
|
||
public function setUp() | ||
{ | ||
$this->transformer = new JsonLdEmbeddingJsonDocumentTransformer(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_should_return_a_document_with_only_the_embedded_json_ld() | ||
{ | ||
$id = '8ea290f6-deb2-426e-820a-68eeefde9c4d'; | ||
|
||
$jsonLd = (object) [ | ||
'@id' => 'https://io.uitdatabank.be/events/8ea290f6-deb2-426e-820a-68eeefde9c4d', | ||
'@type' => 'Event', | ||
'location' => (object) [ | ||
'@id' => 'https://io.uitdatabank.be/places/9361008e-4e5b-4060-ad49-0866c8fa1860', | ||
'@type' => 'Place', | ||
'address' => (object) [ | ||
'nl' => (object) [ | ||
'streetAddress' => 'Eenmeilaan 35', | ||
'postalCode' => '3010', | ||
'addressLocality' => 'Kessel-Lo', | ||
'addressCountry' => 'BE', | ||
], | ||
], | ||
], | ||
]; | ||
|
||
$encodedJsonLd = json_encode($jsonLd); | ||
|
||
$indexed = (object) [ | ||
'@id' => 'https://io.uitdatabank.be/events/8ea290f6-deb2-426e-820a-68eeefde9c4d', | ||
'@type' => 'Event', | ||
'regions' => ['gem-leuven', 'prv-vlaams-brabant'], | ||
'address' => [ | ||
'nl' => (object) [ | ||
'streetAddress' => 'Eenmeilaan 35', | ||
'postalCode' => '3010', | ||
'addressLocality' => 'Kessel-Lo', | ||
'addressCountry' => 'BE', | ||
], | ||
], | ||
'location' => (object) [ | ||
'@id' => 'https://io.uitdatabank.be/places/9361008e-4e5b-4060-ad49-0866c8fa1860', | ||
'@type' => 'Place', | ||
'address' => [ | ||
'nl' => (object) [ | ||
'streetAddress' => 'Eenmeilaan 35', | ||
'postalCode' => '3010', | ||
'addressLocality' => 'Kessel-Lo', | ||
'addressCountry' => 'BE', | ||
], | ||
], | ||
], | ||
'foo' => 'bar', | ||
'originalEmbeddedJsonLd' => $encodedJsonLd, | ||
]; | ||
|
||
$expectedJsonLdDocument = new JsonDocument($id, $encodedJsonLd); | ||
$indexedDocument = new JsonDocument($id, json_encode($indexed)); | ||
|
||
$actualJsonLdDocument = $this->transformer->transform($indexedDocument); | ||
|
||
$this->assertEquals($expectedJsonLdDocument, $actualJsonLdDocument); | ||
$this->assertEquals($jsonLd, $actualJsonLdDocument->getBody()); | ||
} | ||
} |