1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Scribunto\Tests; |
4
|
|
|
|
5
|
|
|
use SMW\Scribunto\LibraryFactory; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \SMW\Scribunto\LibraryFactory |
9
|
|
|
* @group semantic-scribunto |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 1.0 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class LibraryFactoryTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
private $store; |
19
|
|
|
private $parser; |
20
|
|
|
|
21
|
|
|
protected function setUp() { |
22
|
|
|
|
23
|
|
|
$language = $this->getMockBuilder( '\Language' ) |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
|
27
|
|
|
$queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
28
|
|
|
->disableOriginalConstructor() |
29
|
|
|
->getMockForAbstractClass(); |
30
|
|
|
|
31
|
|
|
$this->store = $this->getMockBuilder( '\SMW\Store' ) |
32
|
|
|
->disableOriginalConstructor() |
33
|
|
|
->getMockForAbstractClass(); |
34
|
|
|
|
35
|
|
|
$this->store->expects( $this->any() ) |
36
|
|
|
->method( 'getQueryResult' ) |
37
|
|
|
->will( $this->returnValue( $queryResult ) ); |
38
|
|
|
|
39
|
|
|
$this->parser = $this->getMockBuilder( '\Parser' ) |
40
|
|
|
->disableOriginalConstructor() |
41
|
|
|
->getMock(); |
42
|
|
|
|
43
|
|
|
$this->parser->expects( $this->any() ) |
44
|
|
|
->method( 'getTitle' ) |
45
|
|
|
->will( $this->returnValue( \Title::newFromText( 'Foo' ) ) ); |
46
|
|
|
|
47
|
|
|
$this->parser->expects( $this->any() ) |
48
|
|
|
->method( 'getOutput' ) |
49
|
|
|
->will( $this->returnValue( new \ParserOutput() ) ); |
50
|
|
|
|
51
|
|
|
$this->parser->expects( $this->any() ) |
52
|
|
|
->method( 'getTargetLanguage' ) |
53
|
|
|
->will( $this->returnValue( $language ) ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testCanConstruct() { |
57
|
|
|
|
58
|
|
|
$this->assertInstanceOf( |
59
|
|
|
'\SMW\Scribunto\LibraryFactory', |
60
|
|
|
new LibraryFactory( $this->store ) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testCanConstructQueryResult() { |
65
|
|
|
|
66
|
|
|
$instance = new LibraryFactory( |
67
|
|
|
$this->store |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$this->assertInstanceOf( |
71
|
|
|
'\SMWQueryResult', |
72
|
|
|
$instance->newQueryResultFrom( array( '[[Foo::Bar]]' ) ) |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testCanConstructParserParameterProcessor() { |
77
|
|
|
|
78
|
|
|
$instance = new LibraryFactory( |
79
|
|
|
$this->store |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$this->assertInstanceOf( |
83
|
|
|
'\SMW\ParserParameterProcessor', |
84
|
|
|
$instance->newParserParameterProcessorFrom( array( '' ) ) |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testCanConstructSetParserFunction() { |
89
|
|
|
|
90
|
|
|
$instance = new LibraryFactory( |
91
|
|
|
$this->store |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$this->assertInstanceOf( |
95
|
|
|
'\SMW\SetParserFunction', |
96
|
|
|
$instance->newSetParserFunction( $this->parser ) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testCanConstructSubobjectParserFunction() { |
101
|
|
|
|
102
|
|
|
$instance = new LibraryFactory( |
103
|
|
|
$this->store |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$this->assertInstanceOf( |
107
|
|
|
'\SMW\SubobjectParserFunction', |
108
|
|
|
$instance->newSubobjectParserFunction( $this->parser ) |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|