wiki.techinc.nl/tests/phpunit/includes/htmlform/HTMLAutoCompleteSelectFieldTest.php
Daimona Eaytoy ee672592d8 tests: Replace assertRegExp with assertMatchesRegularExpression
And also assertNotRegExp -> assertDoesNotMatchRegularExpression. The
methods were renamed in PHPUnit 9.

Done automatically with:
  grep -rl assertRegExp tests/ | xargs sed -r -i "s/>assertRegExp\(/>assertMatchesRegularExpression\(/"
  grep -rl assertNotRegExp tests/ | xargs sed -r -i "s/>assertNotRegExp\(/>assertDoesNotMatchRegularExpression\(/"

Split out from Ifdba0f9e98eb6bce4590b7eb73170c51a697d7c6 so that it
remains smaller and easier to review.

Also make a test use MediaWikiUnitTestCase (it's already in the unit/
dir) so that it can access the forward-compat method.

Bug: T243600
Change-Id: Ifa279d5f201d7abeebece292141ebface8278046
2022-10-07 14:13:16 -04:00

46 lines
1.4 KiB
PHP

<?php
/**
* @covers HTMLAutoCompleteSelectField
*/
class HTMLAutoCompleteSelectFieldTest extends MediaWikiIntegrationTestCase {
public $options = [
'Bulgaria' => 'BGR',
'Burkina Faso' => 'BFA',
'Burundi' => 'BDI',
];
/**
* Verify that attempting to instantiate an HTMLAutoCompleteSelectField
* without providing any autocomplete options causes an exception to be
* thrown.
*/
public function testMissingAutocompletions() {
$this->expectException( MWException::class );
$this->expectExceptionMessage( "called without any autocompletions" );
new HTMLAutoCompleteSelectField( [ 'fieldname' => 'Test' ] );
}
/**
* Test that the optional select dropdown is included or excluded based on
* the presence or absence of the 'options' parameter.
*/
public function testOptionalSelectElement() {
$params = [
'fieldname' => 'Test',
'autocomplete-data' => $this->options,
'options' => $this->options,
];
$field = new HTMLAutoCompleteSelectField( $params );
$html = $field->getInputHTML( false );
$this->assertMatchesRegularExpression( '/select/', $html,
"When the 'options' parameter is set, the HTML includes a <select>" );
unset( $params['options'] );
$field = new HTMLAutoCompleteSelectField( $params );
$html = $field->getInputHTML( false );
$this->assertDoesNotMatchRegularExpression( '/select/', $html,
"When the 'options' parameter is not set, the HTML does not include a <select>" );
}
}