Open Journal Systems  3.3.0
FunctionalMedraExportTestCase.php
1 <?php
2 
23 import('tests.functional.plugins.importexport.FunctionalDoiExportTest');
24 import('plugins.importexport.medra.MedraExportPlugin');
25 
26 class FunctionalMedraExportTest extends FunctionalDoiExportTest {
27  const TEST_ACCOUNT = 'TEST_OJS';
28 
32  protected function setUp() : void {
33  $this->pluginId = 'medra';
34 
35  // Retrieve and check configuration. (We're in a chicken
36  // and egg situation: This means that we cannot call
37  // parent::setUp() at this point so we have to retrieve
38  // the base URL here although it will be retrieved again
39  // in the parent class.)
40  $baseUrl = Config::getVar('debug', 'webtest_base_url');
41  $medraPassword = Config::getVar('debug', 'webtest_medra_pw');
42  if (empty($baseUrl) || empty($medraPassword)) {
43  $this->markTestSkipped(
44  'Please set webtest_base_url and webtest_medra_pw in your ' .
45  'config.php\'s [debug] section to the base url of your test server ' .
46  'and the password of your Medra test account.'
47  );
48  }
49 
50  $this->pages = array(
51  'index' => $baseUrl . '/index.php/test/manager/importexport/plugin/MedraExportPlugin',
52  'settings' => $baseUrl . '/index.php/test/manager/plugin/importexport/MedraExportPlugin/settings'
53  );
54 
55  $this->defaultPluginSettings = array(
56  'username' => self::TEST_ACCOUNT,
57  'password' => $medraPassword,
58  'registrantName' => 'Registrant',
59  'fromCompany' => 'From Company',
60  'fromName' => 'From Person',
61  'fromEmail' => 'from@email.com',
62  'publicationCountry' => 'US',
63  'exportIssuesAs' => O4DOI_ISSUE_AS_WORK
64  );
65 
66  parent::setUp('1749');
67  }
68 
69 
80  public function testExportSerialIssueAsWork() {
81  $this->removeRegisteredDois('MedraExportPlugin');
82  $this->configurePlugin(array('exportIssuesAs' => O4DOI_ISSUE_AS_WORK));
83  $this->doTestExpectJournalNameAsPublisher();
84  $this->doExportObjectTest('issue', 1, 'MedraExportPlugin', 'serial-issue-as-work.xml');
85  }
86 
87 
91  protected function checkThatPublisherIsJournalName($xml) {
92  // Test that the publisher is set to the journal title.
93  self::assertContains('<PublisherName>test</PublisherName>', $xml);
94 
95  // Change publisher to the default.
96  return str_replace(
97  '<PublisherName>test</PublisherName>',
98  '<PublisherName>Test Publisher</PublisherName>',
99  $xml
100  );
101  }
102 
103 
113  $this->removeRegisteredDois('MedraExportPlugin');
114  $this->configurePlugin(array('exportIssuesAs' => O4DOI_ISSUE_AS_MANIFESTATION));
115  $this->doExportObjectTest('issue', 1, 'MedraExportPlugin', 'serial-issue-as-manifestation.xml');
116  }
117 
118 
127  public function testExportSerialArticleAsWork() {
128  $this->removeRegisteredDois('MedraExportPlugin');
129  $this->configurePlugin(array('exportIssuesAs' => O4DOI_ISSUE_AS_WORK));
130  $this->doExportObjectTest('article', 1, 'MedraExportPlugin', 'serial-article-as-work-1.xml');
131  }
132 
133 
144  $this->removeRegisteredDois('MedraExportPlugin');
145  $this->configurePlugin(array('exportIssuesAs' => O4DOI_ISSUE_AS_MANIFESTATION));
146  $this->doExportObjectTest('galley', 1, 'MedraExportPlugin', 'serial-article-as-manifestation-1.xml', true);
147  $this->doExportObjectTest('galley', array(1,2,3), 'MedraExportPlugin', 'serial-article-as-manifestation-2.xml', true);
148  }
149 
150 
159  public function testExportUnregisteredDois() {
160  $this->removeRegisteredDois('MedraExportPlugin');
161  $this->configurePlugin(array('exportIssuesAs' => O4DOI_ISSUE_AS_MANIFESTATION));
162 
163  // Test whether exporting updates changes correctly
164  // sets the notification type.
165  $pluginInstance = $this->instantiatePlugin('MedraExportPlugin');
166  $hookName = 'submissiondao::getAdditionalFieldNames';
167  HookRegistry::register($hookName, array($pluginInstance, 'getAdditionalFieldNames'));
168  $submissionDao = DAORegistry::getDAO('SubmissionDAO');
169  $testObject = $submissionDao->getById(1);
170  $testObject->setData('medra::' . DOI_EXPORT_REGDOI, '1749/t.v1i1.1');
171  $submissionDao->updateObject($testObject);
172 
173  // Remove the hook.
174  $hooks = HookRegistry::getHooks();
175  foreach($hooks[$hookName] as $index => $hook) {
176  if (is_a($hook[0], 'MedraExportPlugin')) {
177  unset($hooks[$hookName][$index]);
178  break;
179  }
180  }
181 
182  $objects = array(
183  'issue' => 1,
184  'article' => 1,
185  'galley' => array(1,2,3)
186  );
187  $xmlFiles = array(
188  'serial-article-as-work-2.xml',
189  'serial-article-as-manifestation-2.xml',
190  'serial-issue-as-manifestation.xml'
191  );
192  parent::testExportUnregisteredDois('MedraExportPlugin', $objects, $xmlFiles);
193  }
194 
195 
224  parent::testRegisterOrExportSpecificObjects('MedraExportPlugin', array('issue', 'article', 'galley'), self::TEST_ACCOUNT, true);
225  }
226 
227 
231  public function testRegisterUnregisteredDois() {
232  parent::testRegisterUnregisteredDois('MedraExportPlugin', array('Issue', 'Article', 'Galley'), self::TEST_ACCOUNT);
233  }
234 
235 
247  public function testWorkProductExplanation() {
248  $this->logIn();
249  foreach(array('index', 'articles', 'galleys', 'all') as $pageName) {
250  $this->open($this->pages[$pageName]);
251  $this->assertElementPresent('//a[@href="http://www.medra.org/en/metadata_td.htm"]');
252  }
253  }
254 
255 
268  parent::testObjectsWithoutDOICannotBeSelectedForExport(array('issues', 'articles', 'galleys', 'all'));
269  }
270 
271 
275  public function testPluginSettings() {
276  $tests = array(
277  array(
278  'fromCompany' => 'FromComp1',
279  'fromName' => 'FromName1',
280  'fromEmail' => 'from@email.us',
281  'registrantName' => 'Registrant1',
282  'publicationCountry' => 'US',
283  'exportIssuesAs' => O4DOI_ISSUE_AS_WORK
284  ),
285  array(
286  'fromCompany' => 'FromComp2',
287  'fromName' => 'FromName2',
288  'fromEmail' => 'from@email.de',
289  'registrantName' => 'Registrant2',
290  'publicationCountry' => 'DE',
291  'exportIssuesAs' => O4DOI_ISSUE_AS_MANIFESTATION
292  )
293  );
294  $inputTypes = array(
295  'fromCompany' => TEST_INPUTTYPE_TEXT,
296  'fromName' => TEST_INPUTTYPE_TEXT,
297  'fromEmail' => TEST_INPUTTYPE_EMAIL,
298  'registrantName' => TEST_INPUTTYPE_TEXT,
299  'publicationCountry' => TEST_INPUTTYPE_SELECT,
300  'exportIssuesAs' => TEST_INPUTTYPE_SELECT
301  );
302  parent::testPluginSettings($tests, $inputTypes);
303  }
304 
305 
315  public function testConfigurationError() {
316  $exportPages = array('issues', 'articles', 'galleys', 'all');
317  parent::testConfigurationError($exportPages);
318 
319  // Test that the plug-in cannot be used when required configuration parameters are missing.
320  $pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO'); /* @var $pluginSettingsDao PluginSettingsDAO */
321  $pluginSettingsDao->updateSetting(1, $this->pluginId . 'exportplugin', 'registrantName', '');
322  $this->assertConfigurationError($exportPages, 'The plug-in is not fully set up');
323  }
324 
325 
340  $this->removeRegisteredDois('MedraExportPlugin');
341  $examples = array(
342  array(O4DOI_ISSUE_AS_WORK, 'issues', '1', 'serial-issue-as-work.xml'),
343  array(O4DOI_ISSUE_AS_MANIFESTATION, 'issues', '1', 'serial-issue-as-manifestation.xml'),
344  array(O4DOI_ISSUE_AS_WORK, 'articles', '1', 'serial-article-as-work-1.xml'),
345  array(O4DOI_ISSUE_AS_MANIFESTATION, 'galleys', '1', 'serial-article-as-manifestation-1.xml'),
346  array(O4DOI_ISSUE_AS_MANIFESTATION, 'galleys', '1 2 3', 'serial-article-as-manifestation-2.xml')
347  );
348 
349  foreach($examples as $example) {
350  list($exportIssuesAs, $exportObjectType, $objectIds, $xmlFile) = $example;
351 
352  // Configure the issue export type.
353  $this->configurePlugin(array('exportIssuesAs' => $exportIssuesAs));
354 
355  parent::testExportAndRegisterObjectsViaCli('MedraExportPlugin', 'export', $exportObjectType, $objectIds, $xmlFile);
356  parent::testExportAndRegisterObjectsViaCli('MedraExportPlugin', 'register', $exportObjectType, $objectIds);
357  $this->removeRegisteredDois('MedraExportPlugin');
358  }
359  }
360 
361 
366  parent::testUnsupportedObjectTypeCliError('MedraExportPlugin');
367  }
368 
369 
374  parent::testNonExistentJournalPathCliError('MedraExportPlugin');
375  }
376 
377 
382  parent::testOutputFileNotWritableCliError('MedraExportPlugin');
383  }
384 
385 
390  parent::testNonExistentObjectIdCliError('MedraExportPlugin');
391  }
392 
393 
394  //
395  // Implement template methods from FunctionalDoiExportTest
396  //
400  protected function cleanXml($xml) {
401  // Fix URLs.
402  $xml = PKPString::regexp_replace('#http://[^\s]+/index.php/(test|index)#', 'http://example.com/index.php/test', $xml);
403 
404  // Fix sent date.
405  $xml = PKPString::regexp_replace('/<SentDate>[0-9]{12}<\/SentDate>/', '<SentDate>201111082218</SentDate>', $xml);
406 
407  // Fix version.
408  $xml = PKPString::regexp_replace('/(<MessageNote>[^<]*)([0-9]\.){4}(<\/MessageNote>)/', '\1x.x.x.x.\3', $xml);
409 
410  return parent::cleanXml($xml);
411  }
412 }
413 
FunctionalMedraExportTest\cleanXml
cleanXml($xml)
Definition: FunctionalMedraExportTestCase.php:400
FunctionalMedraExportTest
Test the mEDRA plug-in.
Definition: FunctionalMedraExportTestCase.php:26
PKPString\regexp_replace
static regexp_replace($pattern, $replacement, $subject, $limit=-1)
Definition: PKPString.inc.php:279
FunctionalMedraExportTest\testOutputFileNotWritableCliError
testOutputFileNotWritableCliError()
Definition: FunctionalMedraExportTestCase.php:381
FunctionalMedraExportTest\TEST_ACCOUNT
const TEST_ACCOUNT
Definition: FunctionalMedraExportTestCase.php:27
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
FunctionalMedraExportTest\testExportUnregisteredDois
testExportUnregisteredDois()
Definition: FunctionalMedraExportTestCase.php:159
FunctionalMedraExportTest\testObjectsWithoutDOICannotBeSelectedForExport
testObjectsWithoutDOICannotBeSelectedForExport()
Definition: FunctionalMedraExportTestCase.php:267
FunctionalMedraExportTest\testExportSerialArticleAsWork
testExportSerialArticleAsWork()
Definition: FunctionalMedraExportTestCase.php:127
FunctionalMedraExportTest\testPluginSettings
testPluginSettings()
Definition: FunctionalMedraExportTestCase.php:275
FunctionalMedraExportTest\testWorkProductExplanation
testWorkProductExplanation()
Definition: FunctionalMedraExportTestCase.php:247
FunctionalMedraExportTest\testRegisterOrExportSpecificObjects
testRegisterOrExportSpecificObjects()
Definition: FunctionalMedraExportTestCase.php:223
FunctionalMedraExportTest\testConfigurationError
testConfigurationError()
Definition: FunctionalMedraExportTestCase.php:315
FunctionalMedraExportTest\testExportSerialArticleAsManifestation
testExportSerialArticleAsManifestation()
Definition: FunctionalMedraExportTestCase.php:143
FunctionalMedraExportTest\testUnsupportedObjectTypeCliError
testUnsupportedObjectTypeCliError()
Definition: FunctionalMedraExportTestCase.php:365
Config\getVar
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
FunctionalMedraExportTest\testExportAndRegisterObjectsViaCli
testExportAndRegisterObjectsViaCli()
Definition: FunctionalMedraExportTestCase.php:339
HookRegistry\getHooks
static & getHooks($hookName=null)
Definition: HookRegistry.inc.php:28
FunctionalMedraExportTest\setUp
setUp()
Definition: FunctionalMedraExportTestCase.php:32
FunctionalMedraExportTest\testNonExistentObjectIdCliError
testNonExistentObjectIdCliError()
Definition: FunctionalMedraExportTestCase.php:389
FunctionalMedraExportTest\testRegisterUnregisteredDois
testRegisterUnregisteredDois()
Definition: FunctionalMedraExportTestCase.php:231
FunctionalMedraExportTest\testExportSerialIssueAsManifestation
testExportSerialIssueAsManifestation()
Definition: FunctionalMedraExportTestCase.php:112
HookRegistry\register
static register($hookName, $callback, $hookSequence=HOOK_SEQUENCE_NORMAL)
Definition: HookRegistry.inc.php:70
FunctionalMedraExportTest\testExportSerialIssueAsWork
testExportSerialIssueAsWork()
Definition: FunctionalMedraExportTestCase.php:80
FunctionalMedraExportTest\checkThatPublisherIsJournalName
checkThatPublisherIsJournalName($xml)
Definition: FunctionalMedraExportTestCase.php:91
FunctionalMedraExportTest\testNonExistentJournalPathCliError
testNonExistentJournalPathCliError()
Definition: FunctionalMedraExportTestCase.php:373