1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
);
}
}
|