WMDE-Fisch has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/381170 )
Change subject: Add integration tests for SpecialPage
......................................................................
Add integration tests for SpecialPage
Change-Id: Ib4dee19ceb971e718e141104fb282087e28da000
---
M includes/SpecialConflictTestPage/SpecialConflictTestPage.php
A
tests/phpunit/SpecialConflictTestPage/SpecialConflictTestPageIntegrationTest.php
2 files changed, 235 insertions(+), 2 deletions(-)
Approvals:
Addshore: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/SpecialConflictTestPage/SpecialConflictTestPage.php
b/includes/SpecialConflictTestPage/SpecialConflictTestPage.php
index be671cc..7a4c1fc 100644
--- a/includes/SpecialConflictTestPage/SpecialConflictTestPage.php
+++ b/includes/SpecialConflictTestPage/SpecialConflictTestPage.php
@@ -27,7 +27,7 @@
$request = $this->getRequest();
if ( $request->getVal( 'wpPreview' ) != null ||
$request->getVal( 'wpDiff' ) != null ) {
- $this->showHintBox( ( new Message(
'twoColConflict-test-preview-hint' ) )->parse() );
+ $this->showHintBoxRaw( ( new Message(
'twoColConflict-test-preview-hint' ) )->parse() );
$title = Title::newFromText( $request->getVal(
'mw-twocolconflict-title' ) );
$this->showPreview( $title, $request->getVal(
'wpTextbox1' ) );
@@ -75,11 +75,15 @@
* @param string $additionalClass
*/
private function showHintBox( $message, $additionalClass = '' ) {
+ $this->showHintBoxRaw( Html::rawElement( 'p', [], $message ),
$additionalClass );
+ }
+
+ private function showHintBoxRaw( $message, $additionalClass = '' ) {
$this->getOutput()->addHTML(
Html::rawElement(
'div',
[ 'class' => 'mw-twocolconflict-test-hintbox '
. $additionalClass ],
- Html::rawElement( 'p', [], $message )
+ $message
)
);
}
diff --git
a/tests/phpunit/SpecialConflictTestPage/SpecialConflictTestPageIntegrationTest.php
b/tests/phpunit/SpecialConflictTestPage/SpecialConflictTestPageIntegrationTest.php
new file mode 100644
index 0000000..b5370e8
--- /dev/null
+++
b/tests/phpunit/SpecialConflictTestPage/SpecialConflictTestPageIntegrationTest.php
@@ -0,0 +1,229 @@
+<?php
+
+class SpecialConflictTestPageIntegrationTest extends SpecialPageTestBase {
+
+ /**
+ * Returns a new instance of the special page under test.
+ *
+ * @return SpecialPage
+ */
+ protected function newSpecialPage() {
+ return new SpecialConflictTestPage();
+ }
+
+ public function provideTestData() {
+ return [
+ 'Expect initial input form' => [
+ new FauxRequest(),
+ function ( $html ) {
+ $this->assertFormIsPresent( $html );
+ $this->assertTitleInputFieldPresent(
$html );
+ $this->assertHintBox( $html, 'On this
page you can try out the new Two Column Edit Conflict' .
+ ' interface without messing
anything up.' );
+ },
+ ],
+ 'Expect warning on invalid title' => [
+ new FauxRequest( [
+ 'mw-twocolconflict-test-title' =>
'!@#$',
+ ] ),
+ function ( $html ) {
+ $this->assertFormIsPresent( $html );
+ $this->assertTitleInputFieldPresent(
$html );
+ $this->assertWarningBox( $html, 'There
is no page with this title.' );
+ },
+ ],
+ 'Expect editor on valid title' => [
+ new FauxRequest( [
+ 'mw-twocolconflict-test-title' =>
'TestPage',
+ ] ),
+ function ( $html ) {
+ $this->assertFormIsPresent( $html );
+ $this->assertWikiEditorPresent( $html,
"Test content\n" );
+ },
+ 'Test content'
+ ],
+ 'Expect conflict page on valid title and edit' => [
+ new FauxRequest( [
+ 'mw-twocolconflict-test-title' =>
'TestPage',
+ 'mw-twocolconflict-test-text' => 'Test
content',
+ ] ),
+ function ( $html ) {
+
$this->assertTwoColConflictEditorPresent( $html );
+ $this->assertHiddenInputField( $html,
'mode', 'conflict' );
+ $this->assertHiddenInputField( $html,
'wpUltimateParam', '1' );
+ $this->assertHiddenInputField( $html,
'mw-twocolconflict-your-text', 'Test content' );
+ $this->assertHiddenInputFieldAny(
$html, 'mw-twocolconflict-current-text' );
+ $this->assertHiddenInputFieldAny(
$html, 'mw-twocolconflict-current-text' );
+ $this->assertHintBox(
+ $html,
+ 'This is the test conflict.
Changes won\'t be saved but can be previewed.'
+ );
+ },
+ 'Test content'
+ ],
+ 'Expect preview page on valid title, edit and preview'
=> [
+ new FauxRequest( [
+ 'wpPreview' => true,
+ 'wpTextbox1' => 'Test content super
duper',
+ 'wpEditToken' => true,
+ 'wpUltimateParam' => 1,
+ 'mw-twocolconflict-title' => 'TestPage',
+ ] ),
+ function ( $html ) {
+
$this->assertParserOutputPresentWithContent( $html, "Test content super
duper\n" );
+ },
+ ],
+ ];
+ }
+
+ private function assertFormIsPresent( $html ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild(
+ both( withTagName( 'form' ) )
+ ->andAlso( withAttribute( 'action' ) )
+ ->andAlso( withAttribute( 'method'
)->havingValue( 'POST' ) )
+ ->andAlso( havingChild(
+ both( withTagName( 'button' ) )
+ ->andAlso(
withAttribute( 'type' )->havingValue( 'submit' ) )
+ ) )
+ ) ) )
+ );
+ }
+
+ private function assertTitleInputFieldPresent( $html ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild(
+ both( withTagName( 'input' ) )
+ ->andAlso( withAttribute( 'placeholder'
)->havingValue( 'Main Page' ) )
+ ->andAlso( withAttribute( 'name'
)->havingValue( 'mw-twocolconflict-test-title' ) )
+ ) ) )
+ );
+ }
+
+ private function assertWikiEditorPresent( $html, $text ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild(
+ both( withTagName( 'textarea' ) )
+ ->andAlso( withAttribute( 'name'
)->havingValue( 'mw-twocolconflict-test-text' ) )
+ ->andAlso( havingTextContents( $text ) )
+ ) ) )
+ );
+ }
+
+ private function assertTwoColConflictEditorPresent( $html ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild(
+ both( withTagName( 'textarea' ) )
+ ->andAlso( withAttribute( 'name'
)->havingValue( 'wpTextbox1' ) )
+ ) ) )
+ );
+ }
+
+ private function assertParserOutputPresentWithContent( $html, $text ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild(
+ both( withTagName( 'div' ) )
+ ->andAlso( withClass(
'mw-parser-output' ) )
+ ->andAlso( havingChild(
+ both( withTagName( 'p' ) )
+ ->andAlso(
havingTextContents( $text ) )
+ ) )
+ ) ) )
+ );
+ }
+
+ private function assertWarningBox( $html, $text ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild(
+ both( withTagName( 'div' ) )
+ ->andAlso( withClass( 'warningbox' ) )
+ ->andAlso( havingChild(
+ both( withTagName( 'p' ) )
+ ->andAlso(
havingTextContents( $text ) )
+ ) )
+ ) ) )
+ );
+ }
+
+ private function assertHintBox( $html, $text ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild(
+ both( withTagName( 'div' ) )
+ ->andAlso( withClass(
'mw-twocolconflict-test-hintbox' ) )
+ ->andAlso( havingChild(
+ both( withTagName( 'p' ) )
+ ->andAlso(
havingTextContents( $text ) )
+ ) )
+ ) ) )
+ );
+ }
+
+ private function assertHiddenInputField( $html, $name, $value ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild(
+ both( withTagName( 'input' ) )
+ ->andAlso( withAttribute( 'type'
)->havingValue( 'hidden' ) )
+ ->andAlso( withAttribute( 'name'
)->havingValue( $name ) )
+ ->andAlso( withAttribute( 'value'
)->havingValue( $value ) )
+ ) ) )
+ );
+ }
+
+ private function assertHiddenInputFieldAny( $html, $name ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild(
+ both( withTagName( 'input' ) )
+ ->andAlso( withAttribute( 'type'
)->havingValue( 'hidden' ) )
+ ->andAlso( withAttribute( 'name'
)->havingValue( $name ) )
+ ) ) )
+ );
+ }
+
+ /**
+ * @dataProvider provideTestData
+ */
+ public function testSpecialPageExecutionWithVariousInputs(
+ $request,
+ $htmlAssertionCallable,
+ $presetText = ''
+ ) {
+ // @codingStandardsIgnoreLine
MediaWiki.VariableAnalysis.ForbiddenGlobalVariables.ForbiddenGlobal$wgTitle
+ global $wgTitle;
+
+ $this->setMwGlobals( 'wgTwoColConflictBetaFeature', false );
+
+ $user = $this->getTestUser()->getUser();
+ $testPageArr = $this->insertPage( 'TestPage', $presetText,
NS_MAIN );
+ $wgTitle = $testPageArr[ 'title' ];
+
+ /** @var string $html */
+ /** @var WebResponse $response */
+ list( $html, $response ) = $this->executeSpecialPage(
+ '',
+ $request,
+ 'en',
+ $user
+ );
+
+ $htmlAssertionCallable( $html );
+ // assertion to avoid phpunit showing hamcrest test as risky
+ $this->assertTrue( true );
+ }
+
+ public function testNoOutputWhenBetaFeatureAndNoUser() {
+ $this->setMwGlobals( 'wgTwoColConflictBetaFeature', true );
+
+ list( $html, $response ) = $this->executeSpecialPage();
+
+ $this->assertEquals( '', $html );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/381170
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib4dee19ceb971e718e141104fb282087e28da000
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/TwoColConflict
Gerrit-Branch: master
Gerrit-Owner: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Andrew-WMDE <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits