Completed
Push — master ( 0b8079...0fbd73 )
by mw
34:05
created

AllowsPatternValueTest::testGetShortHtmlText()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 24
nc 1
nop 0
dl 0
loc 36
rs 8.8571
c 1
b 0
f 0
1
<?php
2
3
namespace SMW\Tests\DataValues;
4
5
use SMW\DataItemFactory;
6
use SMW\DataValues\AllowsPatternValue;
7
use SMW\DataValues\ValueParsers\AllowsPatternValueParser;
8
use SMW\Tests\TestEnvironment;
9
10
/**
11
 * @covers \SMW\DataValues\AllowsPatternValue
12
 * @group semantic-mediawiki
13
 *
14
 * @license GNU GPL v2+
15
 * @since 2.4
16
 *
17
 * @author mwjames
18
 */
19
class AllowsPatternValueTest extends \PHPUnit_Framework_TestCase {
20
21
	private $testEnvironment;
22
	private $dataItemFactory;
23
	private $dataValueServiceFactory;
24
	private $constraintValueValidator;
25
26
	protected function setUp() {
27
28
		$this->testEnvironment = new TestEnvironment();
29
		$this->dataItemFactory = new DataItemFactory();
30
31
		$this->mediaWikiNsContentReader = $this->getMockBuilder( '\SMW\MediaWiki\MediaWikiNsContentReader' )
32
			->disableOriginalConstructor()
33
			->getMock();
34
35
		$this->testEnvironment->registerObject( 'MediaWikiNsContentReader', $this->mediaWikiNsContentReader );
36
37
		$propertySpecificationLookup = $this->getMockBuilder( '\SMW\PropertySpecificationLookup' )
38
			->disableOriginalConstructor()
39
			->getMock();
40
41
		$this->testEnvironment->registerObject( 'PropertySpecificationLookup', $propertySpecificationLookup );
42
43
		$this->constraintValueValidator = $this->getMockBuilder( '\SMW\DataValues\ValueValidators\ConstraintValueValidator' )
44
			->disableOriginalConstructor()
45
			->getMock();
46
47
		$this->dataValueServiceFactory = $this->getMockBuilder( '\SMW\Services\DataValueServiceFactory' )
48
			->disableOriginalConstructor()
49
			->getMock();
50
51
		$this->dataValueServiceFactory->expects( $this->any() )
52
			->method( 'getValueParser' )
53
			->will( $this->returnValue( new AllowsPatternValueParser( $this->mediaWikiNsContentReader ) ) );
54
55
		$this->dataValueServiceFactory->expects( $this->any() )
56
			->method( 'getConstraintValueValidator' )
57
			->will( $this->returnValue( $this->constraintValueValidator ) );
58
	}
59
60
	protected function tearDown() {
61
		$this->testEnvironment->tearDown();
62
	}
63
64
	public function testCanConstruct() {
65
66
		$this->assertInstanceOf(
67
			'\SMW\DataValues\AllowsPatternValue',
68
			new AllowsPatternValue()
69
		);
70
	}
71
72
	public function testHasErrorForMissingValue() {
73
74
		$instance = new AllowsPatternValue();
75
76
		$instance->setDataValueServiceFactory(
77
			$this->dataValueServiceFactory
78
		);
79
80
		$instance->setOption( 'smwgDVFeatures', SMW_DV_PVAP );
0 ignored issues
show
Documentation introduced by
SMW_DV_PVAP is of type integer, but the function expects a object<mxied>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81
82
		$instance->setUserValue( '' );
83
84
		$this->assertNotEmpty(
85
			$instance->getErrors()
86
		);
87
	}
88
89
	public function testHasErrorForNonMatchingContent() {
90
91
		$this->mediaWikiNsContentReader->expects( $this->once() )
92
			->method( 'read' )
93
			->will( $this->returnValue( " \nFoo|Bar\n" ) );
94
95
		$instance = new AllowsPatternValue();
96
97
		$instance->setDataValueServiceFactory(
98
			$this->dataValueServiceFactory
99
		);
100
101
		$instance->setOption( 'smwgDVFeatures', SMW_DV_PVAP );
0 ignored issues
show
Documentation introduced by
SMW_DV_PVAP is of type integer, but the function expects a object<mxied>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
102
103
		$instance->setUserValue( 'NotMatchable' );
104
105
		$this->assertNotEmpty(
106
			$instance->getErrors()
107
		);
108
	}
109
110
	public function testHasNoErrorOnMatchableContent() {
111
112
		$this->mediaWikiNsContentReader->expects( $this->once() )
113
			->method( 'read' )
114
			->will( $this->returnValue( " \nFoo|Bar\n" ) );
115
116
		$instance = new AllowsPatternValue();
117
118
		$instance->setDataValueServiceFactory(
119
			$this->dataValueServiceFactory
120
		);
121
122
		$instance->setOption( 'smwgDVFeatures', SMW_DV_PVAP );
0 ignored issues
show
Documentation introduced by
SMW_DV_PVAP is of type integer, but the function expects a object<mxied>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
124
		$instance->setUserValue( 'Foo' );
125
126
		$this->assertEmpty(
127
			$instance->getErrors()
128
		);
129
	}
130
131
	public function testErrorOnNotEnabledFeatureWhenUserValueIsNotEmpty() {
132
133
		$instance = new AllowsPatternValue();
134
135
		$instance->setDataValueServiceFactory(
136
			$this->dataValueServiceFactory
137
		);
138
139
		$instance->setUserValue( 'abc/e' );
140
141
		$this->assertNotEmpty(
142
			$instance->getErrors()
143
		);
144
	}
145
146
	public function testGetShortWikiText() {
147
148
		$allowsPatternValueParser = $this->getMockBuilder( '\SMW\DataValues\ValueParsers\AllowsPatternValueParser' )
149
			->disableOriginalConstructor()
150
			->getMock();
151
152
		$allowsPatternValueParser->expects( $this->any() )
153
			->method( 'parse' )
154
			->will( $this->returnValue( 'Foo' ) );
155
156
		$dataValueServiceFactory = $this->getMockBuilder( '\SMW\Services\DataValueServiceFactory' )
157
			->disableOriginalConstructor()
158
			->getMock();
159
160
		$dataValueServiceFactory->expects( $this->any() )
161
			->method( 'getValueParser' )
162
			->will( $this->returnValue( $allowsPatternValueParser ) );
163
164
		$dataValueServiceFactory->expects( $this->any() )
165
			->method( 'getConstraintValueValidator' )
166
			->will( $this->returnValue( $this->constraintValueValidator ) );
167
168
		$instance = new AllowsPatternValue();
169
		$instance->setOption( 'smwgDVFeatures', SMW_DV_PVAP );
0 ignored issues
show
Documentation introduced by
SMW_DV_PVAP is of type integer, but the function expects a object<mxied>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
170
171
		$instance->setDataValueServiceFactory(
172
			$dataValueServiceFactory
173
		);
174
175
		$instance->setUserValue( 'abc/e' );
176
177
		$this->assertContains(
178
			'Smw_allows_pattern',
179
			$instance->getShortWikiText()
180
		);
181
	}
182
183
	public function testGetShortHtmlText() {
184
185
		$allowsPatternValueParser = $this->getMockBuilder( '\SMW\DataValues\ValueParsers\AllowsPatternValueParser' )
186
			->disableOriginalConstructor()
187
			->getMock();
188
189
		$allowsPatternValueParser->expects( $this->any() )
190
			->method( 'parse' )
191
			->will( $this->returnValue( 'Foo' ) );
192
193
		$dataValueServiceFactory = $this->getMockBuilder( '\SMW\Services\DataValueServiceFactory' )
194
			->disableOriginalConstructor()
195
			->getMock();
196
197
		$dataValueServiceFactory->expects( $this->any() )
198
			->method( 'getValueParser' )
199
			->will( $this->returnValue( $allowsPatternValueParser ) );
200
201
		$dataValueServiceFactory->expects( $this->any() )
202
			->method( 'getConstraintValueValidator' )
203
			->will( $this->returnValue( $this->constraintValueValidator ) );
204
205
		$instance = new AllowsPatternValue();
206
		$instance->setOption( 'smwgDVFeatures', SMW_DV_PVAP );
0 ignored issues
show
Documentation introduced by
SMW_DV_PVAP is of type integer, but the function expects a object<mxied>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
207
208
		$instance->setDataValueServiceFactory(
209
			$dataValueServiceFactory
210
		);
211
212
		$instance->setUserValue( 'abc/e' );
213
214
		$this->assertContains(
215
			'Smw_allows_pattern',
216
			$instance->getShortHtmlText()
217
		);
218
	}
219
220
}
221