Passed
Pull Request — master (#136)
by None
04:56 queued 51s
created

MediaWikiContextInteractorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 94
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SCI\Tests;
4
5
use SCI\MediaWikiContextInteractor;
6
use SMW\Tests\PHPUnitCompat;
7
8
/**
9
 * @covers \SCI\MediaWikiContextInteractor
10
 * @group semantic-cite
11
 *
12
 * @license GNU GPL v2+
13
 * @since   1.0
14
 *
15
 * @author mwjames
16
 * @reviewer thomas-topway-it
17
 */
18
class MediaWikiContextInteractorTest extends \PHPUnit_Framework_TestCase {
19
20
	use PHPUnitCompat;
21
22
	public function testCanConstruct() {
23
24
		$context = $this->getMockBuilder( '\IContextSource' )
25
			->disableOriginalConstructor()
26
			->getMock();
27
28
		$this->assertInstanceOf(
29
			'\SCI\MediaWikiContextInteractor',
30
			new MediaWikiContextInteractor( $context )
31
		);
32
	}
33
34
	public function testHasAction() {
35
36
		$context = $this->getMockBuilder( '\IContextSource' )
37
			->disableOriginalConstructor()
38
			->getMock();
39
40
		$webRequest = $this->getMockBuilder( '\WebRequest' )
41
			->disableOriginalConstructor()
42
			->getMock();
43
44
		// replaced $this->once() with $this->any(), is that correct ?
45
		$webRequest->expects( $this->any() )
46
			->method( 'getVal' )
47
			->will( $this->returnValue( 'view' ) );
48
49
		// replaced $this->once() with $this->any(), is that correct ?
50
		$context->expects( $this->any() )
51
			->method( 'getRequest' )
52
			->will( $this->returnValue( $webRequest ) );
53
54
		$instance = new MediaWikiContextInteractor( $context );
55
56
		$this->assertTrue(
57
			$instance->hasAction( 'view' )
58
		);
59
	}
60
61
	/**
62
	 * @dataProvider oldidDirectionProvider
63
	 */
64
	public function testGetOldId( $direction ) {
65
66
		$context = $this->getMockBuilder( '\IContextSource' )
67
			->disableOriginalConstructor()
68
			->getMock();
69
70
		$webRequest = $this->getMockBuilder( '\WebRequest' )
71
			->disableOriginalConstructor()
72
			->getMock();
73
74
		$webRequest->expects( $this->any() )
75
			->method( 'getText' )
76
			->will( $this->returnValue( $direction ) );
77
78
		$context->expects( $this->any() )
79
			->method( 'getRequest' )
80
			->will( $this->returnValue( $webRequest ) );
81
82
		$context->expects( $this->any() )
83
			->method( 'getTitle' )
84
			->will( $this->returnValue( \Title::newFromText( __METHOD__ ) ) );
85
86
		$instance = new MediaWikiContextInteractor( $context );
87
88
		$this->assertInternalType(
89
			'integer',
90
			$instance->getOldId()
91
		);
92
	}
93
94
	public function oldidDirectionProvider() {
95
96
		$provider = [];
97
98
		$provider[] = [
99
			'next'
100
		];
101
102
		$provider[] = [
103
			'prev'
104
		];
105
106
		$provider[] = [
107
			'cur'
108
		];
109
110
		return $provider;
111
	}
112
113
}
114