@@ -102,55 +102,6 @@ public function testOnHtmlPageLinkRendererBeginTitlesMatch() {
102
102
$ this ->assertSame ( $ text , $ mockTitle ->getPrefixedText () );
103
103
}
104
104
105
- /**
106
- * @covers HidePrefix::onBeforePageDisplay
107
- */
108
- public function testOnBeforePageDisplay () {
109
- // Create mock OutputPage and Skin objects
110
- $ outMock = $ this ->getMockBuilder ( 'OutputPage ' )
111
- ->disableOriginalConstructor ()
112
- ->getMock ();
113
-
114
- // Create mock Skin object
115
- $ skMock = $ this ->getMockBuilder ( 'Skin ' )
116
- ->disableOriginalConstructor ()
117
- ->getMock ();
118
-
119
- // Example page title with prefix
120
- $ pageTitleWithPrefix = 'Prefix:Example_Title ' ;
121
- $ pageTitleWithoutPrefix = 'Example_Title ' ;
122
-
123
- // Create a mock Title object
124
- $ titleMock = $ this ->createMock ( Title::class );
125
- $ titleMock ->method ( 'getPrefixedText ' )->willReturn ( $ pageTitleWithPrefix );
126
- $ titleMock ->method ( 'getText ' )->willReturn ( $ pageTitleWithoutPrefix );
127
-
128
- $ outMock ->expects ( $ this ->any () )
129
- ->method ( 'getTitle ' )
130
- ->willReturn ( $ titleMock );
131
-
132
- $ title = $ outMock ->getTitle ();
133
-
134
- $ outMock ->expects ( $ this ->any () )
135
- ->method ( 'getPageTitle ' )
136
- ->willReturn ( $ pageTitleWithPrefix );
137
-
138
- // Assert that pageTitle is with prefix
139
- $ this ->assertSame ( $ title ->getPrefixedText (), $ outMock ->getPageTitle () );
140
-
141
- $ outMock ->expects ( $ this ->any () )
142
- ->method ( 'setPageTitle ' )
143
- ->willReturn ( $ pageTitleWithoutPrefix );
144
- $ pageTitle = $ outMock ->setPageTitle ( $ pageTitleWithoutPrefix );
145
-
146
- // Get the full title with prefix and split it
147
- $ titleWithPrefix = $ title ->getPrefixedText ();
148
- $ titleWithoutPrefix = explode ( ': ' , $ titleWithPrefix , 2 );
149
-
150
- // Assert that pageTitle is without prefix
151
- $ this ->assertSame ( $ titleWithoutPrefix [1 ], $ pageTitle );
152
- }
153
-
154
105
/**
155
106
* @covers HidePrefix::onBeforePageDisplay
156
107
*/
@@ -179,4 +130,39 @@ public function testOnBeforePageDisplayWhenTitleIsMissing() {
179
130
180
131
$ this ->assertSame ( $ title ->getPrefixedText (), $ outMock ->getPageTitle () );
181
132
}
133
+
134
+ public function newHooksInstance () {
135
+ return new Hooks (
136
+ $ this ->getServiceContainer ()->getMainConfig (),
137
+ $ this ->getServiceContainer ()->getSpecialPageFactory (),
138
+ $ this ->getServiceContainer ()->getUserOptionsLookup (),
139
+ null
140
+ );
141
+ }
142
+
143
+ public static function provideOnBeforePageDisplay () {
144
+ return [
145
+ 'no prefix ' => [ 'Main Page ' , 'Main Page ' , 'Main Page ' ],
146
+ 'with prefix ' => [ 'Category:Main Page ' , 'Main Page ' , 'Main Page ' ],
147
+ 'special with prefix ' => [ 'Special:ListFiles ' , 'ListFiles ' , 'ListFiles ' ],
148
+ 'special no prefix ' => [ 'Special:Watchlist ' , 'Watchlist ' , 'Watchlist ' ],
149
+ ];
150
+ }
151
+
152
+ /**
153
+ * @dataProvider provideOnBeforePageDisplay
154
+ * @covers HidePrefix::onBeforePageDisplay
155
+ */
156
+ public function testOnBeforePageDisplay ( $ pagename , $ expectedTitle , $ pageTitle ) {
157
+ $ t = Title::newFromText ( $ pagename );
158
+ $ t ->setContentModel ( CONTENT_MODEL_WIKITEXT );
159
+ $ skin = new SkinTemplate ();
160
+ $ output = $ this ->createMock ( OutputPage::class );
161
+ $ output ->method ( 'getTitle ' )->willReturn ( $ t );
162
+ $ output ->method ( 'isArticle ' )->willReturn ( true );
163
+ $ output ->method ( 'getPageTitle ' )->willReturn ( $ pageTitle );
164
+ $ output ->expects ( $ this ->once () )->method ( 'setPageTitle ' )->with ( $ expectedTitle );
165
+
166
+ HidePrefix::onBeforePageDisplay ( $ output , $ skin );
167
+ }
182
168
}
0 commit comments