summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/RdfFileResourceTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/RdfFileResourceTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/RdfFileResourceTest.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/RdfFileResourceTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/RdfFileResourceTest.php
new file mode 100644
index 00000000..131d3c82
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/RdfFileResourceTest.php
@@ -0,0 +1,100 @@
+<?php
+
+namespace SMW\Tests\Integration;
+
+use SMW\DIWikiPage;
+use SMW\Localizer;
+use SMW\Tests\MwDBaseUnitTestCase;
+use SMWExportController as ExportController;
+use SMWRDFXMLSerializer as RDFXMLSerializer;
+use Title;
+
+/**
+ * @group semantic-mediawiki
+ * @group medium
+ *
+ * @license GNU GPL v2+
+ * @since 2.2
+ *
+ * @author mwjames
+ */
+class RdfFileResourceTest extends MwDBaseUnitTestCase {
+
+ private $fixturesFileProvider;
+ private $stringValidator;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $utilityFactory = $this->testEnvironment->getUtilityFactory();
+
+ $this->fixturesFileProvider = $utilityFactory->newFixturesFactory()->newFixturesFileProvider();
+ $this->stringValidator = $utilityFactory->newValidatorFactory()->newStringValidator();
+
+ $this->testEnvironment->withConfiguration( [
+ 'smwgPageSpecialProperties' => [ '_MEDIA', '_MIME' ],
+ 'smwgNamespacesWithSemanticLinks' => [ NS_MAIN => true, NS_FILE => true ],
+ 'smwgMainCacheType' => 'hash',
+ 'smwgExportBCAuxiliaryUse' => true
+ ] );
+
+ // Ensure that the DB creates the extra tables for MEDIA/MINE
+ $this->getStore()->clear();
+ $this->getStore()->setupStore( false );
+
+ // MW GLOBALS to be restored after the test
+ $this->testEnvironment->withConfiguration( [
+ 'wgEnableUploads' => true,
+ 'wgFileExtensions' => [ 'txt' ],
+ 'wgVerifyMimeType' => true
+ ] );
+
+ \SMWExporter::clear();
+ }
+
+ protected function tearDown() {
+ $this->testEnvironment->tearDown();
+ parent::tearDown();
+ }
+
+ public function testFileUploadForDummyTextFile() {
+ Localizer::getInstance()->clear();
+
+ $subject = new DIWikiPage( 'RdfLinkedFile.txt', NS_FILE );
+ $fileNS = Localizer::getInstance()->getNamespaceTextById( NS_FILE );
+
+ $dummyTextFile = $this->fixturesFileProvider->newUploadForDummyTextFile(
+ 'RdfLinkedFile.txt'
+ );
+
+ $dummyTextFile->doUpload(
+ '[[HasFile::File:RdfLinkedFile.txt]]'
+ );
+
+ $this->testEnvironment->executePendingDeferredUpdates();
+
+ $exportController = new ExportController( new RDFXMLSerializer() );
+ $exportController->enableBacklinks( false );
+
+ ob_start();
+
+ $exportController->printPages(
+ [ $subject->getTitle()->getPrefixedDBKey() ]
+ );
+
+ $output = ob_get_clean();
+
+ $expected = [
+ "<rdfs:label>{$fileNS}:RdfLinkedFile.txt</rdfs:label>",
+ '<swivt:file rdf:resource="' . $dummyTextFile->getLocalFile()->getFullURL() . '"/>',
+ '<property:Media_type-23aux rdf:datatype="http://www.w3.org/2001/XMLSchema#string">TEXT</property:Media_type-23aux>',
+ '<property:MIME_type-23aux rdf:datatype="http://www.w3.org/2001/XMLSchema#string">text/plain</property:MIME_type-23aux>'
+ ];
+
+ $this->stringValidator->assertThatStringContains(
+ $expected,
+ $output
+ );
+ }
+
+}