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