1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\Integration\JSONScript; |
4
|
|
|
|
5
|
|
|
use SMWExportController as ExportController; |
6
|
|
|
use SMWRDFXMLSerializer as RDFXMLSerializer; |
7
|
|
|
use SMWTurtleSerializer as TurtleSerializer; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @group semantic-mediawiki |
11
|
|
|
* @group medium |
12
|
|
|
* |
13
|
|
|
* @license GNU GPL v2+ |
14
|
|
|
* @since 2.3 |
15
|
|
|
* |
16
|
|
|
* @author mwjames |
17
|
|
|
*/ |
18
|
|
|
class RdfTestCaseProcessor extends \PHPUnit_Framework_TestCase { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var Store |
22
|
|
|
*/ |
23
|
|
|
private $store; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var StringValidator |
27
|
|
|
*/ |
28
|
|
|
private $stringValidator; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var RunnerFactory |
32
|
|
|
*/ |
33
|
|
|
private $runnerFactory; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var boolean |
37
|
|
|
*/ |
38
|
|
|
private $debug = false; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param Store |
42
|
|
|
* @param StringValidator |
43
|
|
|
*/ |
44
|
|
|
public function __construct( $store, $stringValidator, $runnerFactory ) { |
45
|
|
|
$this->store = $store; |
46
|
|
|
$this->stringValidator = $stringValidator; |
47
|
|
|
$this->runnerFactory = $runnerFactory; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @since 2.2 |
52
|
|
|
*/ |
53
|
|
|
public function setDebugMode( $debugMode ) { |
54
|
|
|
$this->debug = $debugMode; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function process( array $case ) { |
58
|
|
|
|
59
|
|
|
// Allows for data to be re-read from the DB instead of being fetched |
60
|
|
|
// from the store-id-cache |
61
|
|
|
if ( isset( $case['store']['clear-cache'] ) && $case['store']['clear-cache'] ) { |
62
|
|
|
$this->store->clear(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ( isset( $case['dumpRDF'] ) ) { |
66
|
|
|
$this->assertDumpRdfOutputForCase( $case ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ( isset( $case['exportcontroller'] ) ) { |
70
|
|
|
$this->assertExportControllerOutputForCase( $case ); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function assertDumpRdfOutputForCase( $case ) { |
75
|
|
|
|
76
|
|
|
$maintenanceRunner = $this->runnerFactory->newMaintenanceRunner( 'SMW\Maintenance\DumpRdf' ); |
77
|
|
|
$maintenanceRunner->setQuiet(); |
78
|
|
|
|
79
|
|
|
$maintenanceRunner->setOptions( $case['dumpRDF']['parameters'] ); |
80
|
|
|
$maintenanceRunner->run(); |
81
|
|
|
|
82
|
|
|
$this->assertOutputForCase( |
83
|
|
|
$case, |
84
|
|
|
$maintenanceRunner->getOutput() |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
private function assertExportControllerOutputForCase( $case ) { |
89
|
|
|
|
90
|
|
|
if ( isset( $case['exportcontroller']['syntax'] ) && $case['exportcontroller']['syntax'] === 'turtle' ) { |
91
|
|
|
$serializer = new TurtleSerializer(); |
92
|
|
|
} else { |
93
|
|
|
$serializer = new RDFXMLSerializer(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$exportController = new ExportController( $serializer ); |
97
|
|
|
$exportController->enableBacklinks( $case['exportcontroller']['parameters']['backlinks'] ); |
98
|
|
|
|
99
|
|
|
ob_start(); |
100
|
|
|
|
101
|
|
|
if ( isset( $case['exportcontroller']['print-pages'] ) ) { |
102
|
|
|
$exportController->printPages( |
103
|
|
|
$case['exportcontroller']['print-pages'], |
104
|
|
|
(int)$case['exportcontroller']['parameters']['recursion'], |
105
|
|
|
$case['exportcontroller']['parameters']['revisiondate'] |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
if ( isset( $case['exportcontroller']['wiki-info'] ) ) { |
110
|
|
|
$exportController->printWikiInfo(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$output = ob_get_clean(); |
114
|
|
|
|
115
|
|
|
$this->assertOutputForCase( $case, $output ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
private function assertOutputForCase( $case, $output ) { |
119
|
|
|
|
120
|
|
|
if ( $this->debug ) { |
121
|
|
|
print_r( $output ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if ( isset( $case['assert-output']['to-contain'] ) ) { |
125
|
|
|
$this->stringValidator->assertThatStringContains( |
126
|
|
|
$case['assert-output']['to-contain'], |
127
|
|
|
$output, |
128
|
|
|
$case['about'] |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
if ( isset( $case['assert-output']['not-contain'] ) ) { |
133
|
|
|
$this->stringValidator->assertThatStringNotContains( |
134
|
|
|
$case['assert-output']['not-contain'], |
135
|
|
|
$output, |
136
|
|
|
$case['about'] |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
} |
142
|
|
|
|