/** * Return OAIRecord object from database row. * @param $row array * @return OAIRecord */ function &_returnRecordFromRow(&$row) { $oaiRecord = new OAIRecord(); $record =& $this->recordDao->_returnRecordFromRow($row); $archive =& $this->archiveDao->_returnArchiveFromRow($row); $oaiRecord->identifier = $this->oai->recordIdToIdentifier($record->getRecordId()); $oaiRecord->datestamp = OAIUtils::UTCDate(strtotime($this->datetimeFromDB($row['datestamp']))); $oaiRecord->sets = array($row['archive_id']); $oaiRecord->setData('archive', $archive); $oaiRecord->setData('record', $record); $oaiRecord->setData('schemaPluginName', $row['schema_plugin']); return $oaiRecord; }
/** * Return OAIRecord object from database row. * @param $row array * @return OAIRecord */ function &_returnRecordFromRow(&$row) { $record = new OAIRecord(); $paperId = $row['paper_id']; /* if ($this->conferenceSettingsDao->getSetting($row['conference_id'], 'enablePublicPaperId')) { if (!empty($row['public_paper_id'])) { $paperId = $row['public_paper_id']; } } */ $paper =& $this->publishedPaperDao->getPublishedPaperByPaperId($paperId); $conference =& $this->getConference($row['conference_id']); $schedConf =& $this->getSchedConf($row['sched_conf_id']); $track =& $this->getTrack($row['track_id']); $galleys =& $this->paperGalleyDao->getGalleysByPaper($paperId); $record->setData('paper', $paper); $record->setData('conference', $conference); $record->setData('schedConf', $schedConf); $record->setData('track', $track); $record->setData('galleys', $galleys); // FIXME Use public ID in OAI identifier? $record->identifier = $this->oai->paperIdToIdentifier($row['paper_id']); $record->datestamp = OAIUtils::UTCDate(strtotime($this->datetimeFromDB($row['last_modified']))); $record->sets = array($conference->getPath() . ':' . $track->getLocalizedAbbrev()); return $record; }
/** * @covers OAIMetadataFormat_DC * @covers Dc11SchemaArticleAdapter */ public function testToXml() { $this->markTestSkipped('Skipped because of weird class interaction with ControlledVocabDAO.'); // // Create test data. // $journalId = 1; // Enable the DOI plugin. $pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO'); /* @var $pluginSettingsDao PluginSettingsDAO */ $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enabled', 1); $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enableIssueDoi', 1); $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enableArticleDoi', 1); $pluginSettingsDao->updateSetting($journalId, 'doipubidplugin', 'enableGalleyDoi', 1); // Author import('classes.article.Author'); $author = new Author(); $author->setFirstName('author-firstname'); $author->setLastName('author-lastname'); $author->setAffiliation('author-affiliation', 'en_US'); $author->setEmail('*****@*****.**'); // Article import('classes.article.PublishedArticle'); $article = $this->getMock('PublishedArticle', array('getBestArticleId')); /* @var $article PublishedArticle */ $article->expects($this->any())->method('getBestArticleId')->will($this->returnValue(9)); $article->setId(9); $article->setJournalId($journalId); $author->setSubmissionId($article->getId()); $article->setPages(15); $article->setType('art-type', 'en_US'); $article->setTitle('article-title-en', 'en_US'); $article->setTitle('article-title-de', 'de_DE'); $article->setDiscipline('article-discipline', 'en_US'); $article->setSubject('article-subject', 'en_US'); $article->setAbstract('article-abstract', 'en_US'); $article->setSponsor('article-sponsor', 'en_US'); $article->setStoredPubId('doi', 'article-doi'); $article->setLanguage('en_US'); // Galleys import('classes.article.ArticleGalley'); $galley = new ArticleGalley(); $galley->setId(98); $galley->setStoredPubId('doi', 'galley-doi'); $galleys = array($galley); // Journal import('classes.journal.Journal'); $journal = $this->getMock('Journal', array('getSetting')); /* @var $journal Journal */ $journal->expects($this->any())->method('getSetting')->will($this->returnCallback(array($this, 'getJournalSetting'))); $journal->setPrimaryLocale('en_US'); $journal->setPath('journal-path'); $journal->setId($journalId); // Section import('classes.journal.Section'); $section = new Section(); $section->setIdentifyType('section-identify-type', 'en_US'); // Issue import('classes.issue.Issue'); $issue = $this->getMock('Issue', array('getIssueIdentification')); /* @var $issue Issue */ $issue->expects($this->any())->method('getIssueIdentification')->will($this->returnValue('issue-identification')); $issue->setId(96); $issue->setDatePublished('2010-11-05'); $issue->setStoredPubId('doi', 'issue-doi'); $issue->setJournalId($journalId); // // Create infrastructural support objects // // Router import('lib.pkp.classes.core.PKPRouter'); $router = $this->getMock('PKPRouter', array('url')); $application = PKPApplication::getApplication(); $router->setApplication($application); $router->expects($this->any())->method('url')->will($this->returnCallback(array($this, 'routerUrl'))); // Request import('classes.core.Request'); $request = $this->getMock('Request', array('getRouter')); $request->expects($this->any())->method('getRouter')->will($this->returnValue($router)); Registry::set('request', $request); // // Create mock DAOs // // Create a mocked AuthorDAO that returns our test author. import('classes.article.AuthorDAO'); $authorDao = $this->getMock('AuthorDAO', array('getBySubmissionId')); $authorDao->expects($this->any())->method('getBySubmissionId')->will($this->returnValue(array($author))); DAORegistry::registerDAO('AuthorDAO', $authorDao); // Create a mocked OAIDAO that returns our test data. import('classes.oai.ojs.OAIDAO'); $oaiDao = $this->getMock('OAIDAO', array('getJournal', 'getSection', 'getIssue')); $oaiDao->expects($this->any())->method('getJournal')->will($this->returnValue($journal)); $oaiDao->expects($this->any())->method('getSection')->will($this->returnValue($section)); $oaiDao->expects($this->any())->method('getIssue')->will($this->returnValue($issue)); DAORegistry::registerDAO('OAIDAO', $oaiDao); // Create a mocked ArticleGalleyDAO that returns our test data. import('classes.article.ArticleGalleyDAO'); $articleGalleyDao = $this->getMock('ArticleGalleyDAO', array('getBySubmissionId')); $articleGalleyDao->expects($this->any())->method('getBySubmissionId')->will($this->returnValue($galleys)); DAORegistry::registerDAO('ArticleGalleyDAO', $articleGalleyDao); // FIXME: ArticleGalleyDAO::getBySubmissionId returns iterator; array expected here. Fix expectations. // Create a mocked PublishedArticleDAO that returns our test article. import('classes.article.PublishedArticleDAO'); $articleDao = $this->getMock('PublishedArticleDAO', array('getPublishedArticleByArticleId')); $articleDao->expects($this->any())->method('getPublishedArticleByArticleId')->will($this->returnValue($article)); DAORegistry::registerDAO('PublishedArticleDAO', $articleDao); // // Test // // OAI record $record = new OAIRecord(); $record->setData('article', $article); $record->setData('galleys', $galleys); $record->setData('journal', $journal); $record->setData('section', $section); $record->setData('issue', $issue); // Instantiate the OAI meta-data format. $prefix = OAIMetadataFormatPlugin_DC::getMetadataPrefix(); $schema = OAIMetadataFormatPlugin_DC::getSchema(); $namespace = OAIMetadataFormatPlugin_DC::getNamespace(); $mdFormat = new OAIMetadataFormat_DC($prefix, $schema, $namespace); $xml = $mdFormat->toXml($record); self::assertXmlStringEqualsXmlFile('tests/plugins/oaiMetadataFormats/dc/expectedResult.xml', $xml); }
/** * Return OAIRecord object from database row. * @param $row array * @return OAIRecord */ function &_returnRecordFromRow(&$row) { $record = new OAIRecord(); $articleId = $row['article_id']; $publishedArticle =& $this->publishedArticleDao->getPublishedArticleByArticleId($articleId); $journal =& $this->getJournal($row['journal_id']); $section =& $this->getSection($row['section_id']); $issue =& $this->getIssue($row['issue_id']); $galleys =& $this->articleGalleyDao->getGalleysByArticle($articleId); $record->setData('article', $publishedArticle); $record->setData('journal', $journal); $record->setData('section', $section); $record->setData('issue', $issue); $record->setData('galleys', $galleys); $record->identifier = $this->oai->articleIdToIdentifier($row['article_id']); $record->datestamp = OAIUtils::UTCDate(strtotime($this->datetimeFromDB($row['last_modified']))); $record->sets = array($journal->getPath() . ':' . $section->getLocalizedAbbrev()); return $record; }
/** * @covers OAIMetadataFormat_DC * @covers Dc11SchemaArticleAdapter */ public function testToXml() { // // Create test data. // // Author import('classes.article.Author'); $author = new Author(); $author->setFirstName('author-firstname'); $author->setLastName('author-lastname'); $author->setAffiliation('author-affiliation', 'en_US'); // Supplementary file import('classes.article.SuppFile'); $suppFile = new SuppFile(); $suppFile->setFileId(999); // Article import('classes.article.PublishedArticle'); $article = $this->getMock('PublishedArticle', array('getBestArticleId')); /* @var $article PublishedArticle */ $article->expects($this->any())->method('getBestArticleId')->will($this->returnValue(9)); $article->setId(9); $article->addAuthor($author); $article->setSuppFiles(array($suppFile)); $article->setPages(15); $article->setType('art-type', 'en_US'); $article->setTitle('article-title-en', 'en_US'); $article->setTitle('article-title-de', 'de_DE'); $article->setDiscipline('article-discipline', 'en_US'); $article->setSubject('article-subject', 'en_US'); $article->setSubjectClass('article-subject-class', 'en_US'); $article->setAbstract('article-abstract', 'en_US'); $article->setSponsor('article-sponsor', 'en_US'); $article->setStoredDOI('article-doi'); $article->setLanguage('en_US'); $article->setCoverageGeo('article-coverage-geo', 'en_US'); $article->setCoverageChron('article-coverage-chron', 'en_US'); $article->setCoverageSample('article-coverage-sample', 'en_US'); // Galleys import('classes.article.ArticleGalley'); $galley = new ArticleGalley(); $galley->setFileType('galley-filetype'); $galleys = array($galley); // Journal import('classes.journal.Journal'); $journal = $this->getMock('Journal', array('getSetting')); /* @var $journal Journal */ $journal->expects($this->any())->method('getSetting')->will($this->returnCallback(array($this, 'getJournalSetting'))); $journal->setPrimaryLocale('en_US'); $journal->setPath('journal-path'); // Section import('classes.journal.Section'); $section = new Section(); $section->setIdentifyType('section-identify-type', 'en_US'); // Issue import('classes.issue.Issue'); $issue = $this->getMock('Issue', array('getIssueIdentification')); /* @var $issue Issue */ $issue->expects($this->any())->method('getIssueIdentification')->will($this->returnValue('issue-identification')); $issue->setDatePublished('2010-11-05'); // // Create infrastructural support objects // // Router import('lib.pkp.classes.core.PKPRouter'); $router = $this->getMock('PKPRouter', array('url')); $application = PKPApplication::getApplication(); $router->setApplication($application); $router->expects($this->any())->method('url')->will($this->returnValue('router-url')); // Request import('classes.core.Request'); $request = $this->getMock('Request', array('getRouter')); $request->expects($this->any())->method('getRouter')->will($this->returnValue($router)); Registry::set('request', $request); // // Create mock DAOs // // Create a mocked OAIDAO that returns our test data. import('classes.oai.ojs.OAIDAO'); $oaiDao = $this->getMock('OAIDAO', array('getJournal', 'getSection', 'getIssue')); $oaiDao->expects($this->any())->method('getJournal')->will($this->returnValue($journal)); $oaiDao->expects($this->any())->method('getSection')->will($this->returnValue($section)); $oaiDao->expects($this->any())->method('getIssue')->will($this->returnValue($issue)); DAORegistry::registerDAO('OAIDAO', $oaiDao); // Create a mocked ArticleGalleyDAO that returns our test data. import('classes.article.ArticleGalleyDAO'); $articleGalleyDao = $this->getMock('OAIDAO', array('getGalleysByArticle')); $articleGalleyDao->expects($this->any())->method('getGalleysByArticle')->will($this->returnValue($galleys)); DAORegistry::registerDAO('ArticleGalleyDAO', $articleGalleyDao); // // Test // // OAI record $record = new OAIRecord(); $record->setData('article', $article); $record->setData('galleys', $galleys); $record->setData('journal', $journal); $record->setData('section', $section); $record->setData('issue', $issue); // Instantiate the OAI meta-data format. $prefix = OAIMetadataFormatPlugin_DC::getMetadataPrefix(); $schema = OAIMetadataFormatPlugin_DC::getSchema(); $namespace = OAIMetadataFormatPlugin_DC::getNamespace(); $mdFormat = new OAIMetadataFormat_DC($prefix, $schema, $namespace); $xml = $mdFormat->toXml($record); self::assertXmlStringEqualsXmlFile('tests/plugins/oaiMetadataFormats/dc/expectedResult.xml', $xml); }