These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace SMW\Tests\DataValues\ValueFormatters; |
||
4 | |||
5 | use SMW\DataValues\ReferenceValue; |
||
6 | use SMW\DataValues\ValueFormatters\ReferenceValueFormatter; |
||
7 | use SMW\DataItemFactory; |
||
8 | use SMW\Tests\TestEnvironment; |
||
9 | |||
10 | /** |
||
11 | * @covers \SMW\DataValues\ValueFormatters\ReferenceValueFormatter |
||
12 | * @group semantic-mediawiki |
||
13 | * |
||
14 | * @license GNU GPL v2+ |
||
15 | * @since 2.5 |
||
16 | * |
||
17 | * @author mwjames |
||
18 | */ |
||
19 | class ReferenceValueFormatterTest extends \PHPUnit_Framework_TestCase { |
||
20 | |||
21 | private $testEnvironment; |
||
22 | private $dataItemFactory; |
||
23 | private $stringValidator; |
||
24 | |||
25 | protected function setUp() { |
||
26 | parent::setUp(); |
||
27 | |||
28 | $this->testEnvironment = new TestEnvironment(); |
||
29 | $this->dataItemFactory = new DataItemFactory(); |
||
30 | |||
31 | $this->stringValidator = $this->testEnvironment->getUtilityFactory()->newValidatorFactory()->newStringValidator(); |
||
32 | |||
33 | $this->propertySpecificationLookup = $this->getMockBuilder( '\SMW\PropertySpecificationLookup' ) |
||
34 | ->disableOriginalConstructor() |
||
35 | ->getMock(); |
||
36 | |||
37 | $this->testEnvironment->registerObject( 'PropertySpecificationLookup', $this->propertySpecificationLookup ); |
||
38 | } |
||
39 | |||
40 | protected function tearDown() { |
||
41 | $this->testEnvironment->tearDown(); |
||
42 | parent::tearDown(); |
||
43 | } |
||
44 | |||
45 | public function testCanConstruct() { |
||
46 | |||
47 | $this->assertInstanceOf( |
||
48 | '\SMW\DataValues\ValueFormatters\ReferenceValueFormatter', |
||
49 | new ReferenceValueFormatter() |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | public function testIsFormatterForValidation() { |
||
54 | |||
55 | $referenceValue = $this->getMockBuilder( '\SMW\DataValues\ReferenceValue' ) |
||
56 | ->disableOriginalConstructor() |
||
57 | ->getMock(); |
||
58 | |||
59 | $instance = new ReferenceValueFormatter(); |
||
60 | |||
61 | $this->assertTrue( |
||
62 | $instance->isFormatterFor( $referenceValue ) |
||
63 | ); |
||
64 | } |
||
65 | |||
66 | public function testToUseCaptionOutput() { |
||
67 | |||
68 | $referenceValue = new ReferenceValue(); |
||
69 | $referenceValue->setCaption( 'ABC' ); |
||
70 | |||
71 | $instance = new ReferenceValueFormatter( $referenceValue ); |
||
72 | |||
73 | $this->assertEquals( |
||
74 | 'ABC', |
||
75 | $instance->format( ReferenceValueFormatter::WIKI_SHORT ) |
||
76 | ); |
||
77 | |||
78 | $this->assertEquals( |
||
79 | 'ABC', |
||
80 | $instance->format( ReferenceValueFormatter::HTML_SHORT ) |
||
81 | ); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @dataProvider stringValueProvider |
||
86 | */ |
||
87 | public function testFormat( $suserValue, $type, $linker, $expected ) { |
||
88 | |||
89 | $referenceValue = new ReferenceValue(); |
||
90 | |||
91 | $referenceValue->setFieldProperties( array( |
||
92 | $this->dataItemFactory->newDIProperty( 'Foo' ), |
||
93 | $this->dataItemFactory->newDIProperty( 'Date' ), |
||
94 | $this->dataItemFactory->newDIProperty( 'URL' ) |
||
95 | ) ); |
||
96 | |||
97 | $referenceValue->setOption( ReferenceValue::OPT_CONTENT_LANGUAGE, 'en' ); |
||
0 ignored issues
–
show
|
|||
98 | $referenceValue->setOption( ReferenceValue::OPT_USER_LANGUAGE, 'en' ); |
||
0 ignored issues
–
show
'en' is of type string , 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...
|
|||
99 | |||
100 | $referenceValue->setUserValue( $suserValue ); |
||
101 | |||
102 | $instance = new ReferenceValueFormatter( $referenceValue ); |
||
103 | |||
104 | $this->stringValidator->assertThatStringContains( |
||
105 | $expected, |
||
106 | $instance->format( $type, $linker ) |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | public function testTryToFormatOnMissingDataValueThrowsException() { |
||
111 | |||
112 | $instance = new ReferenceValueFormatter(); |
||
113 | |||
114 | $this->setExpectedException( 'RuntimeException' ); |
||
115 | $instance->format( ReferenceValueFormatter::VALUE ); |
||
116 | } |
||
117 | |||
118 | public function stringValueProvider() { |
||
119 | |||
120 | $provider[] = array( |
||
121 | 'abc;12;3', |
||
122 | ReferenceValueFormatter::VALUE, |
||
123 | null, |
||
124 | 'Abc;12;3' |
||
125 | ); |
||
126 | |||
127 | $provider[] = array( |
||
128 | 'abc', |
||
129 | ReferenceValueFormatter::WIKI_SHORT, |
||
130 | null, |
||
131 | array( |
||
132 | 'Abc', |
||
133 | 'class="smw-reference smw-reference-indicator smw-highlighter smwttinline"', |
||
134 | 'data-title="Reference"', |
||
135 | 'title="Date: ?, URL: ?"' |
||
136 | ) |
||
137 | ); |
||
138 | |||
139 | $provider[] = array( |
||
140 | 'abc', |
||
141 | ReferenceValueFormatter::HTML_SHORT, |
||
142 | null, |
||
143 | array( |
||
144 | 'Abc', |
||
145 | 'class="smw-reference smw-reference-indicator smw-highlighter smwttinline"', |
||
146 | 'data-title="Reference"', |
||
147 | 'title="Date: ?, URL: ?"' |
||
148 | ) |
||
149 | ); |
||
150 | |||
151 | $provider[] = array( |
||
152 | 'abc', |
||
153 | ReferenceValueFormatter::WIKI_LONG, |
||
154 | null, |
||
155 | array( |
||
156 | 'Abc', |
||
157 | 'class="smw-reference smw-reference-indicator smw-highlighter smwttinline"', |
||
158 | 'data-title="Reference"', |
||
159 | 'title="Date: ?, URL: ?"' |
||
160 | ) |
||
161 | ); |
||
162 | |||
163 | $provider[] = array( |
||
164 | 'abc', |
||
165 | ReferenceValueFormatter::HTML_LONG, |
||
166 | null, |
||
167 | array( |
||
168 | 'Abc', |
||
169 | 'class="smw-reference smw-reference-indicator smw-highlighter smwttinline"', |
||
170 | 'data-title="Reference"', |
||
171 | 'title="Date: ?, URL: ?"' |
||
172 | ) |
||
173 | ); |
||
174 | |||
175 | return $provider; |
||
176 | } |
||
177 | |||
178 | } |
||
179 |
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: