1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\DataValues; |
4
|
|
|
|
5
|
|
|
use SMW\DataValues\TemperatureValue; |
6
|
|
|
use SMW\ApplicationFactory; |
7
|
|
|
use SMW\DIProperty; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers \SMW\DataValues\TemperatureValue |
11
|
|
|
* @group semantic-mediawiki |
12
|
|
|
* |
13
|
|
|
* @license GNU GPL v2+ |
14
|
|
|
* @since 2.4 |
15
|
|
|
* |
16
|
|
|
* @author mwjames |
17
|
|
|
*/ |
18
|
|
|
class TemperatureValueTest extends \PHPUnit_Framework_TestCase { |
19
|
|
|
|
20
|
|
|
public function testCanConstruct() { |
21
|
|
|
|
22
|
|
|
$this->assertInstanceOf( |
23
|
|
|
'\SMW\DataValues\TemperatureValue', |
24
|
|
|
new TemperatureValue() |
25
|
|
|
); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testSetUserValueToReturnKelvinForAnyNonPreferredDisplayUnit() { |
29
|
|
|
|
30
|
|
|
$instance = new TemperatureValue(); |
31
|
|
|
$instance->setUserValue( '100 °C' ); |
32
|
|
|
|
33
|
|
|
$this->assertContains( |
34
|
|
|
'373.15 K', |
35
|
|
|
$instance->getWikiValue() |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$instance->setUserValue( '100 Fahrenheit' ); |
39
|
|
|
|
40
|
|
|
$this->assertContains( |
41
|
|
|
'310.928 K', |
42
|
|
|
$instance->getWikiValue() |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$this->assertContains( |
46
|
|
|
'100 Fahrenheit', |
47
|
|
|
$instance->getShortWikiText() |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testSetUserValueOnUnknownUnit() { |
52
|
|
|
|
53
|
|
|
$instance = new TemperatureValue(); |
54
|
|
|
$instance->setUserValue( '100 Unknown' ); |
55
|
|
|
|
56
|
|
|
$this->assertContains( |
57
|
|
|
'error', |
58
|
|
|
$instance->getWikiValue() |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testSetUserValueToReturnOnPreferredDisplayUnit() { |
63
|
|
|
|
64
|
|
|
$propertySpecificationLookup = $this->getMockBuilder( '\SMW\PropertySpecificationLookup' ) |
65
|
|
|
->disableOriginalConstructor() |
66
|
|
|
->getMock(); |
67
|
|
|
|
68
|
|
|
$propertySpecificationLookup->expects( $this->once() ) |
69
|
|
|
->method( 'getDisplayUnitsFor' ) |
70
|
|
|
->will( $this->returnValue( array( 'Celsius' ) ) ); |
71
|
|
|
|
72
|
|
|
ApplicationFactory::getInstance()->registerObject( 'PropertySpecificationLookup', $propertySpecificationLookup ); |
73
|
|
|
|
74
|
|
|
$instance = new TemperatureValue(); |
75
|
|
|
$instance->setProperty( new DIProperty( 'Foo' ) ); |
|
|
|
|
76
|
|
|
$instance->setUserValue( '100 °C' ); |
77
|
|
|
|
78
|
|
|
$this->assertContains( |
79
|
|
|
'373 K', |
80
|
|
|
$instance->getWikiValue() |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$this->assertContains( |
84
|
|
|
'100 °C', |
85
|
|
|
$instance->getShortWikiText() |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$this->assertContains( |
89
|
|
|
'100 °C (373 K, 212 °F, 672 °R)', |
90
|
|
|
$instance->getLongWikiText() |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
ApplicationFactory::getInstance()->clear(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.