23 import(
'tests.functional.plugins.importexport.FunctionalDoiExportTest');
24 import(
'plugins.importexport.datacite.DataciteExportPlugin');
35 protected function setUp() : void {
36 $this->pluginId =
'datacite';
44 $this->dcPassword =
Config::getVar(
'debug',
'webtest_datacite_pw');
45 if (empty($baseUrl) || empty($this->dcPassword)) {
46 $this->markTestSkipped(
47 'Please set webtest_base_url and webtest_datacite_pw in your ' .
48 'config.php\'s [debug] section to the base url of your test server ' .
49 'and the password of your DataCite test account.'
53 $indexPage = $baseUrl .
'/index.php/test/manager/importexport/plugin/DataciteExportPlugin';
55 'index' => $indexPage,
56 'settings' => $baseUrl .
'/index.php/test/manager/plugin/importexport/DataciteExportPlugin/settings'
59 $this->defaultPluginSettings = array(
60 'username' => self::TEST_ACCOUNT,
61 'password' => $this->dcPassword
64 parent::setUp(
'10.5072');
66 $this->configurePlugin();
79 $this->doTestExpectJournalNameAsPublisher();
80 $this->doExportObjectTest(
'issue', 1,
'DataciteExportPlugin',
'datacite-issue.xml');
89 self::assertContains(
'<publisher>test</publisher>', $xml);
90 self::assertContains(
'<creatorName>test</creatorName>', $xml);
94 '<publisher>test</publisher>',
95 '<publisher>Test Publisher</publisher>',
101 '<creatorName>test</creatorName>',
102 '<creatorName>Test Publisher</creatorName>',
117 $this->doExportObjectTest(
'article', 1,
'DataciteExportPlugin',
'datacite-article.xml');
130 $sampleFiles = array(
131 'datacite-galley-1.xml',
132 'datacite-galley-2.xml',
133 'datacite-galley-3.xml',
135 $this->doExportObjectTest(
'galley', array(1,2,3),
'DataciteExportPlugin', $sampleFiles);
151 'galley' => array(1,2,3),
154 'datacite-article.xml',
155 'datacite-galley-1.xml',
156 'datacite-galley-2.xml',
157 'datacite-galley-3.xml',
158 'datacite-issue.xml',
160 parent::testExportUnregisteredDois(
'DataciteExportPlugin', $objects, $xmlFiles);
178 parent::testRegisterOrExportSpecificObjects(
'DataciteExportPlugin', array(
'issue',
'article',
'galley'), self::TEST_ACCOUNT);
186 parent::testRegisterUnregisteredDois(
'DataciteExportPlugin', array(
'Issue',
'Article',
'Galley'), self::TEST_ACCOUNT);
189 $registrationTests = array(
190 array(
'datacite-issue.xml',
'issue/view/1',
'10.5072/t.v1i1'),
191 array(
'datacite-article.xml',
'article/view/1',
'10.5072/t.v1i1.1'),
192 array(
'datacite-galley-1.xml',
'article/view/1/1',
'10.5072/t.v1i1.1.g1'),
193 array(
'datacite-galley-2.xml',
'article/view/1/2',
'10.5072/t.v1i1.1.g2'),
194 array(
'datacite-galley-3.xml',
'article/view/1/3',
'10.5072/t.v1i1.1.g3'),
196 foreach($registrationTests as $registrationTest) {
197 list($sampleFile, $targetUrl, $doi) = $registrationTest;
198 $targetUrl =
'http://example.com/index.php/test/' . $targetUrl;
216 parent::testObjectsWithoutDOICannotBeSelectedForExport(array(
'issues',
'articles',
'galleys',
'all'));
226 'username' =>
'some-test-symbol',
227 'password' =>
'some-password'
230 'username' =>
'some-other-symbol',
231 'password' =>
'another-password'
235 'username' => TEST_INPUTTYPE_TEXT,
236 'password' => TEST_INPUTTYPE_TEXT
238 parent::testPluginSettings($tests, $inputTypes);
251 parent::testConfigurationError(array(
'issues',
'articles',
'galleys',
'all'));
280 array(
'issues',
'1',
'datacite-issue.xml'),
281 array(
'articles',
'1',
'datacite-article.xml'),
282 array(
'galleys',
'1',
'datacite-galley-1.xml'),
283 array(
'galleys',
'1 2 3', array(
'datacite-galley-1.xml',
'datacite-galley-2.xml',
'datacite-galley-3.xml')),
286 foreach($examples as $example) {
287 list($exportObjectType, $objectIds, $xmlFiles) = $example;
288 parent::testExportAndRegisterObjectsViaCli(
'DataciteExportPlugin',
'export', $exportObjectType, $objectIds, $xmlFiles);
289 parent::testExportAndRegisterObjectsViaCli(
'DataciteExportPlugin',
'register', $exportObjectType, $objectIds);
298 parent::testUnsupportedObjectTypeCliError(
'DataciteExportPlugin');
306 parent::testNonExistentJournalPathCliError(
'DataciteExportPlugin');
314 parent::testOutputFileNotWritableCliError(
'DataciteExportPlugin');
322 parent::testNonExistentObjectIdCliError(
'DataciteExportPlugin');
334 import(
'lib.pkp.classes.helpers.PKPCurlHelper');
339 curl_setopt($curlCh, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
340 curl_setopt($curlCh, CURLOPT_USERPWD, $login);
343 $apiUrl =
"https://mds.datacite.org/%action/$doi?testMode=true";
345 curl_setopt($curlCh, CURLOPT_RETURNTRANSFER,
true);
349 'metadata' => $sampleFile
351 foreach($tests as $action => $expectedResponse) {
353 curl_setopt($curlCh, CURLOPT_URL, str_replace(
'%action', $action, $apiUrl));
359 for ($secs=0; $secs <= 60 && $tryAgain; $secs+=10) {
362 if ($lastStatus == 204) {
365 $response = curl_exec($curlCh);
366 $lastStatus = curl_getinfo($curlCh, CURLINFO_HTTP_CODE);
367 $tryAgain = ($lastStatus == 204);
370 if ($lastStatus == 204) {
371 self::fail(
"The DOI $doi has been correctly registered but is not yet available " .
372 "due to Handle's latency. Please re-execute this test in a few minutes.");
376 self::assertEquals(200, $lastStatus);
377 if ($action ==
'doi') {
379 self::assertEquals($expectedTargetUrl, $response);
382 $this->assertXml($sampleFile, $response);
386 }
catch(Exception $e) {
401 $xml = str_replace(
'##editor.issues.pages##',
'Pages', $xml);
404 if (strpos($xml,
'<date dateType="Updated">') !==
false) {
412 $article = $submissionDao->getById(1);
413 $modifiedDate = date(
'Y-m-d', strtotime($article->getLastModified()));
414 $xml = str_replace(
'<date dateType="Updated">' . $modifiedDate,
'<date dateType="Updated">2011-12-09', $xml);
417 return parent::cleanXml($xml);