Currently, our Views filter/argument plugins for taxonomy terms are completely untested, as far as I can see. It would be great to remedy that situation (of course).
As our normal ViewsTest doesn’t even include the Taxonomy module, let alone provide adequate test content, we should probably add this as a completely new test class instead. (Maybe even testing the admin UI, as for ViewsTest – but the user-facing functionality is the clear priority here.)

Comments

drunken monkey created an issue. See original summary.

legolasbo’s picture

Assigned: Unassigned » legolasbo

Working on this

legolasbo’s picture

Status: Active » Needs review
StatusFileSize
new3.29 KB

Attached patch adds coverage for the SearchApiTerm argument plugin.

borisson_’s picture

Assigned: legolasbo » Unassigned
Status: Needs review » Reviewed & tested by the community

I think testing this with a kernel test is sufficient, I don't think we should add an integration test for this as well.

legolasbo’s picture

StatusFileSize
new838 bytes
new3.34 KB

I noticed there were some coding standards violations in my patch. This patch fixes that. Leaving the issue at RTBC since the change is so minor.

borisson_’s picture

+++ b/tests/src/Kernel/Plugin/views/argument/SearchApiTermTest.php
@@ -0,0 +1,113 @@
+   * @var \Drupal\taxonomy\Entity\Vocabulary
+   *  The test vocabulary.

I think this should be in the other direction, ie:

The test vocabulary
@var ...

legolasbo’s picture

StatusFileSize
new582 bytes
new3.35 KB

You're right!

drunken monkey’s picture

Status: Reviewed & tested by the community » Needs work

Thanks a lot for your work, looks pretty good already!
Just two small complaints:

+++ b/tests/src/Kernel/Plugin/views/argument/SearchApiTermTest.php
@@ -0,0 +1,114 @@
+namespace Drupal\tests\search_api\Kernel\Plugin\views\argument;

I think this should just be called SearchApiTermArgumentTest and live in the (existing) Drupal\tests\search_api\Kernel\Views namespace. Adding three levels of namespace with just a single class doesn’t seem sensible.
If we get enough test classes for single plugins, we can still move them to a sub-namespace later.

+++ b/tests/src/Kernel/Plugin/views/argument/SearchApiTermTest.php
@@ -0,0 +1,114 @@
+    self::assertNull($plugin->title());

I know it’s a static method, but assertions are still called dynamically (i.e., via $this->assert_()) nearly exclusively. For consistency, I’d therefore also prefer this here. (Same for all other assertions.)

I think testing this with a kernel test is sufficient, I don't think we should add an integration test for this as well.

I disagree, with this issue I actually had an integration test in mind. We now have three different taxonomy-related Views plugins, it would have seemed sensible adding a single integration test for all of them, like we have one for most other plugins in ViewsTest::testView().
Getting coverage through Kernel tests is of course also great, but since in this case we override just a single method, it’s clear that this has no chance of uncovering all problems we might run into in the future. This depends a lot on Views internals, our own traits, etc., and I think we make sure the overall functionality remains working, not just the one method we actually override in the plugin classes (two, now, with SearchApiAllTerms).

So, while I’ll surely also commit this Kernel test, I wouldn’t consider this issue fixed until we have an integration test for at least part of this functionality. It shouldn’t be too difficult, just needs a test setup that also includes taxonomy terms.

legolasbo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.95 KB
new3.32 KB

Feedback addressed.

drunken monkey’s picture

StatusFileSize
new3.17 KB
new3.84 KB

Alright, thanks!
Then just a few nit-picks on my part. If those are fine with you, I’ll commit this (and set back to “Active“ for the integration test – if I remember).

legolasbo’s picture

Status: Needs review » Reviewed & tested by the community

Nits are fine by me :)

drunken monkey’s picture

Status: Reviewed & tested by the community » Active

Alright, committed.
Thanks again!

Setting back to “Active” for the integration test.