1 | <?php |
||
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 | } |
||
114 |