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

CachedReferenceListOutputRendererTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 128
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SCI\Tests;
4
5
use SCI\CachedReferenceListOutputRenderer;
6
7
/**
8
 * @covers \SCI\CachedReferenceListOutputRenderer
9
 * @group semantic-cite
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class CachedReferenceListOutputRendererTest extends \PHPUnit_Framework_TestCase {
17
18
	private $referenceListOutputRenderer;
19
	private $contextInteractor;
20
	private $namespaceExaminer;
21
	private $cache;
22
	private $cacheKeyProvider;
23
24
	protected function setUp() : void {
25
26
		$this->referenceListOutputRenderer = $this->getMockBuilder( '\SCI\ReferenceListOutputRenderer' )
27
			->disableOriginalConstructor()
28
			->getMock();
29
30
		$this->contextInteractor = $this->getMockBuilder( '\SCI\MediaWikiContextInteractor' )
31
			->disableOriginalConstructor()
32
			->getMock();
33
34
		$this->namespaceExaminer = $this->getMockBuilder( '\SMW\NamespaceExaminer' )
35
			->disableOriginalConstructor()
36
			->getMock();
37
38
		$this->cache = $this->getMockBuilder( '\Onoi\Cache\Cache' )
39
			->disableOriginalConstructor()
40
			->getMock();
41
42
		$this->cacheKeyProvider = $this->getMockBuilder( '\SCI\CacheKeyProvider' )
43
			->disableOriginalConstructor()
44
			->getMock();
45
	}
46
47
	public function testCanConstruct() {
48
49
		$this->assertInstanceOf(
50
			'\SCI\CachedReferenceListOutputRenderer',
51
			new CachedReferenceListOutputRenderer(
52
				$this->referenceListOutputRenderer,
53
				$this->contextInteractor,
54
				$this->namespaceExaminer,
55
				$this->cache,
56
				$this->cacheKeyProvider
57
			)
58
		);
59
	}
60
61
	public function testUnmodifiedTextForNotEnabledSemanticNamespace() {
62
63
		$this->contextInteractor->expects( $this->once() )
64
			->method( 'getTitle' )
65
			->will( $this->returnValue( \Title::newFromText( __METHOD__ ) ) );
66
67
		$this->contextInteractor->expects( $this->once() )
68
			->method( 'hasAction' )
69
			->will( $this->returnValue( true ) );
70
71
		$this->namespaceExaminer->expects( $this->once() )
72
			->method( 'isSemanticEnabled' )
73
			->will( $this->returnValue( false ) );
74
75
		$instance =	new CachedReferenceListOutputRenderer(
76
			$this->referenceListOutputRenderer,
77
			$this->contextInteractor,
78
			$this->namespaceExaminer,
79
			$this->cache,
80
			$this->cacheKeyProvider
81
		);
82
83
		$text = '';
84
		$instance->addReferenceListToText( $text );
85
86
		$this->assertEmpty(
87
			$text
88
		);
89
	}
90
91
	public function testRemovalOfPlaceholderForDisabledReferencelist() {
92
93
		$this->contextInteractor->expects( $this->once() )
94
			->method( 'hasMagicWord' )
95
			->with( $this->equalTo( 'SCI_NOREFERENCELIST' ) )
96
			->will( $this->returnValue( true ) );
97
98
		$instance =	new CachedReferenceListOutputRenderer(
99
			$this->referenceListOutputRenderer,
100
			$this->contextInteractor,
101
			$this->namespaceExaminer,
102
			$this->cache,
103
			$this->cacheKeyProvider
104
		);
105
106
		$text = '<div id="scite-custom-referencelist"><span></span></div>';
107
		$instance->addReferenceListToText( $text );
108
109
		$this->assertEmpty(
110
			$text
111
		);
112
	}
113
114
	public function testNoAutoReferencelistOnFileNamespace() {
115
116
		$this->contextInteractor->expects( $this->atLeastOnce() )
117
			->method( 'getTitle' )
118
			->will( $this->returnValue( \Title::newFromText( __METHOD__, NS_FILE ) ) );
119
120
		$this->contextInteractor->expects( $this->once() )
121
			->method( 'hasAction' )
122
			->will( $this->returnValue( true ) );
123
124
		$this->contextInteractor->expects( $this->never() )
125
			->method( 'getOldId' );
126
127
		$this->namespaceExaminer->expects( $this->once() )
128
			->method( 'isSemanticEnabled' )
129
			->will( $this->returnValue( true ) );
130
131
		$instance =	new CachedReferenceListOutputRenderer(
132
			$this->referenceListOutputRenderer,
133
			$this->contextInteractor,
134
			$this->namespaceExaminer,
135
			$this->cache,
136
			$this->cacheKeyProvider
137
		);
138
139
		$text = '';
140
		$instance->addReferenceListToText( $text );
141
	}
142
143
}
144