/**
  * @covers PersistableFilter
  */
 public function testInstantiationAndExecute()
 {
     $constructorArg = PersistableFilter::tempGroup('class::lib.pkp.tests.classes.filter.TestClass1', 'class::lib.pkp.tests.classes.filter.TestClass2');
     $testFilter = new PersistableFilter($constructorArg);
     // Test getters/setters that are not implicitly tested by other tests
     self::assertInstanceOf('FilterGroup', $testFilter->getFilterGroup());
     $testFilter->setDisplayName('Some other display name');
     $testFilter->setIsTemplate(1);
     self::assertTrue($testFilter->getIsTemplate());
     self::assertEquals(0, $testFilter->getParentFilterId());
     $testFilter->setParentFilterId(1);
     self::assertEquals(1, $testFilter->getParentFilterId());
     // Test settings
     self::assertFalse($testFilter->hasSettings());
     $testSetting = new EmailFilterSetting('testEmail', 'Test Email', 'Test Email is required');
     $testSetting2 = new EmailFilterSetting('testEmail2', 'Test Email2', 'Test Email2 is required');
     $testSetting2->setIsLocalized(true);
     $testFilter->addSetting($testSetting);
     $testFilter->addSetting($testSetting2);
     self::assertEquals(array('testEmail' => $testSetting, 'testEmail2' => $testSetting2), $testFilter->getSettings());
     self::assertTrue($testFilter->hasSettings());
     self::assertEquals(array('testEmail'), $testFilter->getSettingNames());
     self::assertEquals(array('testEmail2'), $testFilter->getLocalizedSettingNames());
     self::assertTrue($testFilter->hasSetting('testEmail'));
     self::assertEquals($testSetting, $testFilter->getSetting('testEmail'));
     // Test type validation.
     $typeDescriptionFactory = TypeDescriptionFactory::getInstance();
     $inputTypeDescription = 'class::lib.pkp.tests.classes.filter.TestClass1';
     $outputTypeDescription = 'class::lib.pkp.tests.classes.filter.TestClass2';
     self::assertEquals($inputTypeDescription, $testFilter->getInputType()->getTypeDescription());
     self::assertEquals($outputTypeDescription, $testFilter->getOutputType()->getTypeDescription());
 }
 /**
  * @covers Mods34SchemaSubmissionAdapter
  */
 public function testMods34SchemaSubmissionAdapter()
 {
     // Test constructor.
     $adapter = new Mods34SchemaSubmissionAdapter(PersistableFilter::tempGroup('metadata::plugins.metadata.mods34.schema.Mods34Schema(CITATION)', 'class::lib.pkp.classes.submission.Submission'));
     self::assertEquals(ASSOC_TYPE_CITATION, $adapter->getAssocType());
     self::assertType('Mods34Schema', $adapter->getMetadataSchema());
     self::assertEquals('Submission', $adapter->getDataObjectClass());
     // Instantiate a test description.
     $submissionDescription =& $this->getMods34Description();
     // Instantiate test submission.
     $submission = new Submission();
     $submission->setTitle('previous submission title', 'en_US');
     $submission->setAbstract('previous abstract', 'en_US');
     // Remove the abstract to test whether the injection into existing data works.
     // (The abstract should not be deleted.)
     $submissionDescription->removeStatement('abstract');
     // Test metadata injection (no replace).
     $resultSubmission =& $adapter->injectMetadataIntoDataObject($submissionDescription, $submission, 'lib.pkp.tests.plugins.metadata.mods34.filter.Author');
     $expectedResult = array('cleanTitle' => array('en_US' => 'new submission title', 'de_DE' => 'neuer Titel'), 'title' => array('en_US' => 'new submission title', 'de_DE' => 'neuer Titel'), 'abstract' => array('en_US' => 'previous abstract'), 'sponsor' => array('en_US' => 'Some Sponsor'), 'dateSubmitted' => '2010-07-07', 'language' => 'en', 'pages' => 215, 'coverageGeo' => array('en_US' => 'some geography'), 'mods34:titleInfo/nonSort' => array('en_US' => 'the', 'de_DE' => 'ein'), 'mods34:titleInfo/subTitle' => array('en_US' => 'subtitle', 'de_DE' => 'Subtitel'), 'mods34:titleInfo/partNumber' => array('en_US' => 'part I', 'de_DE' => 'Teil I'), 'mods34:titleInfo/partName' => array('en_US' => 'introduction', 'de_DE' => 'Einführung'), 'mods34:note' => array('en_US' => array('0' => 'some note', '1' => 'another note'), 'de_DE' => array('0' => 'übersetzte Anmerkung')), 'mods34:subject/temporal[@encoding="w3cdtf" @point="start"]' => '1950', 'mods34:subject/temporal[@encoding="w3cdtf" @point="end"]' => '1954');
     self::assertEquals($expectedResult, $resultSubmission->getAllData());
     // Test meta-data extraction.
     $adapter = new Mods34SchemaSubmissionAdapter(PersistableFilter::tempGroup('class::lib.pkp.classes.submission.Submission', 'metadata::plugins.metadata.mods34.schema.Mods34Schema(CITATION)'));
     $extractedDescription =& $adapter->extractMetadataFromDataObject($submission);
     $submissionDescription->removeStatement('recordInfo/recordCreationDate[@encoding="w3cdtf"]');
     self::assertTrue($submissionDescription->addStatement('recordInfo/recordCreationDate[@encoding="w3cdtf"]', date('Y-m-d')));
     self::assertTrue($submissionDescription->addStatement('abstract', $abstract = 'previous abstract'));
     $missingMappings = array('genre[@authority="marcgt"]', 'originInfo/place/placeTerm[@type="text"]', 'originInfo/place/placeTerm[@type="code" @authority="iso3166"]', 'originInfo/publisher', 'originInfo/dateIssued[@keyDate="yes" @encoding="w3cdtf"]', 'originInfo/edition', 'physicalDescription/form[@authority="marcform"]', 'physicalDescription/internetMediaType', 'identifier[@type="isbn"]', 'identifier[@type="doi"]', 'identifier[@type="uri"]', 'location/url[@usage="primary display"]', 'recordInfo/recordIdentifier[@source="pkp"]', 'subject/topic');
     foreach ($missingMappings as $missingMapping) {
         $submissionDescription->removeStatement($missingMapping);
     }
     self::assertEquals($submissionDescription, $extractedDescription);
 }
 /**
  * @covers Nlm30CitationSchemaCitationAdapter
  */
 public function testNlm30CitationSchemaCitationAdapter()
 {
     // Test constructor.
     $adapter = new Nlm30CitationSchemaCitationAdapter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'class::lib.pkp.classes.citation.Citation'));
     self::assertEquals(ASSOC_TYPE_CITATION, $adapter->getAssocType());
     self::assertType('Nlm30CitationSchema', $adapter->getMetadataSchema());
     self::assertEquals('Citation', $adapter->getDataObjectClass());
     // Instantiate a test description.
     $authorDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema', ASSOC_TYPE_AUTHOR);
     $authorDescription->addStatement('surname', $surname = 'some surname');
     $citationDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema', ASSOC_TYPE_CITATION);
     $citationDescription->addStatement('article-title', $articleTitle = 'article title');
     $citationDescription->addStatement('person-group[@person-group-type="author"]', $authorDescription);
     // Instantiate test citation.
     $citation = new Citation();
     // Test metadata injection.
     $resultCitation =& $adapter->injectMetadataIntoDataObject($citationDescription, $citation);
     $expectedResult = array('rawCitation' => '', 'nlm30:person-group[@person-group-type="author"]' => array(array('surname' => 'some surname')), 'nlm30:article-title' => array('en_US' => 'article title'));
     self::assertEquals($expectedResult, $resultCitation->getAllData());
     // Instantiate and inject a second test description.
     $authorDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema', ASSOC_TYPE_AUTHOR);
     $authorDescription->addStatement('surname', $anotherSurname = 'another surname');
     $secondDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema', ASSOC_TYPE_CITATION);
     $secondDescription->addStatement('person-group[@person-group-type="author"]', $authorDescription);
     $secondDescription->addStatement('source', $source = 'some source');
     $resultCitation =& $adapter->injectMetadataIntoDataObject($secondDescription, $citation);
     $expectedResult = array('rawCitation' => '', 'nlm30:person-group[@person-group-type="author"]' => array(array('surname' => 'another surname')), 'nlm30:article-title' => array('en_US' => 'article title'), 'nlm30:source' => array('en_US' => 'some source'));
     self::assertEquals($expectedResult, $resultCitation->getAllData());
     // Test meta-data extraction.
     $adapter = new Nlm30CitationSchemaCitationAdapter(PersistableFilter::tempGroup('class::lib.pkp.classes.citation.Citation', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
     $extractedDescription =& $adapter->extractMetadataFromDataObject($resultCitation);
     $secondDescription->addStatement('article-title', $articleTitle = 'article title');
     self::assertEquals($secondDescription, $extractedDescription);
 }
 /**
  * @covers PKPSubmissionNlm30XmlFilter
  */
 public function testExecute()
 {
     // Instantiate test meta-data for a citation.
     import('lib.pkp.classes.metadata.MetadataDescription');
     $nameSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema';
     $nameDescription = new MetadataDescription($nameSchemaName, ASSOC_TYPE_AUTHOR);
     $nameDescription->addStatement('given-names', $value = 'Peter');
     $nameDescription->addStatement('given-names', $value = 'B');
     $nameDescription->addStatement('surname', $value = 'Bork');
     $nameDescription->addStatement('prefix', $value = 'Mr.');
     $citationSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema';
     $citationDescription = new MetadataDescription($citationSchemaName, ASSOC_TYPE_CITATION);
     $citationDescription->addStatement('person-group[@person-group-type="author"]', $nameDescription);
     $citationDescription->addStatement('article-title', $value = 'PHPUnit in a nutshell', 'en_US');
     $citationDescription->addStatement('date', $value = '2009-08-17');
     $citationDescription->addStatement('size', $value = 320);
     $citationDescription->addStatement('uri', $value = 'http://phpunit.org/nutshell');
     $citationDescription->addStatement('[@publication-type]', $value = 'book');
     $citation =& $this->getCitation($citationDescription);
     // Persist a few copies of the citation for testing.
     $citationDao =& $this->getCitationDao();
     for ($seq = 1; $seq <= 10; $seq++) {
         $citation->setSeq($seq);
         $citation->setCitationState(CITATION_APPROVED);
         $citationId = $citationDao->insertObject($citation);
         self::assertTrue(is_numeric($citationId));
         self::assertTrue($citationId > 0);
     }
     // Execute the filter and check the outcome.
     $mockSubmission =& $this->getTestSubmission();
     // FIXME: Add NLM 3.0 tag set schema validation as soon as we implement the full tag set, see #5648.
     $filter = new PKPSubmissionNlm30XmlFilter(PersistableFilter::tempGroup('class::lib.pkp.classes.submission.Submission', 'xml::*'));
     $nlm30Xml = $filter->execute($mockSubmission);
     self::assertXmlStringEqualsXmlFile('./lib/pkp/tests/plugins/metadata/nlm30/filter/sample-nlm30-citation.xml', $nlm30Xml);
 }
 /**
  * Test Pubmed lookup without PmID
  * @covers PubmedNlm30CitationSchemaFilter
  */
 public function testExecuteWithSearch()
 {
     // Build the test citations array
     $citationFilterTests = array(array('testInput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Scott', 'D'), 'surname' => 'Halpern'), array('given-names' => array('Peter', 'A'), 'surname' => 'Ubel'), array('given-names' => array('Arthur', 'L'), 'surname' => 'Caplan')), 'article-title' => 'Solid-organ transplantation in HIV-infected patients.', 'source' => 'N Engl J Med', 'volume' => '347', 'issue' => '4'), 'testOutput' => $this->getTestOutput()), array('testInput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Scott', 'D'), 'surname' => 'Halpern'), array('given-names' => array('Peter', 'A'), 'surname' => 'Ubel'), array('given-names' => array('Arthur', 'L'), 'surname' => 'Caplan'))), 'testOutput' => $this->getTestOutput()));
     // Execute the test
     $filter = new PubmedNlm30CitationSchemaFilter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
     $this->assertNlm30CitationSchemaFilter($citationFilterTests, $filter);
 }
 /**
  * Constructor
  *
  * @param $metadataDescription MetadataDescription
  */
 function MetadataDescriptionDummyAdapter(&$metadataDescription, $mode = null)
 {
     $this->setDisplayName('Inject/Extract Metadata into/from a MetadataDescription');
     // Configure the adapter
     $inputType = $outputType = 'metadata::' . $metadataDescription->getMetadataSchemaName() . '(*)';
     parent::MetadataDataObjectAdapter(PersistableFilter::tempGroup($inputType, $outputType), $mode);
     $this->_assocType = $metadataDescription->getAssocType();
 }
 /**
  * Retrieve the citation output filter that will be
  * used to transform citations.
  * @return TemplateBasedFilter
  */
 function getCitationOutputFilterInstance()
 {
     $citationOutputFilterName = $this->getData('citationOutputFilterName');
     assert(!is_null($citationOutputFilterName));
     list($inputTypeDescription, $outputTypeDescription) = $this->getCitationOutputFilterTypeDescriptions();
     $filterGroup = PersistableFilter::tempGroup($inputTypeDescription, $outputTypeDescription);
     return instantiate($citationOutputFilterName, 'TemplateBasedFilter', null, null, $filterGroup);
 }
 /**
  * Test CrossRef lookup without DOI
  * @covers CrossrefNlm30CitationSchemaFilter
  */
 public function testExecuteWithOpenurl10Search()
 {
     // Build the test citations array
     $citationFilterTests = array(array('testInput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Hao'), 'surname' => 'Chen')), 'source' => 'BMC Bioinformatics', 'issue' => '1', 'volume' => '5', 'fpage' => 147, '[@publication-type]' => 'journal'), 'testOutput' => array('source' => 'BMC Bioinformatics', 'issue' => '1', 'volume' => '5', 'date' => '2004', 'fpage' => 147, 'uri' => 'http://www.biomedcentral.com/1471-2105/5/147', 'issn[@pub-type="ppub"]' => '14712105', 'person-group[@person-group-type="author"]' => array(array('given-names' => array('Hao'), 'surname' => 'Chen'), array('given-names' => array('Burt', 'M'), 'surname' => 'Sharp')), 'pub-id[@pub-id-type="doi"]' => '10.1186/1471-2105-5-147', '[@publication-type]' => 'journal')));
     // Execute the test
     $filter = new CrossrefNlm30CitationSchemaFilter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
     $filter->setEmail(self::ACCESS_EMAIL);
     $this->assertNlm30CitationSchemaFilter($citationFilterTests, $filter);
 }
 /**
  * @covers ParaciteRawCitationNlm30CitationSchemaFilter
  */
 public function testAllCitationsWithThisParser()
 {
     foreach (ParaciteRawCitationNlm30CitationSchemaFilter::getSupportedCitationModules() as $citationModule) {
         $filter = new ParaciteRawCitationNlm30CitationSchemaFilter(PersistableFilter::tempGroup('primitive::string', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
         $filter->setData('citationModule', $citationModule);
         parent::_testAllCitationsWithThisParser($filter);
         unset($filter);
     }
 }
 /**
  * @copydoc OAIMetadataFormat::toXML
  */
 function toXml(&$record, $format = null)
 {
     $publicationFormat =& $record->getData('publicationFormat');
     $description = $publicationFormat->extractMetadata(new Xmdp22Schema());
     $xmlFilter = new Xmdp22DescriptionXmlFilter(PersistableFilter::tempGroup('metadata::plugins.metadata.xmdp22.schema.Xmdp22Schema(*)', 'xml::schema(plugins/metadata/xmdp22/filter/xmdp22.xsd)'));
     //FIXME: Hack to remove the duplicate XML document declarations
     $response = substr($xmlFilter->process($description), 39);
     return $response;
 }
 /**
  * @covers Mods34DescriptionXmlFilter
  */
 public function testMods34DescriptionXmlFilter()
 {
     // Get the test description.
     $submissionDescription = $this->getMods34Description();
     // Instantiate filter.
     $filter = new Mods34DescriptionXmlFilter(PersistableFilter::tempGroup('metadata::plugins.metadata.mods34.schema.Mods34Schema(*)', 'xml::schema(lib/pkp/plugins/metadata/mods34/filter/mods34.xsd)'));
     // Transform MODS description to XML.
     $output = $filter->execute($submissionDescription);
     self::assertXmlStringEqualsXmlFile('./lib/pkp/tests/plugins/metadata/mods34/filter/test.xml', $output);
 }
 /**
  * @covers IsbndbIsbnNlm30CitationSchemaFilter
  * @covers IsbndbNlm30CitationSchemaFilter
  */
 public function testExecute()
 {
     // Test data
     $isbnLookupTest = array('testInput' => '9780820452425', 'testOutput' => array('source' => array('en_US' => 'After literacy: essays'), 'date' => '2001', 'person-group[@person-group-type="author"]' => array(0 => array('given-names' => array('John'), 'surname' => 'Willinsky')), 'publisher-loc' => 'New York', 'publisher-name' => 'P. Lang', 'isbn' => '9780820452425', '[@publication-type]' => 'book'));
     // Build the test array
     $citationFilterTests = array($isbnLookupTest);
     // Test the filter
     $filter = new IsbndbIsbnNlm30CitationSchemaFilter(PersistableFilter::tempGroup('primitive::string', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
     $filter->setData('apiKey', self::ISBNDB_TEST_APIKEY);
     $this->assertNlm30CitationSchemaFilter($citationFilterTests, $filter);
 }
 /**
  * @covers IsbndbNlm30CitationSchemaIsbnFilter
  * @covers IsbndbNlm30CitationSchemaFilter
  */
 public function testExecute()
 {
     // Test data
     $isbnSearchTest = array('testInput' => array('person-group[@person-group-type="author"]' => array(0 => array('given-names' => array('John'), 'surname' => 'Willinsky')), 'source' => array('en_US' => 'After literacy')), 'testOutput' => '9780820452425');
     // Build the test array
     $citationFilterTests = array($isbnSearchTest);
     // Test the filter
     $filter = new IsbndbNlm30CitationSchemaIsbnFilter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'primitive::string'));
     $apiKey = $this->_getIsbndbApiKey();
     if (!$apiKey) {
         $this->markTestSkipped('ISBNDB API key not available.');
     }
     $filter->setData('apiKey', $apiKey);
     $this->assertNlm30CitationSchemaFilter($citationFilterTests, $filter);
 }
 /**
  * Test CrossRef lookup with DOI
  * @covers WorldcatNlm30CitationSchemaFilter
  */
 public function testExecuteWithDoi()
 {
     // Test book lookup
     $testWithApiKey = array('testInput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Paula'), 'surname' => 'Fernandes Lopes')), 'source' => 'A ética platônica: modelo de ética da boa vida'), 'testOutput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Paula', 'Fernandes'), 'surname' => 'Lopes')), 'source' => 'A ética platônica : modelo de ética da boa vida', 'isbn' => '851503154X', 'publisher-loc' => 'São Paulo', 'publisher-name' => 'Ed. Loyola', 'date' => '2005'));
     // Build the test citations array
     $citationFilterTests = array($testWithApiKey);
     // Execute the tests with API key
     $filter = new WorldcatNlm30CitationSchemaFilter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
     $filter->setData('apiKey', self::WORLDCAT_TEST_APIKEY);
     $this->assertNlm30CitationSchemaFilter($citationFilterTests, $filter);
     // Try again without API key
     $testWithoutApiKey = array('testInput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Paula'), 'surname' => 'Fernandes Lopes')), 'source' => 'A ética platônica: modelo de ética da boa vida'), 'testOutput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Paula', 'Fernandes'), 'surname' => 'Lopes')), 'source' => 'A ética platônica : modelo de ética da boa vida', 'isbn' => '9788515031542', 'date' => '2005', 'publisher-name' => 'Ed. Loyola', 'publisher-loc' => 'São Paulo'));
     $citationFilterTests = array($testWithoutApiKey);
     $filter = new WorldcatNlm30CitationSchemaFilter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
     $this->assertNlm30CitationSchemaFilter($citationFilterTests, $filter);
 }
 /**
  * Test CrossRef lookup with DOI
  * @covers WorldcatNlm30CitationSchemaFilter
  */
 public function testExecuteWithDoi()
 {
     // Test book lookup
     $testWithApiKey = array('testInput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Paula'), 'surname' => 'Fernandes Lopes')), 'source' => 'A ética platônica: modelo de ética da boa vida'), 'testOutput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Paula', 'Fernandes'), 'surname' => 'Lopes')), 'source' => 'A ética platônica : modelo de ética da boa vida', 'isbn' => '851503154X', 'publisher-loc' => 'São Paulo', 'publisher-name' => 'Ed. Loyola', 'date' => '2005', '[@publication-type]' => NLM30_PUBLICATION_TYPE_BOOK));
     // Build the test citations array
     $citationFilterTests = array($testWithApiKey);
     // Execute the tests with API key
     self::assertEquals(80, strlen(Config::getVar('debug', 'worldcat_apikey')), 'It seems that the WorldCat API key has not been configured.');
     $filter = new WorldcatNlm30CitationSchemaFilter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
     $filter->setData('apiKey', Config::getVar('debug', 'worldcat_apikey'));
     $this->assertNlm30CitationSchemaFilter($citationFilterTests, $filter);
     // Try again without API key
     $testWithoutApiKey = array('testInput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Paula'), 'surname' => 'Fernandes Lopes')), 'source' => 'A ética platônica: modelo de ética da boa vida'), 'testOutput' => array('person-group[@person-group-type="author"]' => array(array('given-names' => array('Paula', 'Fernandes'), 'surname' => 'Lopes')), 'source' => 'A ética platônica : modelo de ética da boa vida', 'isbn' => '9788515031542', 'date' => '2005', 'publisher-name' => 'Ed. Loyola', 'publisher-loc' => 'São Paulo', '[@publication-type]' => NLM30_PUBLICATION_TYPE_BOOK));
     $citationFilterTests = array($testWithoutApiKey);
     $filter = new WorldcatNlm30CitationSchemaFilter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
     $this->assertNlm30CitationSchemaFilter($citationFilterTests, $filter);
 }
