2018-06-15 20:01:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group api
|
|
|
|
*/
|
|
|
|
class TAINACAN_REST_Importers_Controller extends TAINACAN_UnitApiTestCase {
|
|
|
|
|
2021-04-18 16:24:30 +00:00
|
|
|
public function test_create() {
|
|
|
|
$params = json_encode([ 'importer_slug' => 'csv' ]);
|
2018-06-15 20:01:25 +00:00
|
|
|
|
2018-06-18 18:40:01 +00:00
|
|
|
$request = new \WP_REST_Request('POST', $this->namespace . '/importers/session');
|
2018-06-15 20:01:25 +00:00
|
|
|
$request->set_body($params);
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
$this->assertEquals(201, $response->get_status());
|
|
|
|
$data = $response->get_data();
|
2019-10-11 22:13:51 +00:00
|
|
|
$this->assertTrue( isset($data['id']) );
|
|
|
|
$this->assertTrue( is_string($data['id']) );
|
|
|
|
}
|
2018-06-15 20:01:25 +00:00
|
|
|
|
2019-10-11 20:17:24 +00:00
|
|
|
public function test_update() {
|
|
|
|
global $Tainacan_Importer_Handler;
|
|
|
|
$slug='csv';
|
2019-10-11 20:33:43 +00:00
|
|
|
$importer = $Tainacan_Importer_Handler->initialize_importer($slug);
|
|
|
|
$Tainacan_Importer_Handler->save_importer_instance($importer);
|
2019-10-11 20:17:24 +00:00
|
|
|
$session_id = $importer->get_id();
|
|
|
|
|
|
|
|
$params = json_encode([
|
|
|
|
'url' => 'http://test.com',
|
|
|
|
'options' => ['delimiter' => ';'],
|
|
|
|
'collection' => [
|
|
|
|
'id' => 231,
|
|
|
|
'map' => [
|
|
|
|
30 => 'column1',
|
|
|
|
31 => 'column2'
|
|
|
|
],
|
|
|
|
'total_items' => 1234
|
|
|
|
]
|
2018-06-15 20:01:25 +00:00
|
|
|
]);
|
2019-10-11 20:17:24 +00:00
|
|
|
$request = new \WP_REST_Request('PATCH', $this->namespace . '/importers/session/' . $session_id);
|
2018-06-15 20:01:25 +00:00
|
|
|
$request->set_body($params);
|
|
|
|
|
2019-10-11 20:17:24 +00:00
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
$data = $response->get_data();
|
2018-06-15 20:01:25 +00:00
|
|
|
|
2019-10-11 20:17:24 +00:00
|
|
|
$this->assertEquals(200, $response->get_status());
|
|
|
|
$__importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id);
|
|
|
|
$this->assertEquals('http://test.com', $__importer->get_url());
|
|
|
|
$this->assertEquals(';', $__importer->get_option('delimiter'));
|
|
|
|
$this->assertEquals($__importer->get_url(), $data['url']);
|
|
|
|
$this->assertEquals(1234, $__importer->get_collections()[0]['total_items']);
|
|
|
|
}
|
2018-06-15 20:01:25 +00:00
|
|
|
|
2021-04-18 16:24:30 +00:00
|
|
|
}
|