Open Journal Systems  3.3.0
MedraWebserviceTest.php
1 <?php
2 
17 import('lib.pkp.tests.PKPTestCase');
18 import('plugins.importexport.medra.classes.MedraWebservice');
19 
21  private $ws;
22 
23  protected function setUp() : void {
24  // Retrieve and check configuration.
25  $medraPassword = Config::getVar('debug', 'webtest_medra_pw');
26  if (empty($medraPassword)) {
27  $this->markTestSkipped(
28  'Please set webtest_medra_pw in your config.php\'s ' .
29  '[debug] section to the password of your Medra test account.'
30  );
31  }
32 
33  $this->ws = new MedraWebservice(MEDRA_WS_ENDPOINT_DEV, 'TEST_OJS', $medraPassword);
34  parent::setUp();
35  }
36 
40  public function testUpload() {
41  self::assertTrue($this->ws->upload($this->getTestData()));
42  }
43 
47  public function testUploadWithError() {
48  $metadata = str_replace('SerialVersion', 'UnknownElement', $this->getTestData());
49  $expectedError = "mEDRA: 200 - uploaded file is not valid cvc-complex-type.2.4.a: ".
50  "Invalid content was found starting with element 'UnknownElement'. " .
51  "One of '{\"http://www.editeur.org/onix/DOIMetadata/2.0\":SerialVersion}' is expected.";
52  self::assertEquals($expectedError, $this->ws->upload($metadata));
53  }
54 
58  public function testViewMetadata() {
59  $dom = new DOMDocument('1.0', 'utf-8');
60  $dom->loadXML($this->getTestData());
61  $elem = $dom->getElementsByTagName('DOISerialIssueWork')->item(0);
62  $attr = $dom->createAttribute('xmlns');
63  $attr->value = 'http://www.editeur.org/onix/DOIMetadata/2.0';
64  $elem->appendChild($attr);
65 
66  $result = str_replace(
67  '<NotificationType>07</NotificationType>',
68  '<NotificationType>06</NotificationType>',
69  $this->ws->viewMetadata('1749/t.v1i1')
70  );
71 
72  self::assertXmlStringEqualsXmlString($dom->saveXml($elem), $result);
73  }
74 
79  private function getTestData() {
80  $sampleFile = './tests/functional/plugins/importexport/medra/serial-issue-as-work.xml';
81  return file_get_contents($sampleFile);
82  }
83 }
84 
MedraWebserviceTest\setUp
setUp()
Definition: MedraWebserviceTest.php:23
MedraWebserviceTest\testUpload
testUpload()
Definition: MedraWebserviceTest.php:40
PKPTestCase
Class that implements functionality common to all PKP unit test cases.
Definition: PKPTestCase.inc.php:27
MedraWebserviceTest
Test class for MedraWebservice.
Definition: MedraWebserviceTest.php:20
MedraWebservice
A wrapper for the mEDRA web service 2.0.
Definition: MedraWebservice.inc.php:26
Config\getVar
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
MedraWebserviceTest\testUploadWithError
testUploadWithError()
Definition: MedraWebserviceTest.php:47
MedraWebserviceTest\testViewMetadata
testViewMetadata()
Definition: MedraWebserviceTest.php:58