Problem/Motivation
Creating a node with a entity reference field refer to a file got an error (on js console):
Fatal error: Call to a member function range() on a non-object in /core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php on line 184
Steps To Reproduce
Create a content type "File", with a file field "File"

Add some contents to "File"

Add reference field "File Reference" to "Article", then set "Type of item to reference" to "File" ("File" entity type, not "Content" entity type with bundle "File")


Open javascript console, then add new "Article"

Expected: autocomple work, with a list of file including sample.jpg
Actual: autocomple does not work, with an error:

| Comment | File | Size | Author |
|---|---|---|---|
| #38 | 2353881-nr-bot.txt | 91 bytes | needs-review-queue-bot |
Issue fork drupal-2353881
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:
- 2353881-add-test-coverage
changes, plain diff MR !12264
Comments
Comment #1
tien.xuan.vo commentedHere is a fix. Bellow is the autocomple results after apply the patch:

Comment #2
tien.xuan.vo commentedChange status
Comment #3
primsi commentedReproduced the error, applied patch and tested.
Comment #4
alexpottNice find. We should be able to add an automated test for this.
Comment #5
tien.xuan.vo commentedHere is the patch that contains tests. Please review it for me.
Comment #6
berdirI didn't know about this issue, recently got a fix in that didn't add tests however. Changing this to a task to add those tests.
Comment #7
vedpareek commentedRerolled
Comment #9
sharique commentedentity_create is deprecated.
entity_create is deprecated.
This causing test to fail.
entity_create is deprecated.
Comment #10
rpayanmPlease review.
Comment #12
sharique commentedFatal error: Class 'Drupal\Component\Utility\String' not found in /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/file/src/Tests/FileSelectionTest.php on line 65
Comment #13
googletorp commentedComment #14
rpayanmComment #26
smustgrave commentedThis seems outdated and possibly a reroll.
Comment #27
ravi.shankar commentedPatch #14 doesn't needed reroll, I've fixed Drupal CS issues of patch #14.
Comment #28
smustgrave commentedDid you test this?
Comment #30
smustgrave commentedThinking I got tickets crossed in #28?
But ran #27 for D10 tests and had CI failures.
Comment #34
mohit_aghera commented- Updated a new kernel test to validate the entity query results.
- Using other general practices for creating fields etc.
Code is already fixed so no changes are required in EntityReference handler plugin.
Hiding existing patches in favour of MR.
Tests are passing on local.
Comment #35
smustgrave commentedThanks for working on this!
Test failures seem related to this change.
Comment #36
mohit_aghera commentedMR is green now.
Moving back to NR
Comment #37
smustgrave commentedThanks for fixing that, seems like good test coverage. LGTM.
Comment #38
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #39
mohit_aghera commentedMoving back to RTBC since the MR is already green.
Comment #40
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #41
mohit_aghera commentedUpdated the branch with latest 11.x
Though "needs-review-queue-bot" commented, however, I didn't noticed any merge conflicts though.
Comment #42
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #43
mohit_aghera commentedUpdated branch with latest 11.x
MR is green.
Moving back to RTBC again.
Comment #45
alexpottCommitted f795f24 and pushed to 11.x. Thanks!
Comment #47
catchPushed a commit to switch from the phpunit annotation to attribute to unbreak head.
Comment #49
nicxvan commentedThis broke head there is an annotation.
Edit, I missed it was already fixed