fix metadatum mapper custom meta
This commit is contained in:
parent
0d76dbcac7
commit
59ccca49b6
|
@ -137,10 +137,19 @@ class Exposers {
|
|||
$ret = $item_arr;
|
||||
$metadatum_mapping = $item_arr['metadatum']['exposer_mapping'];
|
||||
if(array_key_exists($mapper->slug, $metadatum_mapping)) {
|
||||
if(is_array($mapper->metadata) && !array_key_exists( $metadatum_mapping[$mapper->slug], $mapper->metadata) ) {
|
||||
if(
|
||||
is_string($metadatum_mapping[$mapper->slug]) && is_array($mapper->metadata) && !array_key_exists( $metadatum_mapping[$mapper->slug], $mapper->metadata) ||
|
||||
is_array($metadatum_mapping[$mapper->slug]) && $mapper->allow_extra_metadata != true
|
||||
) {
|
||||
throw new \Exception('Invalid Mapper Option');
|
||||
}
|
||||
$ret = [$mapper->prefix.$metadatum_mapping[$mapper->slug].$mapper->sufix => $item_arr['value']]; //TODO Validate option
|
||||
$slug = '';
|
||||
if(is_string($metadatum_mapping[$mapper->slug])) {
|
||||
$slug = $metadatum_mapping[$mapper->slug];
|
||||
} else {
|
||||
$slug = $metadatum_mapping[$mapper->slug]['slug'];
|
||||
}
|
||||
$ret = [$mapper->prefix.$slug.$mapper->sufix => $item_arr['value']]; //TODO Validate option
|
||||
} elseif($mapper->slug == 'value') {
|
||||
$ret = [$item_arr['metadatum']['name'] => $item_arr['value']];
|
||||
} else {
|
||||
|
|
|
@ -156,6 +156,33 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
$this->assertEquals('TesteNewMetaUri.com', $data[1]['exposer_mapping']['dublin-core']['uri']);
|
||||
$this->assertEquals('text', $data[1]['exposer_mapping']['dublin-core']['type']);
|
||||
|
||||
$item__metadata_json = json_encode([
|
||||
'values' => 'TestValues_exposersCustomMeta',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $metadatum2->get_id() );
|
||||
$request->set_body($item__metadata_json);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'OAI-PMH',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
|
||||
$xml = new \SimpleXMLElement($data);
|
||||
$dc = $xml->children(\Tainacan\Exposers\Mappers\Dublin_Core::XML_DC_NAMESPACE);
|
||||
$this->assertEquals('adasdasdsaadsf', $dc->description);
|
||||
$this->assertEquals('item_teste_MetadatumMappers', $dc->title);
|
||||
$this->assertEquals('', $dc->contributor);
|
||||
$this->assertEquals('TestValues_exposersCustomMeta', $dc->TesteNewMeta);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue