1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\DataValues; |
4
|
|
|
|
5
|
|
|
use SMW\DataItemFactory; |
6
|
|
|
use SMW\DataValues\InfoLinksProvider; |
7
|
|
|
use SMW\Tests\TestEnvironment; |
8
|
|
|
use SMW\Message; |
9
|
|
|
use SMWNumberValue as NumberValue; |
10
|
|
|
use SMWStringValue as StringValue; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers \SMW\DataValues\InfoLinksProvider |
14
|
|
|
* @group semantic-mediawiki |
15
|
|
|
* |
16
|
|
|
* @license GNU GPL v2+ |
17
|
|
|
* @since 2.4 |
18
|
|
|
* |
19
|
|
|
* @author mwjames |
20
|
|
|
*/ |
21
|
|
|
class InfoLinksProviderTest extends \PHPUnit_Framework_TestCase { |
22
|
|
|
|
23
|
|
|
private $testEnvironment; |
24
|
|
|
private $dataItemFactory; |
25
|
|
|
private $cachedPropertyValuesPrefetcher; |
26
|
|
|
|
27
|
|
|
protected function setUp() { |
28
|
|
|
$this->testEnvironment = new TestEnvironment(); |
29
|
|
|
$this->dataItemFactory = new DataItemFactory(); |
30
|
|
|
|
31
|
|
|
$this->cachedPropertyValuesPrefetcher = $this->getMockBuilder( '\SMW\CachedPropertyValuesPrefetcher' ) |
32
|
|
|
->disableOriginalConstructor() |
33
|
|
|
->getMock(); |
34
|
|
|
|
35
|
|
|
$this->testEnvironment->registerObject( 'CachedPropertyValuesPrefetcher', $this->cachedPropertyValuesPrefetcher ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function tearDown() { |
39
|
|
|
$this->testEnvironment->tearDown(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testCanConstruct() { |
43
|
|
|
|
44
|
|
|
$dataValue = $this->getMockBuilder( '\SMWDataValue' ) |
45
|
|
|
->disableOriginalConstructor() |
46
|
|
|
->getMockForAbstractClass(); |
47
|
|
|
|
48
|
|
|
$this->assertInstanceOf( |
49
|
|
|
'\SMW\DataValues\InfoLinksProvider', |
50
|
|
|
new InfoLinksProvider( $dataValue ) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetInfolinkTextOnNumberValue() { |
55
|
|
|
|
56
|
|
|
$this->cachedPropertyValuesPrefetcher->expects( $this->atLeastOnce() ) |
57
|
|
|
->method( 'getPropertyValues' ) |
58
|
|
|
->will( $this->returnValue( array() ) ); |
59
|
|
|
|
60
|
|
|
$numberValue = new NumberValue(); |
61
|
|
|
|
62
|
|
|
$numberValue->setOption( 'user.language', 'en' ); |
|
|
|
|
63
|
|
|
$numberValue->setOption( 'content.language', 'en' ); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$numberValue->setProperty( |
66
|
|
|
$this->dataItemFactory->newDIProperty( 'Foo' ) |
|
|
|
|
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$numberValue->setUserValue( '1000.42' ); |
70
|
|
|
|
71
|
|
|
$instance = new InfoLinksProvider( $numberValue ); |
72
|
|
|
|
73
|
|
|
$this->assertContains( |
74
|
|
|
'/Foo/1000.42|+]]</span>', |
75
|
|
|
$instance->getInfolinkText( SMW_OUTPUT_WIKI ) |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$this->assertContains( |
79
|
|
|
'/Foo/1000.42">+</a></span>', |
80
|
|
|
$instance->getInfolinkText( SMW_OUTPUT_HTML ) |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testGetInfolinkTextOnStringValue() { |
85
|
|
|
|
86
|
|
|
$this->cachedPropertyValuesPrefetcher->expects( $this->atLeastOnce() ) |
87
|
|
|
->method( 'getPropertyValues' ) |
88
|
|
|
->will( $this->returnValue( array() ) ); |
89
|
|
|
|
90
|
|
|
$stringValue = new StringValue( '_txt' ); |
91
|
|
|
|
92
|
|
|
$stringValue->setOption( 'user.language', 'en' ); |
|
|
|
|
93
|
|
|
$stringValue->setOption( 'content.language', 'en' ); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$stringValue->setProperty( |
96
|
|
|
$this->dataItemFactory->newDIProperty( 'Foo' ) |
|
|
|
|
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$stringValue->setUserValue( 'Text with :: content' ); |
100
|
|
|
|
101
|
|
|
$instance = new InfoLinksProvider( $stringValue ); |
102
|
|
|
|
103
|
|
|
$this->assertContains( |
104
|
|
|
'/Foo/Text-20with-20-2D3A-2D3A-20content|+]]</span>', |
105
|
|
|
$instance->getInfolinkText( SMW_OUTPUT_WIKI ) |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$this->assertContains( |
109
|
|
|
'/Foo/Text-20with-20-2D3A-2D3A-20content">+</a></span>', |
110
|
|
|
$instance->getInfolinkText( SMW_OUTPUT_HTML ) |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testGetInfolinkTextOnStringValueWithServiceLinks() { |
115
|
|
|
|
116
|
|
|
$service = 'testGetInfolinkTextOnStringValueWithServiceLinks'; |
117
|
|
|
|
118
|
|
|
$this->cachedPropertyValuesPrefetcher->expects( $this->atLeastOnce() ) |
119
|
|
|
->method( 'getPropertyValues' ) |
120
|
|
|
->will( $this->returnValue( array( |
121
|
|
|
$this->dataItemFactory->newDIBlob( $service ) ) ) ); |
122
|
|
|
|
123
|
|
|
// Manipulating the Message cache is a hack!! |
124
|
|
|
$parameters = array( |
125
|
|
|
"smw_service_" . $service, |
126
|
|
|
'Bar' |
127
|
|
|
); |
128
|
|
|
|
129
|
|
|
Message::getCache()->save( |
130
|
|
|
Message::getHash( $parameters, Message::TEXT, Message::CONTENT_LANGUAGE ), |
131
|
|
|
'SERVICELINK-A|SERVICELINK-B' |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
$stringValue = new StringValue( '_txt' ); |
135
|
|
|
|
136
|
|
|
$stringValue->setOption( 'user.language', 'en' ); |
|
|
|
|
137
|
|
|
$stringValue->setOption( 'content.language', 'en' ); |
|
|
|
|
138
|
|
|
|
139
|
|
|
$stringValue->setProperty( |
140
|
|
|
$this->dataItemFactory->newDIProperty( 'Foo' ) |
|
|
|
|
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
$stringValue->setUserValue( 'Bar' ); |
144
|
|
|
|
145
|
|
|
$instance = new InfoLinksProvider( $stringValue ); |
146
|
|
|
|
147
|
|
|
$this->assertContains( |
148
|
|
|
'<div class="smwttcontent">[SERVICELINK-B SERVICELINK-A]</div>', |
149
|
|
|
$instance->getInfolinkText( SMW_OUTPUT_WIKI ) |
150
|
|
|
); |
151
|
|
|
|
152
|
|
|
$this->assertContains( |
153
|
|
|
'<div class="smwttcontent"><a href="SERVICELINK-B">SERVICELINK-A</a></div>', |
154
|
|
|
$instance->getInfolinkText( SMW_OUTPUT_HTML ) |
155
|
|
|
); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
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: