File: HTMLSelectNamespaceTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (127 lines) | stat: -rw-r--r-- 4,443 bytes parent folder | download
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
<?php
namespace MediaWiki\Tests\Integration\HTMLForm\Field;

use MediaWiki\HTMLForm\Field\HTMLSelectNamespace;
use MediaWiki\Language\Language;
use MediaWiki\MediaWikiServices;
use MediaWiki\Tests\Integration\HTMLForm\HTMLFormFieldTestCase;

/**
 * @covers MediaWiki\HTMLForm\Field\HTMLSelectNamespace
 */
class HTMLSelectNamespaceTest extends HTMLFormFieldTestCase {
	/** @inheritDoc */
	protected $className = HTMLSelectNamespace::class;

	/**
	 * Until T277470 is fixed, because each time this is run it might be on a box that has
	 * different extensions/config, we just have to grab the data structure ourselves. Ick.
	 */
	private static function makeNamespaceOptionsList( Language $language ): string {
		$namespaces = $language->getNamespaces();
		$expectedOptions = '';
		foreach ( $namespaces as $id => $label ) {
			if ( $id < 0 ) {
				// Don't list special namespaces
				continue;
			}
			if ( $id === 0 ) {
				$repLabel = wfMessage( 'blanknamespace' )->inLanguage( $language )->text();
			} else {
				$repLabel = str_replace( '_', ' ', $label );
			}
			$expectedOptions .= "<option value=\"$id\">$repLabel</option>";
		}
		return $expectedOptions;
	}

	public static function provideInputHtml() {
		$expectedOptions = static::makeNamespaceOptionsList(
			MediaWikiServices::getInstance()->getContentLanguage()
		);

		yield 'Basic list' => [
			[],
			'',
			"<select class=\"namespaceselector\" id=\"mw-input-testfield\" name=\"testfield\">\n<option value=\"all\">all</option>\n" . $expectedOptions . "\n</select>"
		];

		yield 'Basic list, explicitly in userlang' => [
			[
				'in-user-lang' => false
			],
			'',
			"<select class=\"namespaceselector\" id=\"mw-input-testfield\" name=\"testfield\">\n<option value=\"all\">all</option>\n" . $expectedOptions . "\n</select>"
		];

		yield 'Basic list, blank all' => [
			[
				'all' => '',
			],
			'',
			"<select class=\"namespaceselector\" id=\"mw-input-testfield\" name=\"testfield\">\n<option value=\"\" selected=\"\">all</option>\n" . $expectedOptions . "\n</select>"
		];
	}

	public static function provideInputCodex() {
		$expectedOptions = static::makeNamespaceOptionsList(
			MediaWikiServices::getInstance()->getContentLanguage()
		);

		yield 'Basic list' => [
			[],
			'',
			false,
			"<select name=\"testfield\" id=\"mw-input-testfield\" class=\"cdx-select\"><option value=\"all\">all</option>" . $expectedOptions . "</select>"
		];

		yield 'Basic list, explicitly in userlang' => [
			[
				'in-user-lang' => false
			],
			'',
			false,
			"<select name=\"testfield\" id=\"mw-input-testfield\" class=\"cdx-select\"><option value=\"all\">all</option>" . $expectedOptions . "</select>"
		];

		yield 'Basic list, blank all' => [
			[
				'all' => '',
			],
			'',
			false,
			"<select name=\"testfield\" id=\"mw-input-testfield\" class=\"cdx-select\"><option value=\"\" selected=\"\">all</option>" . $expectedOptions . "</select>"
		];
	}

	public static function provideInputOOUI() {
		$expectedOptions = str_replace(
			'"', "'",
			static::makeNamespaceOptionsList( MediaWikiServices::getInstance()->getContentLanguage() )
		);

		yield 'Basic list' => [
			[],
			'',
			"<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>"
		];

		yield 'Basic list, explicitly in userlang' => [
			[
				'in-user-lang' => false
			],
			'',
			"<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>"

		];

		yield 'Basic list, blank all' => [
			[
				'all' => '',
			],
			'',
			"<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>"

		];
	}
}