add oai-pmh dublin core format support
This commit is contained in:
parent
39331653f1
commit
becba0fd2d
|
@ -13,6 +13,7 @@ class Exposers {
|
|||
|
||||
public function __construct() {
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\Xml');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\OAI_PMH');
|
||||
$this->register_exposer_mapper('Tainacan\Exposers\Mappers\Dublin_Core');
|
||||
|
||||
add_filter( 'rest_request_after_callbacks', [$this, 'rest_request_after_callbacks'], 10, 3 );
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
|
||||
class OAI_PMH extends Xml {
|
||||
|
||||
const XML_OAI_DC_NAMESPACE = "http://www.openarchives.org/OAI/2.0/oai_dc/";
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
* @see \Tainacan\Exposers\Types\Type::rest_request_after_callbacks()
|
||||
*/
|
||||
public function rest_request_after_callbacks( $response, $handler, $request ) {
|
||||
$response->set_headers( ['Content-Type: application/xml; charset=' . get_option( 'blog_charset' )] );
|
||||
$xml = new \SimpleXMLElement(apply_filters('tainacan-exposer-head', '<?xml version="1.0" encoding="UTF-8"?>
|
||||
<oai_dc:dc
|
||||
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
|
||||
http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
|
||||
</oai_dc:dc>'
|
||||
));
|
||||
$namespace = apply_filters('tainacan-oai-pmh-namespace', \Tainacan\Exposers\Mappers\Dublin_Core::XML_DC_NAMESPACE);
|
||||
$this->array_to_xml($response->get_data(), apply_filters('tainacan-oai-pmh-root', $xml), $namespace);
|
||||
$response->set_data($xml->asXml());
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
|
@ -58,8 +58,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
return ['collection' => $collection, 'item' => $item, 'field' => $field];
|
||||
}
|
||||
|
||||
public function test_exposers() {
|
||||
$this->create_meta_requirements();
|
||||
public function test_xml_exposer() {
|
||||
global $Tainacan_Fields, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
@ -77,7 +76,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals($item->get_id() , $data['item']['id']);
|
||||
$this->assertEquals($item->get_id(), $data['item']['id']);
|
||||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
|
@ -121,7 +120,30 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('item_teste_Expose', $dc->title);
|
||||
$this->assertEquals('TestValues_exposers', $dc->language);
|
||||
|
||||
//echo $rdf->asXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group oai-pmh
|
||||
*/
|
||||
public function test_oai_pmh() {
|
||||
global $Tainacan_Fields, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'OAI-PMH',
|
||||
'exposer-map' => 'Dublin Core',
|
||||
]);
|
||||
$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('adasdasdsa', $dc->description);
|
||||
$this->assertEquals('item_teste_Expose', $dc->title);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue