Debian Codegraph @

tests/phpunit/integration/includes/HTMLForm/Field/HTMLSelectNamespaceTest.php

raw symbols SCIP
1 <?php
2 namespace MediaWiki\Tests\Integration\HTMLForm\Field;
3
4 use MediaWiki\HTMLForm\Field\HTMLSelectNamespace;
5 use MediaWiki\Language\Language;
6 use MediaWiki\MediaWikiServices;
7 use MediaWiki\Tests\Integration\HTMLForm\HTMLFormFieldTestCase;
8
9 /**
10 * @covers MediaWiki\HTMLForm\Field\HTMLSelectNamespace
11 */
12 class HTMLSelectNamespaceTest extends HTMLFormFieldTestCase {
13 /** @inheritDoc */
14 protected $className = HTMLSelectNamespace::class;
15
16 /**
17 * Until T277470 is fixed, because each time this is run it might be on a box that has
18 * different extensions/config, we just have to grab the data structure ourselves. Ick.
19 */
20 private static function makeNamespaceOptionsList( Language $language ): string {
21 $namespaces = $language->getNamespaces();
22 $expectedOptions = '';
23 foreach ( $namespaces as $id => $label ) {
24 if ( $id < 0 ) {
25 // Don't list special namespaces
26 continue;
27 }
28 if ( $id === 0 ) {
29 $repLabel = wfMessage( 'blanknamespace' )->inLanguage( $language )->text();
30 } else {
31 $repLabel = str_replace( '_', ' ', $label );
32 }
33 $expectedOptions .= "<option value=\"$id\">$repLabel</option>";
34 }
35 return $expectedOptions;
36 }
37
38 public static function provideInputHtml() {
39 $expectedOptions = static::makeNamespaceOptionsList(
40 MediaWikiServices::getInstance()->getContentLanguage()
41 );
42
43 yield 'Basic list' => [
44 [],
45 '',
46 "<select class=\"namespaceselector\" id=\"mw-input-testfield\" name=\"testfield\">\n<option value=\"all\">all</option>\n" . $expectedOptions . "\n</select>"
47 ];
48
49 yield 'Basic list, explicitly in userlang' => [
50 [
51 'in-user-lang' => false
52 ],
53 '',
54 "<select class=\"namespaceselector\" id=\"mw-input-testfield\" name=\"testfield\">\n<option value=\"all\">all</option>\n" . $expectedOptions . "\n</select>"
55 ];
56
57 yield 'Basic list, blank all' => [
58 [
59 'all' => '',
60 ],
61 '',
62 "<select class=\"namespaceselector\" id=\"mw-input-testfield\" name=\"testfield\">\n<option value=\"\" selected=\"\">all</option>\n" . $expectedOptions . "\n</select>"
63 ];
64 }
65
66 public static function provideInputCodex() {
67 $expectedOptions = static::makeNamespaceOptionsList(
68 MediaWikiServices::getInstance()->getContentLanguage()
69 );
70
71 yield 'Basic list' => [
72 [],
73 '',
74 false,
75 "<select name=\"testfield\" id=\"mw-input-testfield\" class=\"cdx-select\"><option value=\"all\">all</option>" . $expectedOptions . "</select>"
76 ];
77
78 yield 'Basic list, explicitly in userlang' => [
79 [
80 'in-user-lang' => false
81 ],
82 '',
83 false,
84 "<select name=\"testfield\" id=\"mw-input-testfield\" class=\"cdx-select\"><option value=\"all\">all</option>" . $expectedOptions . "</select>"
85 ];
86
87 yield 'Basic list, blank all' => [
88 [
89 'all' => '',
90 ],
91 '',
92 false,
93 "<select name=\"testfield\" id=\"mw-input-testfield\" class=\"cdx-select\"><option value=\"\" selected=\"\">all</option>" . $expectedOptions . "</select>"
94 ];
95 }
96
97 public static function provideInputOOUI() {
98 $expectedOptions = str_replace(
99 '"', "'",
100 static::makeNamespaceOptionsList( MediaWikiServices::getInstance()->getContentLanguage() )
101 );
102
103 yield 'Basic list' => [
104 [],
105 '',
106 "<div id='mw-input-testfield' class='oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-dropdownInputWidget oo-ui-dropdownInputWidget-php mw-widget-namespaceInputWidget'><select tabindex='0' name='testfield' class='oo-ui-inputWidget-input oo-ui-indicator-down'><option value='all' selected='selected'>all</option>" . $expectedOptions . "</select></div>"
107 ];
108
109 yield 'Basic list, explicitly in userlang' => [
110 [
111 'in-user-lang' => false
112 ],
113 '',
114 "<div id='mw-input-testfield' class='oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-dropdownInputWidget oo-ui-dropdownInputWidget-php mw-widget-namespaceInputWidget'><select tabindex='0' name='testfield' class='oo-ui-inputWidget-input oo-ui-indicator-down'><option value='all' selected='selected'>all</option>" . $expectedOptions . "</select></div>"
115
116 ];
117
118 yield 'Basic list, blank all' => [
119 [
120 'all' => '',
121 ],
122 '',
123 "<div id='mw-input-testfield' class='oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-dropdownInputWidget oo-ui-dropdownInputWidget-php mw-widget-namespaceInputWidget'><select tabindex='0' name='testfield' class='oo-ui-inputWidget-input oo-ui-indicator-down'><option value='' selected='selected'>all</option>" . $expectedOptions . "</select></div>"
124
125 ];
126 }
127 }