Problem/Motivation

Test coverage for UnpublishByKeywordComment action does not have UI but using functional test

Remaining comment actions are deprecated with
- https://www.drupal.org/node/2934349 (delete)
- https://www.drupal.org/node/2919303 (publish/unpublish/save)

Proposed resolution

Convert test to kernel test to speed-up tests execution

Remaining tasks

Patch/review/commit

Comments

naveenvalecha created an issue. See original summary.

naveenvalecha’s picture

Status: Active » Needs review
StatusFileSize
new4.47 KB

Cross posting the patch from #2526060-4: Add tests for action plugins

Status: Needs review » Needs work

The last submitted patch, 2: 2742997-2.patch, failed testing.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mradcliffe’s picture

Issue tags: +Dublin2016

This patch needs some work and probably needs a re-roll. The details for how to do so can be found in the parent issue linked in the issue summary.

johanv’s picture

I will write a summary for this issue. See https://www.drupal.org/contributor-tasks/write-issue-summary.

eyal shalev’s picture

Working on this during the Dublin sprints

wizonesolutions’s picture

Working on this with Eyal Shalev

johanv’s picture

Issue summary: View changes
eyal shalev’s picture

johanv’s picture

StatusFileSize
new4.51 KB

We fixed the naming issue, and we provided a name for the test user. Here is a new patch.

johanv’s picture

Status: Needs work » Needs review
wizonesolutions’s picture

@johanv and @Eyal Shalev worked on this patch together.

eyal shalev’s picture

StatusFileSize
new4.52 KB

.

The last submitted patch, 11: 2742997-11.patch, failed testing.

johanv’s picture

StatusFileSize
new5.66 KB

We (wizonesolutions, Eyal Shalev and me) split up the test into 5 tests. We tested it locally, and it still works.

mmrares’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/comment/src/Tests/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    + * @file
    

    @file isn't required.

  2. +++ b/core/modules/comment/src/Tests/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    +    // Create format without filters to prevent filtering
    

    Missing full stop.

  3. +++ b/core/modules/comment/src/Tests/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    +   * @param array $keywords
    

    Missing parameter comment.

  4. +++ b/core/modules/comment/src/Tests/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    +   * @return \Drupal\Core\Action\ActionInterface
    

    Description for return value is missing and separate @param and @return sections by a blank line.

  5. +++ b/core/modules/comment/src/Tests/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    +    return $action_stored;
    

    Check the type of @return value

  6. +++ b/core/modules/comment/src/Tests/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    +  }
    

    An empty line before class end.

mmrares’s picture

Tests ran successfully on local environment.

wizonesolutions’s picture

StatusFileSize
new0 bytes

Here is the revised patch. No logic changes, so if the tests in #16 pass, and this is otherwise good, I think we should RTBC this :)

johanv’s picture

You uploaded an empty patch :-)

wizonesolutions’s picture

StatusFileSize
new5.77 KB
wizonesolutions’s picture

johanv’s picture

Status: Needs work » Needs review
johanv’s picture

I have to leave now. I reviewed the latest patch, it handles the comments of mmrares. So if the test bot does not find any problems, I think this is RTBC.

wizonesolutions’s picture

StatusFileSize
new5.77 KB

Fixed file comment.

condor616’s picture

Status: Needs review » Reviewed & tested by the community

I confirm that issues from #17 are resolved in the patch #25
There are no logic changes and test in #16 passed so this will still pass

mradcliffe’s picture

@wizonesolutions, @johanv. One thing that helps when creating new patches is to create an interdiff so that we can see the specific changes between patches. See https://www.drupal.org/documentation/git/interdiff

wizonesolutions’s picture

StatusFileSize
new5.77 KB
new1011 bytes

Fixing inconsistent whitespace and ensuring test method docblocks start with a third-person verb per IRC comment by @YesCT.

No code changes, so tests will still pass.

@condor616 reviewed this live as I wrote it.

mile23’s picture

Just a nit here, not enough to un-rtbc.

+++ b/core/modules/comment/src/Tests/Action/CommentActionsKernelTest.php
@@ -0,0 +1,193 @@
+    \Drupal::currentUser()->setAccount($account);
...
+    \Drupal::service('router.builder')->rebuild();

