Problem/Motivation

Currently, all tests in taxonomy module use entity_create() to create nodes. The entity_create() function is meant to be used in the case of not knowing what type of entity, or having the the type of entity in a variable.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue priority Minor because it is isolated to taxonomy related tests.
Unfrozen changes Unfrozen because it only changes tests.

Allowed in beta because it only changes tests.

Proposed resolution

We should use the injected entity storage where is available or inject it and instead of entity_create('taxonomy_vocabulary', $values) write something like: $vocabulary_storage->create($values);

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Reroll the patch if it no longer applies. Instructions
Update the issue summary Instructions
Update the issue summary noting if allowed during the beta Instructions

User interface changes

None.

API changes

None.

Comments

rosinegrean’s picture

Issue summary: View changes

I'll work on this

rosinegrean’s picture

Assigned: Unassigned » rosinegrean
Issue summary: View changes
rosinegrean’s picture

Status: Active » Needs review
StatusFileSize
new28.12 KB

Changed entity_create from all tests.

Status: Needs review » Needs work

The last submitted patch, 3: drupal8-taxonomy-tests-entity-create-2346253-3.patch, failed testing.

rosinegrean’s picture

Status: Needs work » Needs review
StatusFileSize
new28.13 KB

skipyT’s picture

Status: Needs review » Needs work

this look ok for me, but I don't understand why do we want to use the static functions for create here if for load (#2322509) we are trying to inject the entity storage and to use the entity storage function instead.

I think we should try to use the injected entity storage where is available and instead of Vocabulary::create write something like: $vocabulary_storage->create($values);

rosinegrean’s picture

Status: Needs work » Needs review
StatusFileSize
new32.27 KB
new35.23 KB

Changed static create.

skipyT’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: drupal8-taxonomy-tests-entity-create-2346253-8.patch, failed testing.

lhangea’s picture

Reroll for the patch from comment #8

lhangea’s picture

Assigned: rosinegrean » Unassigned
Status: Needs work » Needs review
yesct’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll, +Needs issue summary update

needs beta evaluation

vedpareek’s picture

Rerolled

vedpareek’s picture

Status: Needs work » Needs review
StatusFileSize
new29.43 KB

Rerolled

Status: Needs review » Needs work

The last submitted patch, 15: 2346253_15.patch, failed testing.

Saphyel’s picture

Assigned: Unassigned » Saphyel
Saphyel’s picture

Assigned: Saphyel » Unassigned
lhangea’s picture

yesct’s picture

Status: Needs work » Needs review

setting to needs review status so that the testbot runs on it.

The last submitted patch, 14: 2346253_14.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 19: drupal8-taxonomy-tests-entity-create-2346253-19.patch, failed testing.

yesct’s picture

Issue tags: +Amsterdam2014, +Needs issue summary update
StatusFileSize
new8.64 KB

restoring tags accidentally removed in #14

@lhangea Thank you for fixing some of those fails.
Since the patch before yours applied to head, you can make an interdiff.
This will help people learn how you fixed the fails, and also make it more likely someone will review the patch.

For instructions on creating an interdiff, see https://drupal.org/documentation/git/interdiff

It also really helps to describe in words why you made the changes you did.
(for example I think you fixed some coding standards stuff along with test fail fixes)

lhangea’s picture

I uploaded a new patch which should be ok now and the interdiff (vs #15).

The changes can be seen pretty clear from the interdiff but basically there are small coding standard fixes, variable name changes and in some places I replaced the old static functions with methods of the injected objects.

lhangea’s picture

Status: Needs work » Needs review
yesct’s picture

+++ b/core/modules/taxonomy/src/Tests/LegacyTest.php
@@ -26,16 +26,19 @@ class LegacyTest extends TaxonomyTestBase {
+    $vocabulary_storage = $this->container->get('entity.manager')->getStorage('taxonomy_vocabulary');
+    $field_config_storage = $this->container->get('entity.manager')->getStorage('field_config');
+    $field_storage_config_storage = $this->container->get('entity.manager')->getStorage('field_storage_config');
 

adding those lines, essencially removed the newline under setup.

I was also super tempted to try

    /** @var \Drupal\taxonomy\VocabularyInterface $vocabulary_storage */
    $vocabulary_storage = $this->container->get('entity.manager')->getStorage('taxonomy_vocabulary');
    /** @var \Drupal\field\FieldConfigInterface $field_config_storage */
    $field_config_storage = $this->container->get('entity.manager')->getStorage('field_config');
    /** @var \Drupal\field\FieldStorageConfigInterface $field_storage_config_storage */
    $field_storage_config_storage = $this->container->get('entity.manager')->getStorage('field_storage_config');

Why not type, so that ->create() is known to be a method?

yesct’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update

on second thought, I think this is fine.

with patch applied,
ag entity_create core/modules/taxonomy
does not show any usages of entity_create in taxonomy tests, so this got them all.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

We changed direction in #7 but the IS has not been updated. I'm not convinced by Node::create() in a test is worse that getting the storage from the entity manager - but whatever as this hardly matters.

rosinegrean’s picture

Issue summary: View changes
Status: Needs work » Needs review
rosinegrean’s picture

Issue summary: View changes
mile23’s picture

Status: Needs review » Closed (duplicate)

This is a duplicate of the various taxonomy-related child issues here: #2490966: [Meta] Replace deprecated usage of entity_create with a direct call to the entity type class

Thanks, folks!