tethys/tests/Feature/DoiClientTest.php

90 lines
2.6 KiB
PHP
Raw Normal View History

2021-02-26 16:02:07 +00:00
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Tethys\Utils\DoiClient;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
2021-02-26 16:02:07 +00:00
class DoiClientTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
// public function testExample()
// {
// $response = $this->get('/');
// $response->assertStatus(200);
// }
public function testCheckDoi()
{
$client = new DoiClient();
// $this->setExpectedException('Opus\Doi\ClientException');
$publish_id = 1;
$prefix = config('tethys.datacite_prefix');
$doiValue = $prefix . '/tethys.' . $publish_id;
$appUrl = config('app.url');
$landingPageUrl = $appUrl . "/dataset/" . $publish_id;
$result = $client->checkDoi(
$doiValue,
$landingPageUrl
);
$this->assertTrue($result);
2021-02-26 16:02:07 +00:00
$result = $client->checkDoi(
'10.5072/tethys-999',
'http://localhost/opus4/frontdoor/index/index/111'
);
$this->assertFalse($result);
}
2021-02-26 16:02:07 +00:00
// public function testRegisterDoiWithDataCiteTestAccount()
// {
// // $this->markTestSkipped(
// // 'Test kann nur manuell gestartet werden (Zugangsdaten zum MDS-Testservice von DataCite erforderlich)'
// // );
2021-02-26 16:02:07 +00:00
// $myRequest = new Request();
// $myRequest->setMethod('POST');
2021-02-26 16:02:07 +00:00
// $myRequest->request->add(
// [
// 'publish_id' => 1,
// // 'path' => 'https://www.demo.laudatio-repository.org/foo'
// ]
// );
2021-02-26 16:02:07 +00:00
// $doiController = new \App\Http\Controllers\DoiController(new DoiClient());
// $doiController->store($myRequest);
2021-02-26 16:02:07 +00:00
// // $client = new DoiClient();
// // $client->registerDoi(
// // '10.5072/tethys-999',
// // xmlMeta,
// // 'http://localhost/opus4/frontdoor/index/index/999'
// // );
// }
public function testGetMetadataForDoi()
{
$client = new DoiClient();
// $this->setExpectedException('Opus\Doi\ClientException');
$publish_id = 1;
$prefix = config('tethys.datacite_prefix');
$doiValue = $prefix . '/tethys.' . $publish_id;
$response = $client->getMetadataForDoi(
$doiValue
);
$this->assertEquals(200, $response->getStatusCode());
$testXml = new \SimpleXMLElement($response->getBody()->getContents());
Log::alert($testXml->saveXML());
2021-02-26 16:02:07 +00:00
}
}