File: HTMLFormFieldTestCase.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 (80 lines) | stat: -rw-r--r-- 2,218 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
<?php

namespace MediaWiki\Tests\Integration\HTMLForm;

use InvalidArgumentException;
use MediaWiki\HTMLForm\HTMLForm;
use MediaWiki\HTMLForm\HTMLFormField;
use MediaWikiIntegrationTestCase;

abstract class HTMLFormFieldTestCase extends MediaWikiIntegrationTestCase {
	/** @var string|null */
	protected $className = null;

	/**
	 * Augment assertEquals a little bit by stripping newlines and tabs from $expected.
	 * This allows $expected to be expressed as a heredoc string.
	 *
	 * @param string $expected HTML
	 * @param string $actual HTML
	 * @param string $msg Optional message
	 */
	private function assertHTMLEqualStrippingWhitespace( $expected, $actual, $msg = '' ) {
		$this->assertEquals(
			str_replace( [ "\n", "\t" ], '', $expected ),
			str_replace( [ "\n", "\t" ], '', $actual ),
			$msg
		);
	}

	public function constructField( array $params ): HTMLFormField {
		if ( $this->className === null ) {
			throw new InvalidArgumentException(
				'HTMLFormFieldTestCase subclass ' . __CLASS__ . ' must override $className or constructField()'
			);
		}
		return new $this->className( $params + [
			'parent' => $this->createMock( HTMLForm::class ),
			'name' => 'testfield'
		] );
	}

	public static function provideInputHtml() {
		return [];
	}

	/**
	 * @dataProvider provideInputHtml
	 */
	public function testGetInputHtml( $params, $value, $expected ) {
		$field = $this->constructField( $params );
		$this->assertHTMLEqualStrippingWhitespace( $expected, $field->getInputHtml( $value ) );
	}

	public static function provideInputOOUI() {
		return [];
	}

	/**
	 * @dataProvider provideInputOOUI
	 */
	public function testGetInputOOUI( $params, $value, $expected ) {
		\OOUI\Theme::setSingleton( new \OOUI\BlankTheme() );

		$field = $this->constructField( $params );
		$this->assertHTMLEqualStrippingWhitespace( $expected, $field->getInputOOUI( $value ) );
	}

	public static function provideInputCodex() {
		return [];
	}

	/**
	 * @dataProvider provideInputCodex
	 */
	public function testGetInputCodex( $params, $value, $hasError, $expected ) {
		$field = $this->constructField( $params );
		$this->assertHTMLEqualStrippingWhitespace( $expected, $field->getInputCodex( $value, $hasError ) );
	}

}