Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Follow-up to #2994904-37: Convert query('SELECT ... FROM {xxx}') to select('xxx')->... in tests
Core should not use direct db calls to entity tables because they are managed by the table mapper entity API.
Proposed resolution
All db_query()
and similar should be replaced with \Drupal::entityQuery()
or with injected entity storage, and updates/deletes should be done via the Entity API.
Remaining tasks
replace all usage
User interface changes
no
API changes
no
Data model changes
no
Comment | File | Size | Author |
---|---|---|---|
#18 | interdiff_16-18.txt | 1.4 KB | mondrake |
#18 | 3012599-18.patch | 17.54 KB | mondrake |
Comments
Comment #2
mondrakeJust a very first patch with one possible conversion, to see how it looks.
It's for
AggregatorCronTest
.Looking at the remaining code, I now see
and wonder if this is correct? Shouldn't this be managed via entity instead?
Comment #3
mondrakeAddressed all the 'count' queries from #2994904-39: Convert query('SELECT ... FROM {xxx}') to select('xxx')->... in tests,
There are way more to do...
Comment #4
andypostInteresting point, I thought to start with aggregator test base)
Btw IMO it makes sense to rework tests to use entity api, ircc there was isdues about it like replacement of entity_create()
Comment #5
andypostKinda #2928930: Properly deprecate entity_create() and remove all occurrences
But it looks like there should be a meta about to rewamp all entity usage)
Comment #6
andypostComment #8
mondrakeTrying going a bit more the Entity API way instead of the db way in the aggregator tests.
taxonomy_index
table is defined through the entity schema, but it's not an entity itself so reverting to use db calls.Still experimenting here.
Comment #10
mondrakeTry this.
Comment #11
mondrakeRe. #4:
then I think we need a meta and children since reworking tests like that is much bigger than just converting db calls.
Potential tests affected:
core\modules\aggregator\tests\src\Functional\FeedParserTest.php
core\modules\aggregator\tests\src\Functional\UpdateFeedItemTest.php
core\modules\block_content\tests\src\Functional\BlockContentSaveTest.php
core\modules\block_content\tests\src\Functional\BlockContentTranslationUITest.php
core\modules\content_moderation\tests\src\Functional\DefaultContentModerationStateRevisionUpdateTest.php
core\modules\file\tests\src\Functional\SaveUploadFormTest.php
core\modules\file\tests\src\Functional\SaveUploadTest.php
core\modules\file\tests\src\FunctionalJavascript\FileManagedFileElementTest.php
core\modules\node\tests\src\Functional\NodeAccessBaseTableTest.php
core\modules\node\tests\src\Functional\NodeAccessRecordsTest.php
core\modules\node\tests\src\Functional\NodeRevisionPermissionsTest.php
core\modules\node\tests\src\Functional\NodeRevisionsAllTest.php
core\modules\node\tests\src\Functional\NodeRevisionsTest.php
core\modules\node\tests\src\Functional\NodeTranslationUITest.php
core\modules\path\tests\src\Functional\PathTaxonomyTermTest.php
core\modules\taxonomy\tests\src\Functional\TermTranslationUITest.php
core\modules\user\tests\src\Kernel\UserInstallTest.php
Comment #12
mondrakeI’ll finish converting the aggregator module.
Comment #13
mondrakeThis is meant to convert all of direct db access (query/delete/update) to aggregator_feed and aggregator_item tables, to Entity API and Entity Query API.
Reverted the changes for TermIndexTest that no longer belong here.
I'd rather change this issue title to point to conversion of the two entities, and create a new meta of which this one should be a child.
Comment #15
mondrakeUpdated issue title and summary.
Comment #16
mondrakeAddressing failures.
Comment #18
mondrakeOne more. If this turns out green, it'd be ready for review.
Comment #19
mondrakeComment #20
volegerLooks good.
Comment #21
alexpottCan someone open a followup to remove queries against the node table in:
Committed 1da1c2b and pushed to 8.7.x. Thanks!
Comment #23
alexpottBackported to 8.6.x too as this is test only change. Committed b7ef221 and pushed to 8.6.x. Thanks!
Comment #25
andypostFollow-up filed #3014771: Replace queryRange call in AggregatorTestBase classes
Comment #26
mondrake