All usages of \Drupal should be $this->container.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 28: 2742997-28.patch, failed testing.

The last submitted patch, 28: 2742997-28.patch, failed testing.

erozqba’s picture

Status: Needs work » Needs review
StatusFileSize
new5.79 KB
new877 bytes

Applying the changes suggested by Mile23

mradcliffe’s picture

+++ b/core/modules/comment/src/Tests/Action/CommentActionsKernelTest.php
@@ -74,7 +74,7 @@
-    $this->container->get('current_user')->setAccount($account);
+    \Drupal::currentUser()->setAccount($account);

@@ -83,7 +83,7 @@
-    $this->container->get('router.builder')->rebuild();
+    \Drupal::service('router.builder')->rebuild();

The interdiff is the reverse. Interdiffs are created in format:

interdiff <previous patch> <next patch>.

I reviewed the patch manually and \Drupal:: is indeed removed in favor of $this->container->get.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

erozqba’s picture

StatusFileSize
new5.79 KB
new877 bytes

Submit a new patch to be tested against 8.4.x and with a fixed interdiff.

Status: Needs review » Needs work

The last submitted patch, 35: 2742997-35.patch, failed testing.

erozqba’s picture

Status: Needs work » Needs review

The last submitted patch, 35: 2742997-35.patch, pass testing.

naveenvalecha’s picture

StatusFileSize
new800 bytes
new5.75 KB

How about the test in this namespace?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

The new test looks good and it seems to be in the correct namespace.

alexpott’s picture

Title: Add Unit tests for comment action plugins » Add tests for comment action plugins

It's a kernel test not a unit test.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/comment/tests/src/Kernel/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    +    $action = Action::load('comment_save_action');
    +    $action->execute([$this->comment]);
    +    $this->assertFalse($this->comment->isNew(), 'Comment saved');
    

    This should assert the comment is new before executing the action.

  2. +++ b/core/modules/comment/tests/src/Kernel/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    +    $this->comment->save();
    +    // Test comment_unpublish_by_keyword_action for comment body.
    +    $action_stored = $this->createUnpublishByKeywordAction([$this->keyword2]);
    +    $action_stored->execute([$this->comment]);
    +    $this->assertFalse($this->comment->isPublished(), 'Comment unpublished by body keyword');
    

    This should assert the comment is published after saving.

  3. +++ b/core/modules/comment/tests/src/Kernel/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    +    $this->comment->save();
    +
    +    // Test comment_publish_action.
    +    $action = Action::load('comment_publish_action');
    +    $action->execute([$this->comment]);
    +    $this->assertTrue($this->comment->isPublished(), 'Comment published');
    

    This needs to assert the comment is not published after saving.

  4. +++ b/core/modules/comment/tests/src/Kernel/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    +    $this->comment->save();
    +
    +    // Test comment_unpublish_action.
    +    $action = Action::load('comment_unpublish_action');
    +    $action->execute([$this->comment]);
    +    $this->assertFalse($this->comment->isPublished(), 'Comment unpublished');
    

    This needs to assert that the comment is published after saving.

  5. +++ b/core/modules/comment/tests/src/Kernel/Action/CommentActionsKernelTest.php
    @@ -0,0 +1,189 @@
    +    $this->comment->save();
    +    $action_stored = $this->createUnpublishByKeywordAction([$this->keyword2]);
    +    // Test comment_unpublish_by_keyword_action for comment subject.
    +    $action_stored
    +      ->set('configuration', ['keywords' => [$this->keyword1]])
    +      ->save();
    +    $this->comment->setPublished(TRUE);
    +    $action_stored->execute([$this->comment]);
    +    $this->assertFalse($this->comment->isPublished(), 'Comment unpublished by subject');
    

    This needs to test that the comment is published before triggering the action. Also I'd expect a test to ensure the is the comment doesn't contain the keyword this action doesn't unpublish the comment. Plus what is the difference between testCommentUnPublishByKeywordAction and testUnpublishByKeywordAction?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

MerryHamster’s picture

StatusFileSize
new0 bytes

Reroll patch from #38 for 8.7.x
Still, need to add all notices from #43

MerryHamster’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 45: 2742997-45.patch, failed testing. View results

