jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/333961 )
Change subject: Replaced some assertTag with hamcrest matchers
......................................................................
Replaced some assertTag with hamcrest matchers
Change-Id: I9f79777f7f6e39290b6766c1446fb23abdfc27b0
---
M repo/tests/phpunit/includes/Specials/HtmlAssertionHelpers.php
1 file changed, 52 insertions(+), 133 deletions(-)
Approvals:
WMDE-leszek: Checked; Looks good to me, approved
Aleksey Bekh-Ivanov (WMDE): Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/repo/tests/phpunit/includes/Specials/HtmlAssertionHelpers.php
b/repo/tests/phpunit/includes/Specials/HtmlAssertionHelpers.php
index 1c621a4..9e6b287 100644
--- a/repo/tests/phpunit/includes/Specials/HtmlAssertionHelpers.php
+++ b/repo/tests/phpunit/includes/Specials/HtmlAssertionHelpers.php
@@ -12,16 +12,10 @@
* @param string $name
*/
protected function assertHtmlContainsInputWithName( $html, $name ) {
- $matcher = [
- 'tag' => 'input',
- 'attributes' => [
- 'name' => $name,
- ],
- ];
- $this->assertTag(
- $matcher,
+
+ assertThat(
$html,
- "Failed to find input element with name '{$name}'"
+ is( htmlPiece( havingChild( tagMatchingOutline( "<input
name='$name'/>" ) ) ) )
);
}
@@ -31,18 +25,10 @@
* @param string $value
*/
protected function assertHtmlContainsInputWithNameAndValue( $html,
$name, $value ) {
- $matcher = [
- 'tag' => 'input',
- 'attributes' => [
- 'name' => $name,
- 'value' => $value,
- ],
- ];
- $this->assertTag(
- $matcher,
+
+ assertThat(
$html,
- "Failed to find input element with name '{$name}' and
value '{$value}' in :\n{$html}"
- );
+ is( htmlPiece( havingChild( tagMatchingOutline( "<input
name='$name' value='$value'/>" ) ) ) ) );
}
/**
@@ -50,16 +36,11 @@
* @param string $name
*/
protected function assertHtmlContainsSelectWithName( $html, $name ) {
- $matcher = [
- 'tag' => 'select',
- 'attributes' => [
- 'name' => $name,
- ],
- ];
- $this->assertTag(
- $matcher,
+
+ assertThat(
$html,
- "Failed to find select element with name '{$name}' in
html:\n\n {$html}"
+ is( htmlPiece( havingChild(
+ tagMatchingOutline( "<select name='$name'/>" )
) ) )
);
}
@@ -69,24 +50,21 @@
* @param string $value
*/
protected function assertHtmlContainsSelectWithNameAndSelectedValue(
$html, $name, $value ) {
- $matcher = [
- 'tag' => 'select',
- 'attributes' => [
- 'name' => $name,
- ],
- 'child' => [
- 'tag' => 'option',
- 'attributes' => [
- 'value' => $value,
- 'selected' => 'selected',
- ],
- ],
- ];
- $this->assertTag(
- $matcher,
+
+ assertThat(
$html,
- "Failed to find select element with name '{$name}' and
selected value '{$value}'" .
- " in html:\n\n {$html}"
+ is(
+ htmlPiece(
+ havingChild(
+ allOf(
+ tagMatchingOutline(
"<select name='$name'/>" ),
+ havingDirectChild(
+
tagMatchingOutline( "<option value='$value' selected/>" )
+ )
+ )
+ )
+ )
+ )
);
}
@@ -94,97 +72,38 @@
* @param string $html
*/
protected function assertHtmlContainsSubmitControl( $html ) {
- $matchers = [
- 'button submit' => [
- 'tag' => 'button',
- 'attributes' => [
- 'type' => 'submit',
- ],
- ],
- 'input submit' => [
- 'tag' => 'input',
- 'attributes' => [
- 'type' => 'submit',
- ],
- ],
- ];
-
- foreach ( $matchers as $matcher ) {
- try {
- $this->assertTag( $matcher, $html, "Failed to
find submit element" );
-
- return;
- } catch ( \PHPUnit_Framework_ExpectationFailedException
$exception ) {
- continue;
- }
- }
-
- $this->fail( "Failed to find submit element" );
+ assertThat(
+ $html,
+ is(
+ htmlPiece(
+ havingChild(
+ either(
+ both(
+ withTagName(
'button' )
+ )->andAlso(
+ either(
+
withAttribute( 'type' )->havingValue( 'submit' )
+
)->orElse(
+
not( withAttribute( 'type' ) )
+ )
+ )
+ )->orElse(
+ tagMatchingOutline(
'<input type="submit"/>' )
+ )
+ )
+ )
+ )
+ );
}
protected function assertHtmlContainsErrorMessage( $html, $messageText
) {
- $assertions = [
- [ $this, 'assertHtmlContainsFormErrorMessage' ],
- [ $this, 'assertHtmlContainsOOUiErrorMessage' ],
- ];
+ $formErrorMessage = tagMatchingOutline( '<div class="error"/>'
);
+ $ooUiErrorMessage = tagMatchingOutline( '<li
class="oo-ui-fieldLayout-messages-error"/>' );
- foreach ( $assertions as $assertion ) {
- try {
- $assertion( $html, $messageText );
-
- return;
- } catch ( \PHPUnit_Framework_ExpectationFailedException
$exception ) {
- continue;
- }
- }
-
- $this->fail(
- "Failed to find error message with text
'{$messageText}' in html:\n\n {$html}"
- );
+ assertThat( $html, is( htmlPiece(
+ havingChild(
+ both( either( $formErrorMessage )->orElse(
$ooUiErrorMessage ) )
+ ->andAlso( havingTextContents(
containsString( $messageText )->ignoringCase() ) ) ) ) ) );
}
-
- protected function assertHtmlContainsFormErrorMessage( $html,
$messageText ) {
- $matcher = [
- 'tag' => 'div',
- 'class' => 'error',
- 'content' => 'regexp: /' . preg_quote( $messageText,
'/' ) . '/ui',
- ];
- $this->assertTag(
- $matcher,
- $html,
- "Failed to find form error message with text
'{$messageText}' in html:\n\n {$html}"
- );
- }
-
- protected function assertHtmlContainsOOUiErrorMessage( $html,
$messageText ) {
- $matcher = [
- 'tag' => 'li',
- 'class' => 'oo-ui-fieldLayout-messages-error',
- 'content' => 'regexp: /' . preg_quote( $messageText,
'/' ) . '/ui',
- ];
- $this->assertTag(
- $matcher,
- $html,
- "Failed to find OO-UI error message with text
'{$messageText}' in html:\n\n {$html}"
- );
- }
-
- /**
- * @param array $matcher Associative array of structure required by
$options argument
- * of {@see \PHPUnit_Util_XML::findNodes}
- * @param string $htmlOrXml
- * @param string $message
- * @param bool $isHtml
- *
- * @see \MediaWikiTestCase::assertTag
- */
- abstract protected function assertTag( $matcher, $htmlOrXml, $message =
'', $isHtml = true );
-
- /**
- * @param string $message
- *
- * @see \PHPUnit_Framework_Assert::fail
- */
- abstract public function fail( $message = '' );
}
--
To view, visit https://gerrit.wikimedia.org/r/333961
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9f79777f7f6e39290b6766c1446fb23abdfc27b0
Gerrit-PatchSet: 18
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits