Passed
Pull Request — master (#136)
by None
03:40
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
		$context->expects( $this->any() )
41
			->method( 'getActionName' )
42
			->willReturn( 'view');
43
44
		$instance = new MediaWikiContextInteractor( $context );
45
46
		$this->assertTrue(
47
			$instance->hasAction( 'view' )
48
		);
49
	}
50
51
	/**
52
	 * @dataProvider oldidDirectionProvider
53
	 */
54
	public function testGetOldId( $direction ) {
55
56
		$context = $this->getMockBuilder( '\IContextSource' )
57
			->disableOriginalConstructor()
58
			->getMock();
59
60
		$webRequest = $this->getMockBuilder( '\WebRequest' )
61
			->disableOriginalConstructor()
62
			->getMock();
63
64
		$webRequest->expects( $this->any() )
65
			->method( 'getText' )
66
			->will( $this->returnValue( $direction ) );
67
68
		$context->expects( $this->any() )
69
			->method( 'getRequest' )
70
			->will( $this->returnValue( $webRequest ) );
71
72
		$context->expects( $this->any() )
73
			->method( 'getTitle' )
74
			->will( $this->returnValue( \Title::newFromText( __METHOD__ ) ) );
75
76
		$instance = new MediaWikiContextInteractor( $context );
77
78
		$this->assertInternalType(
79
			'integer',
80
			$instance->getOldId()
81
		);
82
	}
83
84
	public function oldidDirectionProvider() {
85
86
		$provider = [];
87
88
		$provider[] = [
89
			'next'
90
		];
91
92
		$provider[] = [
93
			'prev'
94
		];
95
96
		$provider[] = [
97
			'cur'
98
		];
99
100
		return $provider;
101
	}
102
103
}
104