Open Preprint Systems  3.3.0
OAIMetadataFormat_DCTest.php
1 <?php
2 
21 require_mock_env('env2');
22 
23 import('lib.pkp.tests.PKPTestCase');
24 
25 import('lib.pkp.classes.oai.OAIStruct');
26 import('lib.pkp.classes.oai.OAIUtils');
27 import('plugins.oaiMetadataFormats.dc.OAIMetadataFormat_DC');
28 import('plugins.oaiMetadataFormats.dc.OAIMetadataFormatPlugin_DC');
29 
31 
35  protected function getMockedDAOs() {
36  return array('AuthorDAO', 'OAIDAO', 'ArticleGalleyDAO');
37  }
38 
42  protected function getMockedRegistryKeys() {
43  return array('request');
44  }
45 
50  public function testToXml() {
51  $this->markTestSkipped('Skipped because of weird class interaction with ControlledVocabDAO.');
52 
53  //
54  // Create test data.
55  //
56  $journalId = 1;
57 
58  // Enable the DOI plugin.
59  $pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO'); /* @var $pluginSettingsDao PluginSettingsDAO */
60  $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enabled', 1);
61  $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enableIssueDoi', 1);
62  $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enablePublicationDoi', 1);
63  $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enableRepresentationyDoi', 1);
64 
65  // Author
66  import('classes.article.Author');
67  $author = new Author();
68  $author->setGivenName('author-firstname', 'en_US');
69  $author->setFamilyName('author-lastname', 'en_US');
70  $author->setAffiliation('author-affiliation', 'en_US');
71  $author->setEmail('someone@example.com');
72 
73  // Article
74  import('classes.submission.Submission');
75  $article = $this->getMockBuilder(Submission::class)
76  ->setMethods(array('getBestId'))
77  ->getMock();
78  $article->expects($this->any())
79  ->method('getBestId')
80  ->will($this->returnValue(9));
81  $article->setId(9);
82  $article->setJournalId($journalId);
83  $author->setSubmissionId($article->getId());
84  $article->setPages(15);
85  $article->setType('art-type', 'en_US');
86  $article->setTitle('article-title-en', 'en_US');
87  $article->setTitle('article-title-de', 'de_DE');
88  $article->setDiscipline('article-discipline', 'en_US');
89  $article->setSubject('article-subject', 'en_US');
90  $article->setAbstract('article-abstract', 'en_US');
91  $article->setSponsor('article-sponsor', 'en_US');
92  $article->setStoredPubId('doi', 'article-doi');
93  $article->setLanguage('en_US');
94 
95  // Galleys
96  import('classes.article.ArticleGalley');
97  $galley = new ArticleGalley();
98  $galley->setId(98);
99  $galley->setStoredPubId('doi', 'galley-doi');
100  $galleys = array($galley);
101 
102  // Journal
103  import('classes.journal.Journal');
104  $journal = $this->getMockBuilder(Journal::class)
105  ->setMethods(array('getSetting'))
106  ->getMock();
107  $journal->expects($this->any())
108  ->method('getSetting') // includes getTitle()
109  ->will($this->returnCallback(array($this, 'getJournalSetting')));
110  $journal->setPrimaryLocale('en_US');
111  $journal->setPath('journal-path');
112  $journal->setId($journalId);
113 
114  // Section
115  import('classes.journal.Section');
116  $section = new Section();
117  $section->setIdentifyType('section-identify-type', 'en_US');
118 
119  // Issue
120  import('classes.issue.Issue');
121  $issue = $this->getMockBuilder(Issue::class)
122  ->setMethods(array('getIssueIdentification'))
123  ->getMock();
124  $issue->expects($this->any())
125  ->method('getIssueIdentification')
126  ->will($this->returnValue('issue-identification'));
127  $issue->setId(96);
128  $issue->setDatePublished('2010-11-05');
129  $issue->setStoredPubId('doi', 'issue-doi');
130  $issue->setJournalId($journalId);
131 
132 
133  //
134  // Create infrastructural support objects
135  //
136 
137  // Router
138  import('lib.pkp.classes.core.PKPRouter');
139  $router = $this->getMockBuilder(PKPRouter::class)
140  ->setMethods(array('url'))
141  ->getMock();
142  $application = Application::get();
143  $router->setApplication($application);
144  $router->expects($this->any())
145  ->method('url')
146  ->will($this->returnCallback(array($this, 'routerUrl')));
147 
148  // Request
149  import('classes.core.Request');
150  $request = $this->getMockBuilder(Request::class)
151  ->setMethods(array('getRouter'))
152  ->getMock();
153  $request->expects($this->any())
154  ->method('getRouter')
155  ->will($this->returnValue($router));
156  Registry::set('request', $request);
157 
158 
159  //
160  // Create mock DAOs
161  //
162 
163  // Create a mocked AuthorDAO that returns our test author.
164  import('classes.article.AuthorDAO');
165  $authorDao = $this->getMockBuilder(AuthorDAO::class)
166  ->setMethods(array('getBySubmissionId'))
167  ->getMock();
168  $authorDao->expects($this->any())
169  ->method('getBySubmissionId')
170  ->will($this->returnValue(array($author)));
171  DAORegistry::registerDAO('AuthorDAO', $authorDao);
172 
173  // Create a mocked OAIDAO that returns our test data.
174  import('classes.oai.ojs.OAIDAO');
175  $oaiDao = $this->getMockBuilder(OAIDAO::class)
176  ->setMethods(array('getJournal', 'getSection', 'getIssue'))
177  ->getMock();
178  $oaiDao->expects($this->any())
179  ->method('getJournal')
180  ->will($this->returnValue($journal));
181  $oaiDao->expects($this->any())
182  ->method('getSection')
183  ->will($this->returnValue($section));
184  $oaiDao->expects($this->any())
185  ->method('getIssue')
186  ->will($this->returnValue($issue));
187  DAORegistry::registerDAO('OAIDAO', $oaiDao);
188 
189  // Create a mocked ArticleGalleyDAO that returns our test data.
190  import('classes.article.ArticleGalleyDAO');
191  $articleGalleyDao = $this->getMockBuilder(ArticleGalleyDAO::class)
192  ->setMethods(array('getBySubmissionId'))
193  ->getMock();
194  $articleGalleyDao->expects($this->any())
195  ->method('getBySubmissionId')
196  ->will($this->returnValue($galleys));
197  DAORegistry::registerDAO('ArticleGalleyDAO', $articleGalleyDao);
198  // FIXME: ArticleGalleyDAO::getBySubmissionId returns iterator; array expected here. Fix expectations.
199 
200  //
201  // Test
202  //
203 
204  // OAI record
205  $record = new OAIRecord();
206  $record->setData('article', $article);
207  $record->setData('galleys', $galleys);
208  $record->setData('journal', $journal);
209  $record->setData('section', $section);
210  $record->setData('issue', $issue);
211 
212  // Instantiate the OAI meta-data format.
216  $mdFormat = new OAIMetadataFormat_DC($prefix, $schema, $namespace);
217 
218  $xml = $mdFormat->toXml($record);
219  self::assertXmlStringEqualsXmlFile('tests/plugins/oaiMetadataFormats/dc/expectedResult.xml', $xml);
220  }
221 
222 
223  //
224  // Public helper methods
225  //
230  function getJournalSetting($settingName) {
231  switch ($settingName) {
232  case 'name':
233  return array('en_US' => 'journal-title');
234 
235  case 'licenseTerms':
236  return array('en_US' => 'journal-copyright');
237 
238  case 'publisherInstitution':
239  return array('journal-publisher');
240 
241  case 'onlineIssn':
242  return 'onlineIssn';
243 
244  case 'printIssn':
245  return null;
246 
247  default:
248  self::fail('Required journal setting is not necessary for the purpose of this test.');
249  }
250  }
251 
252 
253  //
254  // Private helper methods
255  //
259  function routerUrl($request, $newContext = null, $handler = null, $op = null, $path = null) {
260  return $handler.'-'.$op.'-'.implode('-', $path);
261  }
262 }
OAIMetadataFormat_DCTest
Test class for OAIMetadataFormat_DC.
Definition: OAIMetadataFormat_DCTest.php:30
$op
$op
Definition: lib/pkp/pages/help/index.php:18
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
OAIRecord
Definition: OAIStruct.inc.php:301
OAIMetadataFormat_DCTest\getMockedDAOs
getMockedDAOs()
Definition: OAIMetadataFormat_DCTest.php:35
ArticleGalley
A galley is a final presentation version of the full-text of an article.
Definition: ArticleGalley.inc.php:19
PKPTestCase
Class that implements functionality common to all PKP unit test cases.
Definition: PKPTestCase.inc.php:27
OAIMetadataFormat_DCTest\testToXml
testToXml()
Definition: OAIMetadataFormat_DCTest.php:50
Author
Article author metadata class.
Definition: Author.inc.php:20
Registry\set
static set($key, &$value)
Definition: Registry.inc.php:53
PKPOAIMetadataFormatPlugin_DC\getMetadataPrefix
static getMetadataPrefix()
Definition: PKPOAIMetadataFormatPlugin_DC.inc.php:40
DAORegistry\registerDAO
static registerDAO($name, $dao)
Definition: DAORegistry.inc.php:40
OAIMetadataFormat_DCTest\getMockedRegistryKeys
getMockedRegistryKeys()
Definition: OAIMetadataFormat_DCTest.php:42
PKPOAIMetadataFormatPlugin_DC\getNamespace
static getNamespace()
Definition: PKPOAIMetadataFormatPlugin_DC.inc.php:48
PKPOAIMetadataFormatPlugin_DC\getSchema
static getSchema()
Definition: PKPOAIMetadataFormatPlugin_DC.inc.php:44
OAIMetadataFormat_DC
OAI metadata format class – Dublin Core.
Definition: OAIMetadataFormat_DC.inc.php:21
OAIMetadataFormat_DCTest\routerUrl
routerUrl($request, $newContext=null, $handler=null, $op=null, $path=null)
Definition: OAIMetadataFormat_DCTest.php:259
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
Section
Describes basic section properties.
Definition: Section.inc.php:19
OAIMetadataFormat_DCTest\getJournalSetting
getJournalSetting($settingName)
Definition: OAIMetadataFormat_DCTest.php:230