prototype urls test, rewrite exposers to use exposer_type instead esposer_type and get all exposer urls
This commit is contained in:
parent
3c1d3fd5d9
commit
94f02ce0cd
|
@ -199,8 +199,8 @@ class Exposers {
|
|||
$Tainacan_Exposers = self::get_instance();
|
||||
$query_url_params = $request->get_query_params();
|
||||
if (
|
||||
is_array($query_url_params) && array_key_exists('exposer-type', $query_url_params) &&
|
||||
$Tainacan_Exposers->has_type($query_url_params['exposer-type'])
|
||||
is_array($query_url_params) && array_key_exists('exposer_type', $query_url_params) &&
|
||||
$Tainacan_Exposers->has_type($query_url_params['exposer_type'])
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
@ -254,16 +254,16 @@ class Exposers {
|
|||
$query_url_params = $request->get_query_params();
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
if(
|
||||
is_array($body) && array_key_exists('exposer-type', $body) &&
|
||||
$Tainacan_Exposers->has_type($body['exposer-type'])
|
||||
is_array($body) && array_key_exists('exposer_type', $body) &&
|
||||
$Tainacan_Exposers->has_type($body['exposer_type'])
|
||||
) {
|
||||
$type = $Tainacan_Exposers->check_class_name($body['exposer-type'], true);
|
||||
$type = $Tainacan_Exposers->check_class_name($body['exposer_type'], true);
|
||||
return new $type;
|
||||
} elseif (
|
||||
is_array($query_url_params) && array_key_exists('exposer-type', $query_url_params) &&
|
||||
$Tainacan_Exposers->has_type($query_url_params['exposer-type'])
|
||||
is_array($query_url_params) && array_key_exists('exposer_type', $query_url_params) &&
|
||||
$Tainacan_Exposers->has_type($query_url_params['exposer_type'])
|
||||
){
|
||||
$type = $Tainacan_Exposers->check_class_name($query_url_params['exposer-type'], true);
|
||||
$type = $Tainacan_Exposers->check_class_name($query_url_params['exposer_type'], true);
|
||||
return new $type;
|
||||
}
|
||||
return false;
|
||||
|
@ -354,6 +354,27 @@ class Exposers {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of registered types
|
||||
* @param string $output output format, ARRAY_N or OBJECT
|
||||
* @return array of slug or array of \Tainacan\Exposers\Types\Type
|
||||
*/
|
||||
public function get_types($output = \ARRAY_N) {
|
||||
$ret = [];
|
||||
switch ($output) {
|
||||
case \OBJECT:
|
||||
foreach ($this->types as $type) {
|
||||
$ret[] = new $type;
|
||||
}
|
||||
break;
|
||||
case \ARRAY_N:
|
||||
default:
|
||||
return $this->types;
|
||||
break;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \WP_REST_Response $response
|
||||
|
@ -395,4 +416,35 @@ class Exposers {
|
|||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $base_url url base for exposer parameters append
|
||||
* @return string|string[][]
|
||||
*/
|
||||
public static function get_exposer_urls($base_url = '') {
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
$mappers = $Tainacan_Exposers->get_mappers();
|
||||
$types = $Tainacan_Exposers->get_types(\OBJECT);
|
||||
$urls = [];
|
||||
foreach ($types as $type) {
|
||||
$url = $base_url.(strpos($base_url, '?') === false ? '?' : '&').'exposer_type='.$type->slug;
|
||||
$urls[$type->slug] = [$url];
|
||||
if(is_array($type->get_mappers())) {
|
||||
$first = true; // first is default, jump
|
||||
foreach ($type->get_mappers() as $type_mapper) {
|
||||
if($first) {
|
||||
$first = false;
|
||||
continue;
|
||||
}
|
||||
$urls[$type->slug][] = $url.'&exposer_map='.$type_mapper;
|
||||
}
|
||||
} else {
|
||||
foreach ($mappers as $type_mapper) {
|
||||
$urls[$type->slug][] = $url.'&exposer_map='.$type_mapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $urls;
|
||||
}
|
||||
}
|
|
@ -193,7 +193,7 @@ class TAINACAN_REST_Export_Controller extends TAINACAN_UnitApiTestCase {
|
|||
extract($this->create_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Xml',
|
||||
'exposer_type' => 'Xml',
|
||||
'exposer_map' => 'Value',
|
||||
'export-background' => false
|
||||
]);
|
||||
|
@ -232,7 +232,7 @@ class TAINACAN_REST_Export_Controller extends TAINACAN_UnitApiTestCase {
|
|||
extract($this->create_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Xml',
|
||||
'exposer_type' => 'Xml',
|
||||
'exposer-map' => 'Value',
|
||||
'export-background' => false
|
||||
]);
|
||||
|
|
|
@ -129,7 +129,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Xml',
|
||||
'exposer_type' => 'Xml',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->metadatum->get_id() );
|
||||
|
@ -151,7 +151,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers', $data['dc:language']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Xml',
|
||||
'exposer_type' => 'Xml',
|
||||
'exposer_map' => 'Dublin Core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
|
@ -204,7 +204,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers_slug', $data['dc:language']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'xml',
|
||||
'exposer_type' => 'xml',
|
||||
'exposer_map' => 'dublin-core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
|
@ -231,7 +231,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
extract($this->create_meta_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'OAI-PMH',
|
||||
'exposer_type' => 'OAI-PMH',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -254,7 +254,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
extract($this->create_meta_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Html',
|
||||
'exposer_type' => 'Html',
|
||||
'exposer_map' => 'Value'
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
|
@ -314,7 +314,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Csv',
|
||||
'exposer_type' => 'Csv',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -462,7 +462,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'json-ld',
|
||||
'exposer_type' => 'json-ld',
|
||||
'exposer_map' => 'dublin-core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
|
@ -479,6 +479,26 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group exposer_urls
|
||||
*/
|
||||
/*public function test_exposer_urls() {
|
||||
global $Tainacan_Metadata, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$id = $item->get_id();
|
||||
$base_url = "{$this->namespace}/items/{$id}/";
|
||||
$urls = \Tainacan\Exposers\Exposers::get_exposer_urls($base_url);
|
||||
foreach ($urls as $type => $type_urls) {
|
||||
foreach ($type_urls as $url) {
|
||||
$request = new \WP_REST_Request('GET', $url);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status(), $url);
|
||||
}
|
||||
}
|
||||
}*/ // TODO automate test this
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -168,7 +168,7 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'OAI-PMH',
|
||||
'exposer_type' => 'OAI-PMH',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
|
Loading…
Reference in New Issue