Completed
Push — master ( feeac5...f27c97 )
by mw
12s
created

testconstructDescriptionForWikiPageValueChunkOnApproximateValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 9.4285
1
<?php
2
3
namespace SMW\Tests\Query\Parser;
4
5
use SMW\DIProperty;
6
use SMW\DIWikiPage;
7
use SMW\Query\Language\Conjunction;
8
use SMW\Query\Language\Disjunction;
9
use SMW\Query\Parser\DescriptionProcessor;
10
11
/**
12
 * @covers SMW\Query\Parser\DescriptionProcessor
13
 * @group semantic-mediawiki
14
 *
15
 * @license GNU GPL v2+
16
 * @since 2.4
17
 *
18
 * @author mwjames
19
 */
20
class DescriptionProcessorTest extends \PHPUnit_Framework_TestCase {
21
22
	public function testCanConstruct() {
23
24
		$this->assertInstanceOf(
25
			'SMW\Query\Parser\DescriptionProcessor',
26
			new DescriptionProcessor()
27
		);
28
	}
29
30
	public function testError() {
31
32
		$instance = new DescriptionProcessor();
33
		$instance->addError( 'abc' );
34
35
		$this->assertEquals(
36
			array( 'abc' ),
37
			$instance->getErrors()
38
		);
39
40
		$instance->addErrorWithMsgKey( 'Foo' );
41
42
		$this->assertCount(
43
			2,
44
			$instance->getErrors()
45
		);
46
	}
47
48
	public function testconstructDescriptionForPropertyObjectValue() {
49
50
		$instance = new DescriptionProcessor();
51
52
		$this->assertInstanceOf(
53
			'SMW\Query\Language\Description',
54
			$instance->constructDescriptionForPropertyObjectValue( new DIProperty( 'Foo' ), 'bar' )
55
		);
56
	}
57
58
	public function testconstructDescriptionForWikiPageValueChunk() {
59
60
		$instance = new DescriptionProcessor();
61
62
		$valueDescription = $instance->constructDescriptionForWikiPageValueChunk( 'bar' );
63
64
		$this->assertInstanceOf(
65
			'SMW\Query\Language\ValueDescription',
66
			$valueDescription
67
		);
68
69
		$this->assertEquals(
70
			new DIWikiPage( 'Bar', NS_MAIN ),
71
			$valueDescription->getDataItem()
72
		);
73
	}
74
75
	public function testconstructDescriptionForWikiPageValueChunkOnApproximateValue() {
76
77
		$instance = new DescriptionProcessor();
78
79
		$valueDescription = $instance->constructDescriptionForWikiPageValueChunk( '~bar' );
80
81
		$this->assertEquals(
82
			new DIWikiPage( 'bar', NS_MAIN ),
83
			$valueDescription->getDataItem()
84
		);
85
	}
86
87
	public function testGetDisjunctiveCompoundDescription() {
88
89
		$instance = new DescriptionProcessor();
90
91
		$currentDescription = $instance->constructDescriptionForWikiPageValueChunk( 'bar' );
92
93
		$newDescription = $instance->constructDescriptionForPropertyObjectValue(
94
			new DIProperty( 'Foo' ),
95
			'foobar'
96
		);
97
98
		$this->assertInstanceOf(
99
			'SMW\Query\Language\Disjunction',
100
			$instance->constructDisjunctiveCompoundDescriptionFrom( $currentDescription, $newDescription )
101
		);
102
	}
103
104
	public function testGetDisjunctiveCompoundDescriptionForCurrentConjunction() {
105
106
		$instance = new DescriptionProcessor();
107
108
		$currentDescription = new Conjunction();
109
110
		$newDescription = $instance->constructDescriptionForPropertyObjectValue(
111
			new DIProperty( 'Foo' ),
112
			'foobar'
113
		);
114
115
		$this->assertInstanceOf(
116
			'SMW\Query\Language\Disjunction',
117
			$instance->constructDisjunctiveCompoundDescriptionFrom( $currentDescription, $newDescription )
118
		);
119
	}
120
121
	public function testGetDisjunctiveCompoundDescriptionForCurrentDisjunction() {
122
123
		$instance = new DescriptionProcessor();
124
125
		$currentDescription = new Disjunction();
126
127
		$newDescription = $instance->constructDescriptionForPropertyObjectValue(
128
			new DIProperty( 'Foo' ),
129
			'foobar'
130
		);
131
132
		$this->assertInstanceOf(
133
			'SMW\Query\Language\Disjunction',
134
			$instance->constructDisjunctiveCompoundDescriptionFrom( $currentDescription, $newDescription )
135
		);
136
	}
137
138
	public function testTryToGetDisjunctiveCompoundDescriptionForNullNewDescription() {
139
140
		$instance = new DescriptionProcessor();
141
142
		$currentDescription = $instance->constructDescriptionForWikiPageValueChunk( 'bar' );
143
144
		$this->assertInstanceOf(
145
			'SMW\Query\Language\ValueDescription',
146
			$instance->constructDisjunctiveCompoundDescriptionFrom( $currentDescription, null )
147
		);
148
	}
149
150
	public function testTryToGetDisjunctiveCompoundDescriptionForNullCurrentDescription() {
151
152
		$instance = new DescriptionProcessor();
153
154
		$newDescription = $instance->constructDescriptionForWikiPageValueChunk( 'bar' );
155
156
		$this->assertInstanceOf(
157
			'SMW\Query\Language\ValueDescription',
158
			$instance->constructDisjunctiveCompoundDescriptionFrom( null, $newDescription )
159
		);
160
	}
161
162
	public function testGetConjunctiveCompoundDescription() {
163
164
		$instance = new DescriptionProcessor();
165
166
		$currentDescription = $instance->constructDescriptionForWikiPageValueChunk( 'bar' );
167
168
		$newDescription = $instance->constructDescriptionForPropertyObjectValue(
169
			new DIProperty( 'Foo' ),
170
			'foobar'
171
		);
172
173
		$this->assertInstanceOf(
174
			'SMW\Query\Language\Conjunction',
175
			$instance->constructConjunctiveCompoundDescriptionFrom( $currentDescription, $newDescription )
176
		);
177
	}
178
179
	public function testGetConjunctiveCompoundDescriptionForCurrentConjunction() {
180
181
		$instance = new DescriptionProcessor();
182
183
		$currentDescription = new Conjunction();
184
185
		$newDescription = $instance->constructDescriptionForPropertyObjectValue(
186
			new DIProperty( 'Foo' ),
187
			'foobar'
188
		);
189
190
		$this->assertInstanceOf(
191
			'SMW\Query\Language\Conjunction',
192
			$instance->constructConjunctiveCompoundDescriptionFrom( $currentDescription, $newDescription )
193
		);
194
	}
195
196
	public function testGetConjunctiveCompoundDescriptionForCurrentDisjunction() {
197
198
		$instance = new DescriptionProcessor();
199
200
		$currentDescription = new Disjunction();
201
202
		$newDescription = $instance->constructDescriptionForPropertyObjectValue(
203
			new DIProperty( 'Foo' ),
204
			'foobar'
205
		);
206
207
		$this->assertInstanceOf(
208
			'SMW\Query\Language\Conjunction',
209
			$instance->constructConjunctiveCompoundDescriptionFrom( $currentDescription, $newDescription )
210
		);
211
	}
212
213
	public function testTryToGetConjunctiveCompoundDescriptionForNullNewDescription() {
214
215
		$instance = new DescriptionProcessor();
216
217
		$currentDescription = $instance->constructDescriptionForWikiPageValueChunk( 'bar' );
218
219
		$this->assertInstanceOf(
220
			'SMW\Query\Language\ValueDescription',
221
			$instance->constructConjunctiveCompoundDescriptionFrom( $currentDescription, null )
222
		);
223
	}
224
225
	public function testTryToGetConjunctiveCompoundDescriptionForNullCurrentDescription() {
226
227
		$instance = new DescriptionProcessor();
228
229
		$newDescription = $instance->constructDescriptionForWikiPageValueChunk( 'bar' );
230
231
		$this->assertInstanceOf(
232
			'SMW\Query\Language\ValueDescription',
233
			$instance->constructConjunctiveCompoundDescriptionFrom( null, $newDescription )
234
		);
235
	}
236
237
	public function testConstuctDescriptionWithContextPage() {
238
239
		$instance = new DescriptionProcessor();
240
241
		$instance->setContextPage(
242
			DIWikiPage::newFromText( __METHOD__ )
243
		);
244
245
		$currentDescription = new Disjunction();
246
247
		$newDescription = $instance->constructDescriptionForPropertyObjectValue(
248
			new DIProperty( 'Foo' ),
249
			'foobar'
250
		);
251
252
		$this->assertInstanceOf(
253
			'SMW\Query\Language\Conjunction',
254
			$instance->constructConjunctiveCompoundDescriptionFrom( $currentDescription, $newDescription )
255
		);
256
	}
257
258
}
259