Exemplo n.º 16
0
 /**
  * Call the callback to filter the citation. If errors occur
  * they'll be added to the citation form.
  * @param $request Request
  * @param $citation Citation
  * @param $filterCallback callable
  * @param $citationStateAfterFiltering integer the state the citation will
  *  be set to after the filter was executed.
  * @param $fromFilterIds only use filters with the given ids
  * @return Citation the filtered citation or null if an error occurred
  */
 function &_filterCitation($request, &$citation, &$filterCallback, $citationStateAfterFiltering, $fromFilterIds = array())
 {
     // Get the context.
     $router = $request->getRouter();
     $context = $router->getContext($request);
     assert(is_object($context));
     // Make sure that the citation implements only one
     // meta-data schema.
     $supportedMetadataSchemas = $citation->getSupportedMetadataSchemas();
     assert(count($supportedMetadataSchemas) == 1);
     $metadataSchema = $supportedMetadataSchemas[0];
     // Extract the meta-data description from the citation.
     $originalDescription = $citation->extractMetadata($metadataSchema);
     // Let the callback configure the transformation.
     $transformationDefinition = call_user_func_array($filterCallback, array(&$citation, &$originalDescription, $context->getId(), $fromFilterIds));
     $filterList =& $transformationDefinition['filterList'];
     if (empty($filterList)) {
         // We didn't find any applicable filter.
         $filteredCitation = $citationMultiplexer = $citationFilterNet = null;
     } else {
         // Get the input into the transformation.
         $muxInputData =& $transformationDefinition['inputData'];
         // Get the filter group.
         // NB: The filter group is identical for all filters
         // in the list. We can simply take the first filter's
         // group.
         $filterGroup =& $filterList[0]->getFilterGroup();
         /* @var $filterGroup FilterGroup */
         // The filter group must be adapted to return an array rather
         // than a scalar value.
         $filterGroup->setOutputType($filterGroup->getOutputType() . '[]');
         // Instantiate the citation multiplexer filter.
         import('lib.pkp.classes.filter.GenericMultiplexerFilter');
         $citationMultiplexer = new GenericMultiplexerFilter($filterGroup, $transformationDefinition['displayName']);
         // Don't fail just because one of the web services
         // fails. They are much too unstable to rely on them.
         $citationMultiplexer->setTolerateFailures(true);
         // Add sub-filters to the multiplexer.
         $nullVar = null;
         foreach ($filterList as $citationFilter) {
             if ($citationFilter->supports($muxInputData, $nullVar)) {
                 $citationMultiplexer->addFilter($citationFilter);
             }
         }
         // Instantiate the citation de-multiplexer filter.
         // FIXME: This must be configurable if we want to support other
         // meta-data schemas.
         import('lib.pkp.plugins.metadata.nlm30.filter.Nlm30CitationDemultiplexerFilter');
         $citationDemultiplexer = new Nlm30CitationDemultiplexerFilter();
         $citationDemultiplexer->setOriginalDescription($originalDescription);
         $citationDemultiplexer->setOriginalRawCitation($citation->getRawCitation());
         $citationDemultiplexer->setCitationOutputFilter($this->instantiateCitationOutputFilter($context));
         // Combine multiplexer and de-multiplexer to form the
         // final citation filter network.
         import('lib.pkp.classes.filter.GenericSequencerFilter');
         $citationFilterNet = new GenericSequencerFilter(PersistableFilter::tempGroup($filterGroup->getInputType(), 'class::lib.pkp.classes.citation.Citation'), 'Citation Filter Network');
         $citationFilterNet->addFilter($citationMultiplexer);
         $citationFilterNet->addFilter($citationDemultiplexer);
         // Send the input through the citation filter network.
         $filteredCitation =& $citationFilterNet->execute($muxInputData);
     }
     if (is_null($filteredCitation)) {
         // Return the original citation if the filters
         // did not produce any results and add an error message.
         $filteredCitation =& $citation;
         if (!empty($transformationDefinition['filterList'])) {
             $filteredCitation->addError(__('submission.citations.filter.noResultFromFilterError'));
         }
     } else {
         // Copy data from the original citation to the filtered citation.
         $filteredCitation->setId($citation->getId());
         $filteredCitation->setSequence($citation->getSequence());
         $filteredCitation->setRawCitation($citation->getRawCitation());
         $filteredCitation->setAssocId($citation->getAssocId());
         $filteredCitation->setAssocType($citation->getAssocType());
         foreach ($citation->getErrors() as $errorMessage) {
             $filteredCitation->addError($errorMessage);
         }
         foreach ($citation->getSourceDescriptions() as $sourceDescription) {
             $filteredCitation->addSourceDescription($sourceDescription);
         }
     }
     // Set the target citation state.
     $filteredCitation->setCitationState($citationStateAfterFiltering);
     if (is_a($citationMultiplexer, 'CompositeFilter')) {
         // Retrieve the results of intermediate filters and add
         // them to the citation for inspection by the end user.
         $lastOutput =& $citationMultiplexer->getLastOutput();
         if (is_array($lastOutput)) {
             foreach ($lastOutput as $sourceDescription) {
                 $filteredCitation->addSourceDescription($sourceDescription);
             }
         }
     }
     if (is_a($citationFilterNet, 'CompositeFilter')) {
         // Add filtering errors (if any) to the citation's error list.
         foreach ($citationFilterNet->getErrors() as $filterError) {
             $filteredCitation->addError($filterError);
         }
     }
     return $filteredCitation;
 }
 protected function getFilterInstance()
 {
     return new Nlm30CitationSchemaApaFilter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'primitive::string'));
 }
 /**
  * @see Nlm30CitationSchemaParserFilterTestCase::testAllCitationsWithThisParser()
  */
 public function testAllCitationsWithThisParser()
 {
     $filter = new RegexRawCitationNlm30CitationSchemaFilter(PersistableFilter::tempGroup('primitive::string', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
     parent::_testAllCitationsWithThisParser($filter);
 }
 protected function getFilterInstance()
 {
     // FIXME: Add NLM citation-element + name validation (requires partial NLM DTD, XSD or RelaxNG), see #5648.
     return new Nlm30CitationSchemaNlm30XmlFilter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'xml::*'));
 }
