1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests; |
4
|
|
|
|
5
|
|
|
use SMW\Tests\Utils\UtilityFactory; |
6
|
|
|
use SMW\Error; |
7
|
|
|
use SMW\DIWikiPage; |
8
|
|
|
use SMW\DIProperty; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \SMW\Error |
12
|
|
|
* @group semantic-mediawiki |
13
|
|
|
* |
14
|
|
|
* @license GNU GPL v2+ |
15
|
|
|
* @since 2.4 |
16
|
|
|
* |
17
|
|
|
* @author mwjames |
18
|
|
|
*/ |
19
|
|
|
class ErrorTest extends \PHPUnit_Framework_TestCase { |
20
|
|
|
|
21
|
|
|
private $semanticDataValidator; |
22
|
|
|
|
23
|
|
|
protected function setUp() { |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
$this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testCanConstruct() { |
30
|
|
|
|
31
|
|
|
$subject = $this->getMockBuilder( '\SMW\DIWikiPage' ) |
32
|
|
|
->disableOriginalConstructor() |
33
|
|
|
->getMock(); |
34
|
|
|
|
35
|
|
|
$this->assertInstanceOf( |
36
|
|
|
'\SMW\Error', |
37
|
|
|
new Error( $subject ) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testErrorContainer() { |
42
|
|
|
|
43
|
|
|
$instance = new Error( DIWikiPage::newFromText( 'Foo' ) ); |
44
|
|
|
|
45
|
|
|
$this->assertEquals( |
46
|
|
|
new DIProperty( '_ERRC' ), |
47
|
|
|
$instance->getProperty() |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$container = $instance->getContainerFor( new DIProperty( 'Foo' ), 'Some error' ); |
51
|
|
|
|
52
|
|
|
$expected = array( |
53
|
|
|
'propertyCount' => 2, |
54
|
|
|
'propertyKeys' => array( '_ERRP', '_ERRT' ), |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$this->semanticDataValidator->assertThatPropertiesAreSet( |
58
|
|
|
$expected, |
59
|
|
|
$container->getSemanticData() |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testErrorContainerForNullProperty() { |
64
|
|
|
|
65
|
|
|
$instance = new Error( DIWikiPage::newFromText( 'Foo' ) ); |
66
|
|
|
|
67
|
|
|
$this->assertEquals( |
68
|
|
|
new DIProperty( '_ERRC' ), |
69
|
|
|
$instance->getProperty() |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$container = $instance->getContainerFor( null, 'Some error' ); |
73
|
|
|
|
74
|
|
|
$expected = array( |
75
|
|
|
'propertyCount' => 1, |
76
|
|
|
'propertyKeys' => array( '_ERRT' ), |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$this->semanticDataValidator->assertThatPropertiesAreSet( |
80
|
|
|
$expected, |
81
|
|
|
$container->getSemanticData() |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testErrorContainerForInverseProperty() { |
86
|
|
|
|
87
|
|
|
$instance = new Error( DIWikiPage::newFromText( 'Foo' ) ); |
88
|
|
|
|
89
|
|
|
$this->assertEquals( |
90
|
|
|
new DIProperty( '_ERRC' ), |
91
|
|
|
$instance->getProperty() |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$container = $instance->getContainerFor( new DIProperty( 'Foo', true ), array( 'Some error' ) ); |
95
|
|
|
|
96
|
|
|
$expected = array( |
97
|
|
|
'propertyCount' => 2, |
98
|
|
|
'propertyKeys' => array( '_ERRP', '_ERRT' ), |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$this->semanticDataValidator->assertThatPropertiesAreSet( |
102
|
|
|
$expected, |
103
|
|
|
$container->getSemanticData() |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testErrorContainerForSamePropertyAndMsg() { |
108
|
|
|
|
109
|
|
|
$instance = new Error( DIWikiPage::newFromText( 'Foo' ) ); |
110
|
|
|
$property = new DIProperty( 'Foo' ); |
111
|
|
|
|
112
|
|
|
$container = $instance->getContainerFor( |
113
|
|
|
$property, |
114
|
|
|
array( 'Some error' ) |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
$this->assertSame( |
118
|
|
|
$container->getHash(), |
119
|
|
|
$instance->getContainerFor( $property, array( 'Some error' ) )->getHash() |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testErrorContainerForSamePropertyButDifferentMsg() { |
124
|
|
|
|
125
|
|
|
$instance = new Error( DIWikiPage::newFromText( 'Foo' ) ); |
126
|
|
|
$property = new DIProperty( 'Foo' ); |
127
|
|
|
|
128
|
|
|
$container = $instance->getContainerFor( |
129
|
|
|
$property, |
130
|
|
|
array( 'Some error' ) |
131
|
|
|
); |
132
|
|
|
|
133
|
|
|
$this->assertNotSame( |
134
|
|
|
$container->getHash(), |
135
|
|
|
$instance->getContainerFor( $property, array( 'Different error' ) )->getHash() |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|