|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SBL\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SBL\PageDisplayOutputModifier; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @covers \SBL\PageDisplayOutputModifier |
|
9
|
|
|
* @group semantic-breadcrumb-links |
|
10
|
|
|
* |
|
11
|
|
|
* @license GNU GPL v2+ |
|
12
|
|
|
* @since 1.0 |
|
13
|
|
|
* |
|
14
|
|
|
* @author mwjames |
|
15
|
|
|
*/ |
|
16
|
|
|
class PageDisplayOutputModifierTest extends \PHPUnit_Framework_TestCase { |
|
17
|
|
|
|
|
18
|
|
|
public function testCanConstruct() { |
|
19
|
|
|
|
|
20
|
|
|
$this->assertInstanceOf( |
|
21
|
|
|
'\SBL\PageDisplayOutputModifier', |
|
22
|
|
|
new PageDisplayOutputModifier() |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testDisabledHideSubpageParentForTitleManipulation() { |
|
27
|
|
|
|
|
28
|
|
|
$instance = new PageDisplayOutputModifier(); |
|
29
|
|
|
$instance->hideSubpageParent( false ); |
|
30
|
|
|
$instance->setSubpageByNamespace( [ NS_MAIN => true ] ); |
|
31
|
|
|
|
|
32
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
|
33
|
|
|
->disableOriginalConstructor() |
|
34
|
|
|
->getMock(); |
|
35
|
|
|
|
|
36
|
|
|
$output->expects( $this->atLeastOnce() ) |
|
37
|
|
|
->method( 'getTitle' ); |
|
38
|
|
|
|
|
39
|
|
|
$instance->modifyOutput( $output ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testDisabledSubpageNamespaceForTitleManipulation() { |
|
43
|
|
|
|
|
44
|
|
|
$instance = new PageDisplayOutputModifier(); |
|
45
|
|
|
$instance->hideSubpageParent( true ); |
|
46
|
|
|
$instance->setSubpageByNamespace( [ NS_MAIN => false ] ); |
|
47
|
|
|
|
|
48
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
|
49
|
|
|
->disableOriginalConstructor() |
|
50
|
|
|
->getMock(); |
|
51
|
|
|
|
|
52
|
|
|
$title->expects( $this->once() ) |
|
53
|
|
|
->method( 'getNamespace' ) |
|
54
|
|
|
->will( $this->returnValue( NS_MAIN ) ); |
|
55
|
|
|
|
|
56
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
|
57
|
|
|
->disableOriginalConstructor() |
|
58
|
|
|
->getMock(); |
|
59
|
|
|
|
|
60
|
|
|
$output->expects( $this->atLeastOnce() ) |
|
61
|
|
|
->method( 'getTitle' ) |
|
62
|
|
|
->will( $this->returnValue( $title ) ); |
|
63
|
|
|
|
|
64
|
|
|
$instance->modifyOutput( $output ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testEnabledSubpageForTitleManipulation() { |
|
68
|
|
|
|
|
69
|
|
|
$instance = new PageDisplayOutputModifier(); |
|
70
|
|
|
$instance->hideSubpageParent( true ); |
|
71
|
|
|
$instance->setSubpageByNamespace( [ NS_MAIN => true ] ); |
|
72
|
|
|
|
|
73
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
|
74
|
|
|
->disableOriginalConstructor() |
|
75
|
|
|
->getMock(); |
|
76
|
|
|
|
|
77
|
|
|
$title->expects( $this->once() ) |
|
78
|
|
|
->method( 'isSubpage' ) |
|
79
|
|
|
->will( $this->returnValue( true ) ); |
|
80
|
|
|
|
|
81
|
|
|
$title->expects( $this->atLeastOnce() ) |
|
82
|
|
|
->method( 'getNamespace' ) |
|
83
|
|
|
->will( $this->returnValue( NS_MAIN ) ); |
|
84
|
|
|
|
|
85
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
|
86
|
|
|
->disableOriginalConstructor() |
|
87
|
|
|
->getMock(); |
|
88
|
|
|
|
|
89
|
|
|
$output->expects( $this->atLeastOnce() ) |
|
90
|
|
|
->method( 'getTitle' ) |
|
91
|
|
|
->will( $this->returnValue( $title ) ); |
|
92
|
|
|
|
|
93
|
|
|
$output->expects( $this->once() ) |
|
94
|
|
|
->method( 'setPageTitle' ); |
|
95
|
|
|
|
|
96
|
|
|
$instance->modifyOutput( $output ); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testEnabledSubpageForTitleManipulationOnInvalidSubpage() { |
|
100
|
|
|
|
|
101
|
|
|
$instance = new PageDisplayOutputModifier(); |
|
102
|
|
|
$instance->hideSubpageParent( true ); |
|
103
|
|
|
$instance->setSubpageByNamespace( [ NS_MAIN => true ] ); |
|
104
|
|
|
|
|
105
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
|
106
|
|
|
->disableOriginalConstructor() |
|
107
|
|
|
->getMock(); |
|
108
|
|
|
|
|
109
|
|
|
$title->expects( $this->once() ) |
|
110
|
|
|
->method( 'isSubpage' ) |
|
111
|
|
|
->will( $this->returnValue( true ) ); |
|
112
|
|
|
|
|
113
|
|
|
$title->expects( $this->once() ) |
|
114
|
|
|
->method( 'getText' ) |
|
115
|
|
|
->will( $this->returnValue( 'Foo /Bar' ) ); |
|
116
|
|
|
|
|
117
|
|
|
$title->expects( $this->atLeastOnce() ) |
|
118
|
|
|
->method( 'getNamespace' ) |
|
119
|
|
|
->will( $this->returnValue( NS_MAIN ) ); |
|
120
|
|
|
|
|
121
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
|
122
|
|
|
->disableOriginalConstructor() |
|
123
|
|
|
->getMock(); |
|
124
|
|
|
|
|
125
|
|
|
$output->expects( $this->atLeastOnce() ) |
|
126
|
|
|
->method( 'getTitle' ) |
|
127
|
|
|
->will( $this->returnValue( $title ) ); |
|
128
|
|
|
|
|
129
|
|
|
$output->expects( $this->never() ) |
|
130
|
|
|
->method( 'setPageTitle' ); |
|
131
|
|
|
|
|
132
|
|
|
$instance->modifyOutput( $output ); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
|