1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
<?php
namespace SMW\Tests\SPARQLStore\QueryEngine;
use SMW\SPARQLStore\QueryEngine\RepositoryResult;
use SMWExpLiteral as ExpLiteral;
/**
* @covers \SMW\SPARQLStore\QueryEngine\RepositoryResult
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 2.0
*
* @author mwjames
*/
class RepositoryResultTest extends \PHPUnit_Framework_TestCase {
public function testCanConstruct() {
$this->assertInstanceOf(
'\SMW\SPARQLStore\QueryEngine\RepositoryResult',
new RepositoryResult()
);
$this->assertInstanceOf(
'\Iterator',
new RepositoryResult()
);
}
public function testIsBooleanTrue() {
$instance = new RepositoryResult(
[],
[ [ new ExpLiteral( 'true', 'http://www.w3.org/2001/XMLSchema#boolean' ) ] ]
);
$this->assertEquals( 1, $instance->numRows() );
$this->assertTrue( $instance->isBooleanTrue() );
}
public function testIsBooleanNotTrue() {
$instance = new RepositoryResult();
$this->assertFalse(
$instance->isBooleanTrue()
);
}
public function testGetNumericValue() {
$instance = new RepositoryResult(
[],
[ [ new ExpLiteral( '2', 'http://www.w3.org/2001/XMLSchema#integer' ) ] ]
);
$this->assertEquals( 1, $instance->numRows() );
$this->assertSame( 2, $instance->getNumericValue() );
}
public function testGetZeroNumericValue() {
$instance = new RepositoryResult();
$this->assertSame(
0,
$instance->getNumericValue()
);
}
public function testSetGetErrorCode() {
$instance = new RepositoryResult();
$this->assertEquals(
RepositoryResult::ERROR_NOERROR,
$instance->getErrorCode()
);
$instance->setErrorCode(
RepositoryResult::ERROR_INCOMPLETE
);
$this->assertEquals(
RepositoryResult::ERROR_INCOMPLETE,
$instance->getErrorCode()
);
}
public function testIteration() {
$rawList = [
[
new ExpLiteral( '2', 'http://www.w3.org/2001/XMLSchema#integer' ),
new ExpLiteral( 'true', 'http://www.w3.org/2001/XMLSchema#boolean' )
],
[
new ExpLiteral( '2', 'http://www.w3.org/2001/XMLSchema#integer' )
]
];
$instance = new RepositoryResult(
[],
[ $rawList[0], $rawList[1] ]
);
foreach ( $instance as $key => $listItem ) {
$this->assertEquals( $rawList[$key], $listItem );
}
}
public function testGetComments() {
$instance = new RepositoryResult(
[],
[],
[ 'Foo' ]
);
$this->assertContains(
'Foo',
$instance->getComments()
);
}
}
|