Comments

mikelutz created an issue. See original summary.

mikelutz’s picture

Baseline, triggering an error but not removing usages.

mikelutz’s picture

Assigned: mikelutz » Unassigned
Status: Needs work » Needs review
StatusFileSize
new17.17 KB
new15.01 KB

First attempt at testbot fodder.

berdir’s picture

  1. +++ b/core/modules/comment/tests/src/Functional/CommentNodeChangesTest.php
    @@ -27,7 +27,7 @@ public function testNodeDeletion() {
         $this->assertNotNull(FieldConfig::load('node.article.comment'), 'Comment field exists');
         // Delete the node type.
    -    entity_delete_multiple('node_type', [$this->node->bundle()]);
    +    \Drupal::entityTypeManager()->getStorage('node_type')->load($this->node->bundle())->delete();
         $this->assertNull(FieldStorageConfig::load('node.comment'), 'Comment field storage deleted');
    

    $this->node->get('type')->entity->delete() should work too for this.

    The whole thing is a bit weird though, was $this->node already deleted?

  2. +++ b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php
    @@ -290,7 +290,8 @@ public function testShortcutLinkDelete() {
         // Delete all the remaining shortcut links.
    -    entity_delete_multiple('shortcut', array_filter($ids));
    +    $storage = $this->container->get('entity_type.manager')->getStorage('shortcut');
    +    $storage->delete($storage->loadMultiple(array_filter($ids)));
    

    why sometimes $this->container and sometimes \Drupal::entityTypeManager(), I'd always use the second.

  3. +++ b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php
    @@ -31,7 +31,6 @@ protected function setUp() {
     
       /**
        * Deleting terms should also remove related vocabulary.
    -   * Deleting an invalid term should silently fail.
        */
       public function testTermDelete() {
         $vocabulary = $this->createVocabulary();
    @@ -40,9 +39,6 @@ public function testTermDelete() {
    
    @@ -40,9 +39,6 @@ public function testTermDelete() {
         $valid_term->delete();
         $terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]);
         $this->assertTrue(empty($terms), 'Vocabulary is empty after deletion');
    -
    -    // Delete an invalid term. Should not throw any notices.
    -    entity_delete_multiple('taxonomy_term', [42]);
       }
    

    I'm not sure what this is testing, but that description is weird. We definitely don't delete vocabularies when you delete terms, what it is testing is that there are no other terms in that vocabulary, not sure what the point of that is though.

  4. +++ b/core/modules/user/user.module
    @@ -879,7 +879,9 @@ function user_delete($uid) {
      */
     function user_delete_multiple(array $uids) {
    -  entity_delete_multiple('user', $uids);
    +  $user_storage = \Drupal::entityTypeManager()->getStorage('user');
    +  $users = $user_storage->loadMultiple($uids);
    

    lets just @deprecate this function too?

Status: Needs review » Needs work
mikelutz’s picture

1) It wasn't but the purpose of the test is only to show that deleting a bundle deletes the comment field configs too, so I guess it doesn't care.
2) I've never found an answer to $this->container vs \Drupal::service in tests. #2066993: Use magic methods to sync container property to \Drupal::getContainer in functional tests is one of my favorite issues, as the IS says one thing, the issue title says another and the comments come to no final conclusion. Personally I use \Drupal::service in Functional and Javascript tests and $this->container in kernel tests for absolutely no justifiable reason, and even with that I missed the one you linked because I should have used \Drupal to be consistent with myself.
3) No clue. The part I removed seemed to be testing that entity_delete_multiple didn't throw an error if you passed it an invalid entity id, so I just removed that part. I changed the remaining test comment, but I'm not convinced that it tests anything other than if the term is deleted, then the term is deleted..
4) Opened #3051455: Deprecate user_delete and user_delete_multiple as a followup. At fast glance, user_view and user_view_multiple should probably be deprecated as well, and maybe a few more procedural wrappers in that file.

alexpott’s picture

Personally I use \Drupal::service in Functional and Javascript tests and $this->container in kernel tests for absolutely no justifiable reason

There is a reason this is a logical approach. $this->container is maintained in kernel tests to be in-sync with the real container - there is a listener that keeps it updated. In Functional tests \Drupal is updated more often than $this->container (both however are not great - but \Drupal looks worse and therefore is preferable because it reminds us we're doing something we shouldn't :) )

mikelutz’s picture

Per conversation with Berdir I'm closing #3051455: Deprecate user_delete and user_delete_multiple and rolling those deprecations into this patch.

jibran’s picture

Just one tit bit.

+++ b/core/includes/install.core.inc
@@ -1698,7 +1698,10 @@ function install_download_additional_translations_operations(&$install_state) {
+      $en = ConfigurableLanguage::load('en');
+      if ($en) {
+        $en->delete();

Variable name is not correct and it can be one line if($lang= ConfigurableLanguage::load('en'));.

mikelutz’s picture

I'm really not a fan of assignments inside of conditionals, but here you go.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed c210fad and pushed to 8.8.x. Thanks!

  • larowlan committed c210fad on 8.8.x
    Issue #3051069 by mikelutz, jibran, Berdir: Remove usage of deprecated...

Status: Fixed » Closed (fixed)

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

voleger’s picture