1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\DataValues\ValueFormatters; |
4
|
|
|
|
5
|
|
|
use SMW\DataValues\ValueFormatters\NoValueFormatter; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \SMW\DataValues\ValueFormatters\NoValueFormatter |
9
|
|
|
* @group semantic-mediawiki |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 2.4 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class NoValueFormatterTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
public function testCanConstruct() { |
19
|
|
|
|
20
|
|
|
$this->assertInstanceOf( |
21
|
|
|
'\SMW\DataValues\ValueFormatters\NoValueFormatter', |
22
|
|
|
new NoValueFormatter() |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testIsFormatterForValidation() { |
27
|
|
|
|
28
|
|
|
$dataValue = $this->getMockBuilder( '\SMWDataValue' ) |
29
|
|
|
->disableOriginalConstructor() |
30
|
|
|
->getMockForAbstractClass(); |
31
|
|
|
|
32
|
|
|
$instance = new NoValueFormatter(); |
33
|
|
|
|
34
|
|
|
$this->assertTrue( |
35
|
|
|
$instance->isFormatterFor( $dataValue ) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testFormat() { |
40
|
|
|
|
41
|
|
|
$dataItem = $this->getMockBuilder( '\SMWDataItem' ) |
42
|
|
|
->disableOriginalConstructor() |
43
|
|
|
->setMethods( array( 'getSerialization' ) ) |
44
|
|
|
->getMockForAbstractClass(); |
45
|
|
|
|
46
|
|
|
$dataItem->expects( $this->once() ) |
47
|
|
|
->method( 'getSerialization' ) |
48
|
|
|
->will( $this->returnValue( 'isFromSerializationMethod' ) ); |
49
|
|
|
|
50
|
|
|
$dataValue = $this->getMockBuilder( '\SMWDataValue' ) |
51
|
|
|
->disableOriginalConstructor() |
52
|
|
|
->setMethods( array( 'isValid', 'getDataItem' ) ) |
53
|
|
|
->getMockForAbstractClass(); |
54
|
|
|
|
55
|
|
|
$dataValue->expects( $this->any() ) |
56
|
|
|
->method( 'isValid' ) |
57
|
|
|
->will( $this->returnValue( true ) ); |
58
|
|
|
|
59
|
|
|
$dataValue->expects( $this->once() ) |
60
|
|
|
->method( 'getDataItem' ) |
61
|
|
|
->will( $this->returnValue( $dataItem ) ); |
62
|
|
|
|
63
|
|
|
$instance = new NoValueFormatter( $dataValue ); |
64
|
|
|
|
65
|
|
|
$this->assertEquals( |
66
|
|
|
'isFromSerializationMethod', |
67
|
|
|
$instance->format( NoValueFormatter::VALUE ) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testTryToFormatOnMissingDataValueThrowsException() { |
72
|
|
|
|
73
|
|
|
$instance = new NoValueFormatter(); |
74
|
|
|
|
75
|
|
|
$this->setExpectedException( 'RuntimeException' ); |
76
|
|
|
$instance->format( NoValueFormatter::VALUE ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|