This issue refactors logic out of WebTestBase and ImageFieldTestBase and into a new trait, which can be shared among both WebTestBase and BrowserTestBase tests.

This issue blocks #2421427: Improve the UX of Quick Editing single-valued image fields, which includes tests that extend JavascriptTestBase, and as a result cannot use the current test bases to easily get test files or create Image fields.

Comments

samuel.mortenson created an issue. See original summary.

klausi’s picture

Status: Needs review » Needs work

Yes please! Some minor stuff:

  1. index 0000000..3af9617
    --- /dev/null
    
    --- /dev/null
    +++ b/core/modules/image/src/Tests/ImageFieldCreationTrait.php
    

    We don't want to create new test related files in the src/Tests folder of a module because this is the old deprecated Simpletest location. Any test related stuff should be in tests/src.

  2. +++ b/core/modules/image/src/Tests/ImageFieldCreationTrait.php
    @@ -0,0 +1,68 @@
    +  function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array(), $formatter_settings = array(), $description = '') {
    

    visibility of the function is missing, I think this should be "protected", right?

  3. +++ b/core/modules/image/src/Tests/ImageFieldTestBase.php
    index 0000000..d919377
    --- /dev/null
    
    --- /dev/null
    +++ b/core/modules/simpletest/src/TestFilesTrait.php
    

    I'm not happy that we create new stuff in the deprecated simpletest module, but since it calls simpletest_*() functions I guess this is ok for now.

samuel.mortenson’s picture

Status: Needs work » Needs review
StatusFileSize
new13.65 KB
new4.55 KB

Addressed notes from #2.

Status: Needs review » Needs work

The last submitted patch, 3: file-trait-refactor-2782309-3.patch, failed testing.

samuel.mortenson’s picture

Status: Needs work » Needs review
StatusFileSize
new13.66 KB

Re-roll.

catch’s picture

dawehner’s picture

This issue contains some bits from #2738567: Add test trait for drupalGetTestFiles and drupalCompareFile, so we maybe should postpone it for now?

samuel.mortenson’s picture

There will probably be collisions with that issue as #2421427: Improve the UX of Quick Editing single-valued image fields is RTBC'd now, and includes this change.

dawehner’s picture

@samuel.mortenson
Do you mind rerolling your patch with the trait from the other issue?

samuel.mortenson’s picture

Sure, I can do that and update the issue references.

samuel.mortenson’s picture

Actually the "ImageFieldCreationTrait" doesn't exist in that other issue, so it's not as easy as re-rolling the Quick Edit UX issue to use #2738567: Add test trait for drupalGetTestFiles and drupalCompareFile. What's the best way to proceed here?

dawehner’s picture

Well, apply the other patch locally and try to write the ImageFieldCreationTrait on top of it :)

samuel.mortenson’s picture

Status: Needs review » Closed (duplicate)

Done, sorry for the delay. I'm closing this as a duplicate and updating the Quick Edit Image issue.

samuel.mortenson’s picture

Status: Closed (duplicate) » Needs work

Moving back to Needs work, as the "ImageFieldCreationTrait" isn't covered by the other issue. When #2738567: Add test trait for drupalGetTestFiles and drupalCompareFile is committed, I'll re-roll the patch to only include that trait and move the issue back to Needs review.

samuel.mortenson’s picture

Title: Refactor File and Image related test logic into new traits » Refactor File and Image related image field creation logic into a new trait
Issue summary: View changes
StatusFileSize
new5.14 KB

Re-roll to only include the trait not already added in #2738567: Add test trait for drupalGetTestFiles and drupalCompareFile.

samuel.mortenson’s picture

Status: Needs work » Needs review
martin107’s picture

Status: Needs review » Reviewed & tested by the community

The idea behind the issue is good.

Patch is clean. in that it does what is stated and nothing else.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: file-trait-refactor-2782309-15.patch, failed testing.

martin107’s picture

Assigned: Unassigned » martin107

My mistake

Trait 'Drupal\image\Tests\ImageFieldCreationTrait' not found in /var/www/html/core/modules/image/src/Tests/ImageFieldTestBase.php on line 25

I will fix this up.

samuel.mortenson’s picture

Thanks @martin107! I'll leave it to you.

martin107’s picture

Assigned: martin107 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new5.22 KB
new1.03 KB

@samuel.mortenson - Ah you are welcome.

My preferred home in the namespace tree was

1. Drupal\Tests\image\ImageFieldCreationTrait
2. Drupal\Tests\image\Traits\ImageFieldCreationTrait

but the PSR autoloader does not seems to be that flexible.

So I went with the next best

Drupal\Tests\image\Kernel\ImageFieldCreationTrait

If anyone has better suggestions ... my solution seems like a cludge!

dawehner’s picture

Drupal\Tests\image\Kernel\ImageFieldCreationTrait

Well, maybe we should add an issue about it?

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Beside from that though, this looks pretty nice

dawehner’s picture

I'm wondering whether we should have dedicated tests for this new trait.

martin107’s picture

I have opened a side issue for a better home for the trait.

martin107’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5.31 KB
new1.53 KB

A minor nudge added an optional prefix to some @params in the new trait

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @martin107

wim leers’s picture

Priority: Normal » Major
Issue tags: +blocker
alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +rc eligible

As a simple code move in tests this is rc eligible. Committed and pushed 66741e3 to 8.3.x and 18da006 to 8.2.x. Thanks!

  • alexpott committed 66741e3 on 8.3.x
    Issue #2782309 by samuel.mortenson, martin107: Refactor File and Image...

  • alexpott committed 18da006 on 8.2.x
    Issue #2782309 by samuel.mortenson, martin107: Refactor File and Image...

Status: Fixed » Closed (fixed)

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