MerryHamster’s picture

StatusFileSize
new5.75 KB

Reroll patch from #38 for 8.7.x
Still, need to add all notices from #43

MerryHamster’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 48: 2742997-48.patch, failed testing. View results

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vacho’s picture

StatusFileSize
new5.62 KB
new2.31 KB

Adding proposal in #43 to patch.

andypost’s picture

Title: Add tests for comment action plugins » Convert CommentActionsTest to kernel test
Assigned: Unassigned » andypost

This test needs clean-up because save/delete/publish/unpublish actions already tested because they are now core ones.
Moreover module's actions are deprecated except \Drupal\comment\Plugin\Action\UnpublishByKeywordComment one

Also there's already functional test which better to convert to kernel one based on patch here

andypost’s picture

Assigned: andypost » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new7.94 KB

Converted, changed test to test the only action and all ones shipped by default configured
The functional test us removed

andypost’s picture

Actions to save/delete use own tests, the same as [un]publish are using only kernel tests

larowlan’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/comment/tests/src/Kernel/CommentActionsTest.php
    @@ -0,0 +1,159 @@
    +    $account = User::create([
    +      'name' => 'test user',
    +    ]);
    +    $account->save();
    +    $this->container->get('current_user')->setAccount($account);
    

    We have a method on UserCreationTrait for this now

  2. +++ b/core/modules/comment/tests/src/Kernel/CommentActionsTest.php
    @@ -0,0 +1,159 @@
    +    $this->keywords = [$this->randomMachineName(), $this->randomMachineName()];
    

    any reason to make this a class property? can't we just use inline variables in the second method?

andypost’s picture

Status: Needs work » Needs review

Fixed #56.1 using trait from parent class

About #56.2 test needs this keywords in setup (create comment with keywords) and test method

andypost’s picture

StatusFileSize
new1.14 KB
new7.82 KB
krzysztof domański’s picture

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

tvb’s picture

StatusFileSize
new7.89 KB
new819 bytes

Patch could not be applied cleanly to 8.9.x-dev.

Rerolled patch 2742997-58.patch.

It was not an auto merge. See diff of two most recent patches for details: reroll_diff_58-61.txt.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

daffie’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new1.98 KB
new7.79 KB

Rerolled

daffie’s picture

Status: Needs review » Needs work

The patch looks good. Just one minor request:

+++ b/core/modules/comment/tests/src/Kernel/CommentActionsTest.php
@@ -0,0 +1,153 @@
+    $action = Action::load('comment_delete_action');
+    $action->execute([$this->comment]);

Can we add an assertion that This->comment has been deleted.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new864 bytes
new8.11 KB

There's no actual delete happens, that's why previous test missing this hunk (already covered by comment-admin list-builder and views test)

So just make sure the valid values are stored in tempstore is enough

+++ b/core/modules/comment/tests/src/Kernel/CommentActionsTest.php
@@ -0,0 +1,153 @@
+    $action = Action::load('comment_delete_action');
+    $action->execute([$this->comment]);
+    /** @var \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store */
+    $temp_store = $this->container->get('tempstore.private');
+    $account_id = $this->container->get('current_user')->id();
+    $store_entries = $temp_store->get('entity_delete_multiple_confirm')->get($account_id . ':comment');
+    $this->assertSame([$account_id => ['en' => 'en']], $store_entries);

That's what the action is doing, it prepares tempstore with ID's to delete.
The hunk specifically added to cover case of delete action.

See \Drupal\Core\Action\Plugin\Action\Derivative\EntityDeleteActionDeriver::getDerivativeDefinitions()

andypost’s picture

Btw there's only \Drupal\comment\Plugin\Action\UnpublishByKeywordComment action left in comment module, so delete test could be removed

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

@andypost: Thank you for the explanation.

All changes now look good to me.
For me it is RTBC.

  • catch committed 16ba314 on 9.3.x
    Issue #2742997 by andypost, wizonesolutions, erozqba, naveenvalecha,...

  • catch committed ed76b6e on 9.2.x
    Issue #2742997 by andypost, wizonesolutions, erozqba, naveenvalecha,...
catch’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.3.x and cherry-picked to 9.2.x, thanks!

Status: Fixed » Closed (fixed)

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