Exemplo n.º 20
0
 /**
  * @covers Nlm30Nlm23CrosswalkFilter
  */
 public function testExecute()
 {
     $this->markTestSkipped('Weird class interaction with ControlledVocabEntryDAO leads to failure');
     // Instantiate test meta-data for a citation. This must use the complete
     // available schema (although in practice this doesn't make sense) so that
     // we can make sure all tags are correctly converted.
     import('lib.pkp.classes.metadata.MetadataDescription');
     $nameSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema';
     $nameDescription = new MetadataDescription($nameSchemaName, ASSOC_TYPE_AUTHOR);
     $nameDescription->addStatement('given-names', $value = 'Peter');
     $nameDescription->addStatement('given-names', $value = 'B');
     $nameDescription->addStatement('surname', $value = 'Bork');
     $nameDescription->addStatement('prefix', $value = 'Mr.');
     $nameDescription->addStatement('suffix', $value = 'Jr');
     $citationSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema';
     $citationDescription = new MetadataDescription($citationSchemaName, ASSOC_TYPE_CITATION);
     $citationDescription->addStatement('person-group[@person-group-type="author"]', $nameDescription);
     $citationDescription->addStatement('person-group[@person-group-type="editor"]', $nameDescription);
     $citationDescription->addStatement('article-title', $value = 'PHPUnit in a nutshell', 'en_US');
     $citationDescription->addStatement('source', $value = 'PHPUnit in a nutshell', 'en_US');
     $citationDescription->addStatement('date', $value = '2009-08-17');
     $citationDescription->addStatement('date-in-citation[@content-type="access-date"]', $value = '2009-08');
     $citationDescription->addStatement('issue', $value = 5);
     $citationDescription->addStatement('volume', $value = 6);
     $citationDescription->addStatement('season', $value = 'Summer');
     $citationDescription->addStatement('chapter-title', $value = 'Introduction');
     $citationDescription->addStatement('edition', $value = '2nd edition');
     $citationDescription->addStatement('series', $value = 7);
     $citationDescription->addStatement('supplement', $value = 'Summer Special');
     $citationDescription->addStatement('conf-date', $value = '2009-08-17');
     $citationDescription->addStatement('conf-loc', $value = 'Helsinki');
     $citationDescription->addStatement('conf-name', $value = 'PHPUnit Hackfest');
     $citationDescription->addStatement('conf-sponsor', $value = 'Basti himself');
     $citationDescription->addStatement('institution', $value = 'PKP');
     $citationDescription->addStatement('fpage', $value = 9);
     $citationDescription->addStatement('lpage', $value = 312);
     $citationDescription->addStatement('size', $value = 320);
     $citationDescription->addStatement('publisher-loc', $value = 'Vancouver');
     $citationDescription->addStatement('publisher-name', $value = 'SFU');
     $citationDescription->addStatement('isbn', $value = '123456789');
     $citationDescription->addStatement('issn[@pub-type="ppub"]', $value = '987654321');
     $citationDescription->addStatement('issn[@pub-type="epub"]', $value = '111111111');
     $citationDescription->addStatement('pub-id[@pub-id-type="doi"]', $value = '10420/39406');
     $citationDescription->addStatement('pub-id[@pub-id-type="publisher-id"]', $value = 'xyz');
     $citationDescription->addStatement('pub-id[@pub-id-type="coden"]', $value = 'abc');
     $citationDescription->addStatement('pub-id[@pub-id-type="sici"]', $value = 'def');
     $citationDescription->addStatement('pub-id[@pub-id-type="pmid"]', $value = '999999');
     $citationDescription->addStatement('uri', $value = 'http://phpunit.org/nutshell');
     $citationDescription->addStatement('comment', $value = 'just nonsense');
     $citationDescription->addStatement('annotation', $value = 'more nonsense');
     $citationDescription->addStatement('[@publication-type]', $value = 'conf-proc');
     $citation =& $this->getCitation($citationDescription);
     // Persist one copy of the citation for testing.
     $citationDao =& $this->getCitationDao();
     $citation->setSeq(1);
     $citation->setCitationState(CITATION_APPROVED);
     $citationId = $citationDao->insertObject($citation);
     self::assertTrue(is_numeric($citationId));
     self::assertTrue($citationId > 0);
     // Construct the expected output.
     $expectedOutput = '';
     // Prepare NLM 3.0 input.
     $mockSubmission =& $this->getTestSubmission();
     import('lib.pkp.plugins.metadata.nlm30.filter.PKPSubmissionNlm30XmlFilter');
     $nlm30Filter = new PKPSubmissionNlm30XmlFilter(PersistableFilter::tempGroup('class::lib.pkp.classes.submission.Submission', 'xml::*'));
     $nlm30Xml = $nlm30Filter->execute($mockSubmission);
     // Test the downgrade filter.
     import('lib.pkp.classes.xslt.XSLTransformationFilter');
     // FIXME: Add NLM 2.3 and 3.0 tag set schema validation as soon as we implement the full tag set, see #5648.
     $downgradeFilter = new XSLTransformationFilter(PersistableFilter::tempGroup('xml::*', 'xml::*'), 'NLM 3.0 to 2.3 ref-list downgrade');
     $downgradeFilter->setXSLFilename('lib/pkp/plugins/metadata/nlm30/filter/nlm30-to-23-ref-list.xsl');
     $nlm30Xml = $downgradeFilter->execute($nlm30Xml);
     self::assertXmlStringEqualsXmlFile('./lib/pkp/tests/plugins/metadata/nlm30/filter/sample-nlm23-citation.xml', $nlm30Xml);
 }
