WMDE-Fisch has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/381170 )
Change subject: Add integration tests for SpecialPage
......................................................................
Add integration tests for SpecialPage
Change-Id: Ib4dee19ceb971e718e141104fb282087e28da000
---
A
tests/phpunit/SpecialConflictTestPage/SpecialConflictTestPageIntegrationTest.php
1 file changed, 225 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TwoColConflict
refs/changes/70/381170/1
diff --git
a/tests/phpunit/SpecialConflictTestPage/SpecialConflictTestPageIntegrationTest.php
b/tests/phpunit/SpecialConflictTestPage/SpecialConflictTestPageIntegrationTest.php
new file mode 100644
index 0000000..563b3a3
--- /dev/null
+++
b/tests/phpunit/SpecialConflictTestPage/SpecialConflictTestPageIntegrationTest.php
@@ -0,0 +1,225 @@
+<?php
+
+namespace FileImporter\Test;
+
+use FauxRequest;
+use PermissionsError;
+use SpecialConflictTestPage;
+use SpecialPage;
+use SpecialPageTestBase;
+use Title;
+use User;
+use WebResponse;
+
+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 );
+ },
+ ],
+ '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' );
+ },
+ '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 ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild(
+ both( withTagName(
'div' ) )
+ ) ) )
+ );
+ },
+ ],
+ ];
+ }
+
+ private function assertTagExistsWithTextContents( $html, $tagName,
$value ) {
+ assertThat(
+ $html,
+ is( htmlPiece( havingChild( both(
+ withTagName( $tagName ) )
+ ->andAlso( havingTextContents( $value ) )
+ ) ) )
+ );
+ }
+
+ 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 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 = ''
+ ) {
+ global $wgTitle;
+
+ $user = $this->getTestUser()->getUser();
+ $this->insertPage( 'TestPage', $presetText, NS_MAIN );
+ $wgTitle = $title = Title::newFromText( 'TestPage', NS_MAIN );
+
+ /** @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 );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/381170
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib4dee19ceb971e718e141104fb282087e28da000
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TwoColConflict
Gerrit-Branch: master
Gerrit-Owner: WMDE-Fisch <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits