jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/364474 )

Change subject: ChangeFileNameForm show user provided value if present
......................................................................


ChangeFileNameForm show user provided value if present

When entering titles that have a / in them the title
parsing will result in getText only showing the part
after the /.
This results in a loss of info when the user provides
the invlaid char /, so instead always show the user
their own input if present.

Change-Id: I8962ea1578d66b34d538b439e2a55f71e41de82c
---
M src/Html/ChangeFileNameForm.php
A tests/phpunit/Html/ChangeFileNameFormTest.php
2 files changed, 79 insertions(+), 1 deletion(-)

Approvals:
  WMDE-Fisch: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/Html/ChangeFileNameForm.php b/src/Html/ChangeFileNameForm.php
index 008a373..aff6c55 100644
--- a/src/Html/ChangeFileNameForm.php
+++ b/src/Html/ChangeFileNameForm.php
@@ -30,6 +30,12 @@
        }
 
        public function getHtml() {
+               // Try showing the user provided value first if present
+               $filenameValue = 
$this->importPlan->getRequest()->getIntendedName();
+               if ( $filenameValue === null ) {
+                       $filenameValue = $this->importPlan->getTitleText();
+               }
+
                return Html::openElement(
                        'form',
                        [
@@ -45,7 +51,7 @@
                new TextInputWidget(
                        [
                                'name' => 'intendedFileName',
-                               'value' => $this->importPlan->getFileName(),
+                               'value' => $filenameValue,
                                'classes' => [ 'mw-importfile-import-newtitle' 
],
                                'placeholder' => ( new Message( 
'fileimporter-newfilename-placeholder' ) )->plain(),
                                'suggestions' => false,
diff --git a/tests/phpunit/Html/ChangeFileNameFormTest.php 
b/tests/phpunit/Html/ChangeFileNameFormTest.php
new file mode 100644
index 0000000..e0f40c5
--- /dev/null
+++ b/tests/phpunit/Html/ChangeFileNameFormTest.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace FileImporter\Html\Test;
+
+use FauxRequest;
+use FileImporter\Data\ImportDetails;
+use FileImporter\Data\ImportPlan;
+use FileImporter\Data\ImportRequest;
+use FileImporter\Html\ChangeFileNameForm;
+use OOUI\MediaWikiTheme;
+use OOUI\Theme;
+use PHPUnit_Framework_TestCase;
+use SpecialPage;
+use Title;
+
+class ChangeFileNameFormTest extends PHPUnit_Framework_TestCase {
+
+       public function setUp() {
+               parent::setUp();
+               Theme::setSingleton( new MediaWikiTheme );
+       }
+
+       private function getMockSpecialPage() {
+               $mock = $this->getMock( SpecialPage::class, [], [], '', false );
+               $mock->expects( $this->any() )
+                       ->method( 'getPageTitle' )
+                       ->will( $this->returnValue( Title::newFromText( 
'SomeTitle' ) ) );
+               $mock->expects( $this->any() )
+                       ->method( 'getRequest' )
+                       ->will( $this->returnValue( new FauxRequest( [ 
'importDetailsHash' => 'FAKEHASH' ] ) ) );
+               return $mock;
+       }
+
+       /**
+        * @return \PHPUnit_Framework_MockObject_MockObject|ImportDetails
+        */
+       private function getMockImportDetails() {
+               return $this->getMock( ImportDetails::class, [], [], '', false 
);
+       }
+
+       public function provideTestTextDisplayedInInputBox() {
+               return [
+                       [ 'Foo', 'Foo' ],
+                       [ 'Foooo/Barr', 'Foooo/Barr' ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideTestTextDisplayedInInputBox
+        * @param string $userInputName
+        * @param string $expectedInputText
+        */
+       public function testTextDisplayedInInputBox( $userInputName, 
$expectedInputText ) {
+               $importPlan = new ImportPlan(
+                       new ImportRequest( 'http://goog', $userInputName, '' ),
+                       $this->getMockImportDetails()
+               );
+               $form = new ChangeFileNameForm( $this->getMockSpecialPage(), 
$importPlan );
+
+               assertThat(
+                       $form->getHtml(),
+                       is( htmlPiece( havingChild(
+                               both( withTagName( 'input' ) )
+                                       ->andAlso( withAttribute( 'name' 
)->havingValue( 'intendedFileName' ) )
+                                       ->andAlso( withAttribute( 'value' 
)->havingValue( $expectedInputText ) )
+                       ) ) )
+               );
+               // Avoid marking as a risky test
+               $this->assertTrue( true );
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/364474
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8962ea1578d66b34d538b439e2a55f71e41de82c
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/FileImporter
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Andrew-WMDE <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[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

Reply via email to