Exemplo n.º 21
0
 /**
  * Takes the raw xml result of a web service and
  * transforms it via XSL to a (preliminary) XML similar
  * to NLM which is then re-encoded into an array. Finally
  * some typical post-processing is performed.
  * FIXME: Rewrite parser/lookup filter XSL to produce real NLM
  * element-citation XML and factor this code into an NLM XML to
  * NLM description filter.
  * @param $xmlResult string or DOMDocument
  * @param $xslFileName string
  * @return array a metadata array
  */
 function &transformWebServiceResults(&$xmlResult, $xslFileName)
 {
     // Send the result through the XSL to generate a (preliminary) NLM XML.
     $xslFilter = new XSLTransformationFilter(PersistableFilter::tempGroup('xml::*', 'xml::*'), 'Web Service Transformation');
     $xslFilter->setXSLFilename($xslFileName);
     $xslFilter->setResultType(XSL_TRANSFORMER_DOCTYPE_DOM);
     $preliminaryNlm30DOM =& $xslFilter->execute($xmlResult);
     if (is_null($preliminaryNlm30DOM) || is_null($preliminaryNlm30DOM->documentElement)) {
         $translationParams = array('filterName' => $this->getDisplayName());
         $this->addError(__('submission.citations.filter.webserviceResultTransformationError', $translationParams));
         $nullVar = null;
         return $nullVar;
     }
     // Transform the result to an array.
     $xmlHelper = new XMLHelper();
     $preliminaryNlm30Array = $xmlHelper->xmlToArray($preliminaryNlm30DOM->documentElement);
     $preliminaryNlm30Array =& $this->postProcessMetadataArray($preliminaryNlm30Array);
     return $preliminaryNlm30Array;
 }
 /**
  * @covers ParscitRawCitationNlm30CitationSchemaFilter
  */
 public function testExecuteWithWebServiceError()
 {
     $constructor = array(PersistableFilter::tempGroup('primitive::string', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
     $this->assertWebServiceError('ParscitRawCitationNlm30CitationSchemaFilter', $constructor);
 }