blob: 75acd18c8899800f4b519472f4f0904994a2402c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
<?php
namespace SMW\Tests\MediaWiki\Hooks;
use SMW\Tests\Util\Mock\MockTitle;
use SMW\MediaWiki\Hooks\BeforePageDisplay;
use OutputPage;
use Language;
/**
* @covers \SMW\MediaWiki\Hooks\BeforePageDisplay
*
* @ingroup Test
*
* @group SMW
* @group SMWExtension
*
* @license GNU GPL v2+
* @since 1.9
*
* @author mwjames
*/
class BeforePageDisplayTest extends \PHPUnit_Framework_TestCase {
public function testCanConstruct() {
$outputPage = $this->getMockBuilder( '\OutputPage' )
->disableOriginalConstructor()
->getMock();
$skin = $this->getMockBuilder( '\Skin' )
->disableOriginalConstructor()
->getMock();
$this->assertInstanceOf(
'\SMW\MediaWiki\Hooks\BeforePageDisplay',
new BeforePageDisplay( $outputPage, $skin )
);
}
/**
* @dataProvider titleDataProvider
*/
public function testProcess( $setup, $expected ) {
$skin = $this->getMockBuilder( '\Skin' )
->disableOriginalConstructor()
->getMock();
$context = new \RequestContext();
$context->setTitle( $setup['title'] );
$context->setLanguage( Language::factory( 'en' ) );
$outputPage = new OutputPage( $context );
$instance = new BeforePageDisplay( $outputPage, $skin );
$result = $instance->process();
$this->assertInternalType( 'boolean', $result );
$this->assertTrue( $result );
$contains = false;
if ( method_exists( $outputPage, 'getHeadLinksArray' ) ) {
foreach ( $outputPage->getHeadLinksArray() as $key => $value ) {
if ( strpos( $value, 'ExportRDF' ) ){
$contains = true;
break;
};
}
} else{
// MW 1.19
if ( strpos( $outputPage->getHeadLinks(), 'ExportRDF' ) ){
$contains = true;
};
}
$expected['result'] ? $this->assertTrue( $contains ) : $this->assertFalse( $contains );
}
public function titleDataProvider() {
$language = Language::factory( 'en' );
#0 Standard title
$title = MockTitle::buildMockForMainNamespace();
$title->expects( $this->atLeastOnce() )
->method( 'getPrefixedText' )
->will( $this->returnValue( 'Foo' ) );
$title->expects( $this->atLeastOnce() )
->method( 'isSpecialPage' )
->will( $this->returnValue( false ) );
$title->expects( $this->atLeastOnce() )
->method( 'getPageLanguage' )
->will( $this->returnValue( $language ) );
$provider[] = array(
array(
'title' => $title
),
array(
'result' => true
)
);
#1 as SpecialPage
$title = MockTitle::buildMock();
$title->expects( $this->atLeastOnce() )
->method( 'isSpecialPage' )
->will( $this->returnValue( true ) );
$title->expects( $this->atLeastOnce() )
->method( 'getPageLanguage' )
->will( $this->returnValue( $language ) );
$provider[] = array(
array(
'title' => $title
),
array(
'result' => false
)
);
return $provider;
}
}
|