Problem/Motivation

Follow-up from #3221793: Move file upload validation from file.module to constraint validators

core/modules/file/tests/file_test/src/Form/FileTestForm.php
core/modules/file/tests/file_test/src/Form/FileTestSaveUploadFromForm.php

there's a lot of duplicate code between these two, can we get a followup to move to a base-class or trait

Steps to reproduce

Proposed resolution

  • Identify which code is duplicate
  • Decide the best place for each codeblock
  • make a merge request
  • test & review

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3368857

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kim.pepper created an issue. See original summary.

kim.pepper’s picture

Issue tags: +Novice

elber made their first commit to this issue’s fork.

elber’s picture

Hi @kim.pepper should I move everything to a trait?

ultimike made their first commit to this issue’s fork.

ultimike’s picture

Issue tags: +Barcelona2024

The Drupal Contribution Mentoring team is triaging issues for DrupalCon Barcelona 2024, and we are reserving this issue for Mentored Contribution during the event.

After September 27, 2024, this issue returns to being open to all. Thanks!

I plan on working on this issue with my team.

-mike

jacobupal’s picture

We're working on this in our contrib table.

jacobupal’s picture

Issue summary: View changes
jacobupal’s picture

^^ Not anymore, our bad @ultimike! We thought the 'team' meant the whole mentoring team & newbies. Good luck!

nico059 made their first commit to this issue’s fork.

drubolbol’s picture

@nico059 and me have created a new file FileTestFormBase.php with the main common code for buildForm function that is extented by the other classes in the other files.

jacobupal’s picture

Issue summary: View changes
ultimike’s picture

@drubolbol and @nico059 did a great job during the DrupalCon Barcelona mentored core contribution day - making good progress on this issue (and learning a lot about the contribution process along the way.)

Currently, it appears that the changes have caused some tests to fail:

  • Drupal\Tests\file\Functional\SaveUploadTest
  • Drupal\Tests\file\Functional\SaveUploadFormTest
  • Drupal\Tests\file\Functional\RemoteFileSaveUploadTest

See https://git.drupalcode.org/issue/drupal-3368857/-/pipelines/294400 for more details.

-mike

mattlc’s picture

I tried to replace the abstract class by a trait in order to keep original class inheritance/interface implementation intact but the tests results are the same : the "Submit" button cannot be found by #14 stated failing tests.

nico059’s picture

Dear all,

I try also with Trait, and it work's but .... I think the problem with the 3 failed Test is "somewhere else" in the issue fork code. And NOT in the code done here to resolve this issue ...

What I have done ...
I modify the 3 files in repos/drupal/core/modules/file/tests/file_test/src/Form to use a new Trait:
- FileTestForm.php --> to use the Trait
- FileTestSaveUploadFromForm.php --> to use the Trait
- FileTestFormTrait.php --> the Trait itself
I have created a branch with this code here : https://git.drupalcode.org/issue/drupal-3368857/-/tree/3368857-remove-du...

Tests Works BUT ....
The following tests works:
Drupal\Tests\file\Functional\SaveUploadTest
Drupal\Tests\file\Functional\SaveUploadFormTest
Drupal\Tests\file\Functional\RemoteFileSaveUploadTest
BUT .... only if I test them a more recent issue fork
FYI, as I don't know HOW TO DEV in the latest 11.x Drupal version.... I choose a random other fork more recent to test (I choose 3478771-inputconfigurator-should-expose), and when I run them all works !!

Conclusion
I think something is "wrong" in the current issue fork (3368857) somewhere else
Perhaps is it possible to rebase ALL this issue fork with the latest core version ? And see if the Test works too ?

mattlc changed the visibility of the branch 3368857-remove-duplication-trait-rebased to hidden.

anand48 made their first commit to this issue’s fork.

anand48’s picture

Status: Active » Needs review

I have pushed code based on @ultimike and @nico059's approach using an abstract class and the tests appear to pass now. I'm assuming there were some random Functional test failures but they pass once I rerun the pipeline.

smustgrave’s picture

Status: Needs review » Needs work

There are 3 MRs up but no clear indicator which should be reviewed. Also proposed solution section appears to be remaining tasks.

mattlc’s picture

Status: Needs work » Needs review

Hello,

Thank you @anand48, as discussed with both @nico059 and @ultimike at DC Bacelona Trait might be a better solution to keep a simple extension hierarchy.

I worked on the 3368857-remove-duplication-trait.

- minor code style issues fix
- rebased on 11.x
- force pushed to 3368857-remove-duplication-trait

So I think the MR to consider is 9792 from @nico059.

I set the status to Needs review.

smustgrave’s picture

Status: Needs review » Needs work

MRs should be hidden,

But 9792 has errors.

mattlc’s picture

Just saw this. My bad.
I rework on it.
Sorry for that.

smustgrave’s picture

No apology needed!

mattlc changed the visibility of the branch 3368857-remove-duplication-from to hidden.

mattlc changed the visibility of the branch 3368857-remove-duplication-from-form to hidden.

mattlc’s picture

Status: Needs work » Needs review

Fixed phpcs and phpstan errors.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Issues seems resolved and trait seems good to me.

Closed the other 2 MRs

quietone’s picture

Status: Reviewed & tested by the community » Needs work

Thanks everyone for getting this to RTBC. There is just one thing, which I commented on in the MR. I know naming can be a challenge but I do think the method needs a better name.

Anonymous’s picture

Assigned: Unassigned »
Anonymous’s picture

Assigned: » Unassigned
Status: Needs work » Needs review

Hi @quietone

I changed the name of the trait FileTestFormTrait to baseForm as instructed.
Please take a look

Thanks

ankitv18’s picture

Status: Needs review » Needs work

Minor suggestion regarding the naming convention of trait class ~~ hence moving back to NW.

Anonymous’s picture

Status: Needs work » Needs review

Hey @ankitv18,

Thanks for pointing out the mistake.
In #33, @quietone mentioned:

I think we need a better name here, one that doesn't have 'trait' in a method name.

I changed the trait name while I should have just changed the method name. I undid the unnecessary changes and changed the method name as suggested. Ran the tests and the pipeline is all green.

Thanks
Please review it now.

ankitv18’s picture

Status: Needs review » Reviewed & tested by the community

Looks good now ~~ marking this one RTBC

Anonymous’s picture

Rebased and updated fork to latest

Anonymous’s picture

The pipeline was run after rebasing and tests are all green - no errors!

  • quietone committed 7406530a on 11.1.x
    Issue #3368857 by ultimike, nico059, mattlc, akulsaxena, anand48,...

  • quietone committed dd5c7b57 on 11.x
    Issue #3368857 by ultimike, nico059, mattlc, akulsaxena, anand48,...
quietone’s picture

Version: 11.x-dev » 11.1.x-dev
Status: Reviewed & tested by the community » Fixed

@akulsaxena, Welcome to Drupal!

Committed to 11.x and cherry-picked to 11.1.x

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.