/** * @copydoc PHPUnit_Framework_TestCase::tearDown() */ protected function tearDown() { parent::tearDown(); $affectedTables = $this->getAffectedTables(); if (is_array($affectedTables)) { PKPTestHelper::restoreTables($this->getAffectedTables(), $this); } elseif ($affectedTables === PKP_TEST_ENTIRE_DB) { PKPTestHelper::restoreDB($this); } // Switch xdebug screaming back on. PKPTestHelper::xdebugScream(true); }
/** * @covers XMLTypeDescription */ public function testInstantiateAndCheck() { $this->markTestSkipped(); // Xdebug's scream parameter will disable the @ operator // that we need for XML validation. PKPTestHelper::xdebugScream(false); // Test with dtd validation $typeDescription = new XMLTypeDescription('dtd'); $testXmlDom = new DOMDocument(); $testXmlDom->load(dirname(__FILE__) . '/dtdsample-valid.xml'); self::assertTrue($typeDescription->isCompatible($testXmlDom)); $testXmlDom->load(dirname(__FILE__) . '/dtdsample-invalid.xml'); self::assertFalse($typeDescription->isCompatible($testXmlDom)); // Test with xsd validation $typeDescription = new XMLTypeDescription('schema(' . dirname(__FILE__) . '/xsdsample.xsd)'); $testXmlDom = new DOMDocument(); $testXmlDom->load(dirname(__FILE__) . '/xsdsample-valid.xml'); self::assertTrue($typeDescription->isCompatible($testXmlDom)); $testXmlDom->load(dirname(__FILE__) . '/xsdsample-invalid.xml'); self::assertFalse($typeDescription->isCompatible($testXmlDom)); // Test with rng validation $typeDescription = new XMLTypeDescription('relax-ng(' . dirname(__FILE__) . '/rngsample.rng)'); $testXmlDom = new DOMDocument(); $testXmlDom->load(dirname(__FILE__) . '/rngsample-valid.xml'); self::assertTrue($typeDescription->isCompatible($testXmlDom)); $testXmlDom->load(dirname(__FILE__) . '/rngsample-invalid.xml'); self::assertFalse($typeDescription->isCompatible($testXmlDom)); // Try passing in the document as a string $document = '<addressBook> <card> <name>John Smith</name> <email>js@example.com</email> </card> <card> <name>Fred Bloggs</name> <email>fb@example.net</email> </card> </addressBook>'; self::assertTrue($typeDescription->isCompatible($document)); // Test without schema validation $typeDescription = new XMLTypeDescription('*'); $testXmlDom = new DOMDocument(); $testXmlDom->load(dirname(__FILE__) . '/rngsample-valid.xml'); self::assertTrue($typeDescription->isCompatible($testXmlDom)); $testXmlDom->load(dirname(__FILE__) . '/rngsample-invalid.xml'); self::assertTrue($typeDescription->isCompatible($testXmlDom)); }
public function testPubIdsImport() { $journalDao = DAORegistry::getDAO('JournalDAO'); PKPTestHelper::xdebugScream(false); $journalDao->deleteAllPubIds(1, 'other::urn'); PKPTestHelper::xdebugScream(true); $testfile = 'tests/functional/plugins/importexport/pubIds/sample.xml'; $args = array('import', $testfile, 'test', 'admin'); $result = $this->executeCli('PubIdImportExportPlugin', $args); self::assertRegExp('/##plugins.importexport.pubIds.import.success.description##/', $result); // Export single object. $export = $this->getXpathOnExport('PubIdImportExportPlugin/exportIssue/1'); $testCases = array('//pubId[@pubIdType="other::urn"][@pubObjectType="Issue"]' => 'urn:nbn:de:1234-issue1URNSuffix', '//pubId[@pubIdType="other::urn"][@pubObjectType="Article"]' => 'urn:nbn:de:1234-article1URNSuffix', '//pubId[@pubIdType="other::urn"][@pubObjectType="Galley"][@pubObjectId="1"]' => 'urn:nbn:de:1234-galley1URNSuffix', '//pubId[@pubIdType="other::urn"][@pubObjectType="Galley"][@pubObjectId="2"]' => 'urn:nbn:de:1234-galley2URNSuffix'); foreach ($testCases as $xPath => $expectedPubId) { self::assertEquals($expectedPubId, $export->evaluate("string({$xPath})"), "Error while evaluating xPath for {$expectedPubId}:"); } // Trying to import the same file again should lead to an error. $args = array('import', $testfile, 'test', 'admin'); $result = $this->executeCli('PubIdImportExportPlugin', $args); self::assertRegExp('/##plugins.importexport.pubIds.import.error.pubIdExists##/', $result); }
/** * SCENARIO OUTLINE: Objects without DOIs cannot be selected for export. * * GIVEN I configure custom DOIs * AND I've not yet assigned a DOI to an object * THEN the object will not appear on the corresponding {export page}. * * EXAMPLES: See sub-classes. */ protected function testObjectsWithoutDOICannotBeSelectedForExport($exportPages) { $this->logIn(); // Configure custom DOIs. $pubIdPlugins = PluginRegistry::loadCategory('pubIds'); $doiPlugin = $pubIdPlugins['DOIPubIdPlugin']; $doiPlugin->updateSetting(1, 'doiSuffix', 'customId'); // Delete all existing DOIs. $journalDao = DAORegistry::getDAO('JournalDAO'); /* @var $journalDao JournalDAO */ PKPTestHelper::xdebugScream(false); $journalDao->deleteAllPubIds(1, 'doi'); PKPTestHelper::xdebugScream(true); // Make sure that no custom suffix is saved for our test objects. $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */ $issue = $issueDao->getById(1, 1); $issue->setData('doiSuffix', ''); $issueDao->updateObject($issue); $articleDao = DAORegistry::getDAO('ArticleDAO'); /* @var $articleDao ArticleDAO */ $article = $articleDao->getById(1, 1); $article->setData('doiSuffix', ''); $articleDao->updateObject($article); // Do not use PublishedArticleDAO::updatePublishedArticle() for this, otherwise the ADODB cache flush there may cause a permission error. $galleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $galleyDao ArticleGalleyDAO */ $galleys = $galleyDao->getGalleysByArticle(1, 1); foreach ($galleys as $galley) { $galley->setData('doiSuffix', ''); $galleyDao->updateGalley($galley); } $suppFileDao = DAORegistry::getDAO('SuppFileDAO'); /* @var $suppFileDao SuppFileDAO */ $suppFiles = $suppFileDao->getSuppFilesByArticle(1); foreach ($suppFiles as $suppFile) { $suppFile->setData('doiSuffix', ''); $suppFileDao->updateSuppFile($suppFile); } foreach ($exportPages as $exportPage) { try { // Check that the object does not appear on the export page. $this->open($this->pages[$exportPage]); // Check that we get an empty list. This implicitly tests // that the "no data" marker is correctly displayed. $this->assertElementPresent('css=td.nodata'); } catch (Exception $e) { throw $this->improveException($e, "{$exportPage} page"); } } }
/** * Execute the plug-in via its CLI interface. * @param $pluginName string * @param $args array * @return string CLI output */ protected function executeCLI($pluginName, $args) { ob_start(); $plugin = $this->instantiatePlugin($pluginName); PKPTestHelper::xdebugScream(false); $plugin->executeCLI(get_class($this), $args, true); PKPTestHelper::xdebugScream(true); return ob_get_clean(); }
/** * @copydoc PHPUnit_Framework_TestCase::tearDown() */ protected function tearDown() { parent::tearDown(); if (Config::getVar('general', 'installed')) { $affectedTables = $this->getAffectedTables(); if (is_array($affectedTables)) { PKPTestHelper::restoreTables($this->getAffectedTables(), $this); } elseif ($affectedTables === PKP_TEST_ENTIRE_DB) { PKPTestHelper::restoreDB($this); } } }