Passed
Pull Request — master (#136)
by None
04:09
created

ParserFunctionFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 102
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SCI\Tests;
4
5
use SCI\ParserFunctionFactory;
6
use Title;
7
use Parser;
8
use ParserOptions;
9
10
/**
11
 * @covers \SCI\ParserFunctionFactory
12
 * @group semantic-cite
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author mwjames
18
 */
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