1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\DataValues; |
4
|
|
|
|
5
|
|
|
use SMW\DataValues\ErrorMsgTextValue; |
6
|
|
|
use SMW\DataItemFactory; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SMW\DataValues\ErrorMsgTextValue |
10
|
|
|
* @group semantic-mediawiki |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 2.5 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class ErrorMsgTextValueTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
private $dataItemFactory; |
20
|
|
|
|
21
|
|
|
protected function setUp() { |
22
|
|
|
$this->dataItemFactory = new DataItemFactory(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testCanConstruct() { |
26
|
|
|
|
27
|
|
|
$this->assertInstanceOf( |
28
|
|
|
'\SMW\DataValues\ErrorMsgTextValue', |
29
|
|
|
new ErrorMsgTextValue() |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testErrorOnEmptyUserValue() { |
34
|
|
|
|
35
|
|
|
$instance = new ErrorMsgTextValue(); |
36
|
|
|
$instance->setUserValue( '' ); |
37
|
|
|
|
38
|
|
|
$this->assertNotEmpty( |
39
|
|
|
$instance->getErrors() |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testShortWikiText() { |
44
|
|
|
|
45
|
|
|
$instance = new ErrorMsgTextValue(); |
46
|
|
|
$instance->setOption( ErrorMsgTextValue::OPT_USER_LANGUAGE, 'en' ); |
|
|
|
|
47
|
|
|
$instance->setUserValue( '[2,"smw-datavalue-uniqueness-constraint-error","Has Url","http:\/\/loremipsum.org\/2","Lorem ipsum\/2"]' ); |
48
|
|
|
|
49
|
|
|
$this->assertContains( |
50
|
|
|
"''http://loremipsum.org/2''", |
51
|
|
|
$instance->getShortWikiText( true ) |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->assertContains( |
55
|
|
|
"''http://loremipsum.org/2''", |
56
|
|
|
$instance->getShortWikiText( null ) |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$this->assertNotContains( |
60
|
|
|
'<a rel="nofollow" class="external free" href="http://loremipsum.org/2">http://loremipsum.org/2</a>', |
61
|
|
|
$instance->getShortWikiText( true ) |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$this->assertNotContains( |
65
|
|
|
'<a rel="nofollow" class="external free" href="http://loremipsum.org/2">http://loremipsum.org/2</a>', |
66
|
|
|
$instance->getShortWikiText( null ) |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @dataProvider textProvider |
72
|
|
|
*/ |
73
|
|
|
public function testValueOutput( $text, $expected ) { |
74
|
|
|
|
75
|
|
|
$dataItem = $this->dataItemFactory->newDIBlob( $text ); |
76
|
|
|
|
77
|
|
|
$instance = new ErrorMsgTextValue(); |
78
|
|
|
$instance->setDataItem( $dataItem ); |
79
|
|
|
|
80
|
|
|
$this->assertEquals( |
81
|
|
|
$expected, |
82
|
|
|
$instance->getWikiValue() |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$this->assertEquals( |
86
|
|
|
$expected, |
87
|
|
|
$instance->getShortWikiText() |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( |
91
|
|
|
$expected, |
92
|
|
|
$instance->getShortHTMLText() |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$this->assertEquals( |
96
|
|
|
$expected, |
97
|
|
|
$instance->getLongWikiText() |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
$this->assertEquals( |
101
|
|
|
$expected, |
102
|
|
|
$instance->getLongHTMLText() |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function textProvider() { |
107
|
|
|
|
108
|
|
|
$provider[] = array( |
|
|
|
|
109
|
|
|
'Foo', |
110
|
|
|
'Foo' |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
$provider[] = array( |
114
|
|
|
'[2,"Foo"]', |
115
|
|
|
'Foo' |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
return $provider; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
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: