1 | <?php |
||
19 | class ParserFunctionFactoryTest extends \PHPUnit_Framework_TestCase { |
||
20 | |||
21 | private $parser; |
||
22 | |||
23 | protected function setUp() : void { |
||
24 | parent::setUp(); |
||
25 | |||
26 | $title = $this->getMockBuilder( '\Title' ) |
||
27 | ->disableOriginalConstructor() |
||
28 | ->getMock(); |
||
29 | |||
30 | $title->expects( $this->any() ) |
||
31 | ->method( 'getNamespace' ) |
||
32 | ->will( $this->returnValue( NS_MAIN ) ); |
||
33 | |||
34 | $parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
||
35 | ->disableOriginalConstructor() |
||
36 | ->getMock(); |
||
37 | |||
38 | $this->parser = $this->getMockBuilder( '\Parser' ) |
||
39 | ->disableOriginalConstructor() |
||
40 | ->getMock(); |
||
41 | |||
42 | $this->parser->expects( $this->any() ) |
||
43 | ->method( 'getTitle' ) |
||
44 | ->will( $this->returnValue( $title ) ); |
||
45 | |||
46 | $this->parser->expects( $this->any() ) |
||
47 | ->method( 'getOutput' ) |
||
48 | ->will( $this->returnValue( $parserOutput ) ); |
||
49 | } |
||
50 | |||
51 | public function testCanConstruct() { |
||
52 | |||
53 | $this->assertInstanceOf( |
||
54 | '\SCI\ParserFunctionFactory', |
||
55 | new ParserFunctionFactory() |
||
56 | ); |
||
57 | } |
||
58 | |||
59 | public function testNewSciteParserFunctionDefinition() { |
||
60 | |||
61 | $this->parser->setTitle( Title::newFromText( __METHOD__ ) ); |
||
62 | |||
63 | $instance = new ParserFunctionFactory(); |
||
64 | |||
65 | $namespaceExaminer = $this->getMockBuilder( '\SMW\NamespaceExaminer' ) |
||
66 | ->disableOriginalConstructor() |
||
67 | ->getMock(); |
||
68 | |||
69 | $options = $this->getMockBuilder( '\SCI\Options' ) |
||
70 | ->disableOriginalConstructor() |
||
71 | ->getMock(); |
||
72 | |||
73 | list( $name, $definition, $flag ) = $instance->newSciteParserFunctionDefinition( |
||
74 | $namespaceExaminer, |
||
75 | $options |
||
76 | ); |
||
77 | |||
78 | $this->assertEquals( |
||
79 | 'scite', |
||
80 | $name |
||
81 | ); |
||
82 | |||
83 | $this->assertInstanceOf( |
||
84 | '\Closure', |
||
85 | $definition |
||
86 | ); |
||
87 | |||
88 | $text = ''; |
||
89 | |||
90 | $this->assertNotEmpty( |
||
91 | call_user_func_array( $definition, [ $this->parser, $text ] ) |
||
92 | ); |
||
93 | } |
||
94 | |||
95 | public function textNewReferenceListParserFunctionDefinition() { |
||
96 | |||
97 | $this->parser->setTitle( Title::newFromText( __METHOD__ ) ); |
||
98 | |||
99 | $instance = new ParserFunctionFactory(); |
||
100 | |||
101 | list( $name, $definition, $flag ) = $instance->newReferenceListParserFunctionDefinition(); |
||
102 | |||
103 | $this->assertEquals( |
||
104 | 'referencelist', |
||
105 | $name |
||
106 | ); |
||
107 | |||
108 | $this->assertInstanceOf( |
||
109 | '\Closure', |
||
110 | $definition |
||
111 | ); |
||
112 | |||
113 | $text = ''; |
||
114 | |||
115 | $this->assertNotEmpty( |
||
116 | call_user_func_array( $definition, [ $this->parser, $text ] ) |
||
117 | ); |
||
118 | } |
||
119 | |||
120 | } |
||
121 |