Problem/Motivation

In #3086794: Search results pages plugins could display results in administrative theme annotation introduced to display search results of help topics in admin theme
Because patches can't mix experimental and stable code this issue should add annotation to \Drupal\help_topics\Plugin\Search\HelpSearch plugin

Proposed resolution

Add annotation and update introduced test to ensure that search results of help topics displayed in administrative theme

Remaining tasks

- wait for commit of #3086794: Search results pages plugins could display results in administrative theme
- update test and patch
- reveiw and commit

User interface changes

search results of help topics displayed in administrative (configured) theme

API changes

no

Data model changes

no

Release notes snippet

CommentFileSizeAuthor
#37 3087879-36.patch1.86 KBandypost
#30 3087879-30.patch6.39 KBandypost
#30 interdiff.txt860 bytesandypost
#27 3087879-27.patch6.34 KBandypost
#27 interdiff.txt3.29 KBandypost
#23 3087879-23.patch6.27 KBandypost
#23 interdiff.txt992 bytesandypost
#21 3087879-21.patch6.26 KBandypost
#21 interdiff.txt1.24 KBandypost
#16 interdiff.txt5.74 KBandypost
#19 3087879-19.patch6.01 KBandypost
#11 3087879-11.patch3.41 KBandypost
#19 interdiff.txt725 bytesandypost
#11 interdiff.txt557 bytesandypost
#18 3087879-18.patch6.02 KBandypost
#8 3087879-8.patch3.41 KBandypost
#18 interdiff.txt1.46 KBandypost
#7 interdiff.txt2.33 KBandypost
#17 3087879-17.patch5.89 KBandypost
#8 interdiff.txt738 bytesandypost
#17 interdiff.txt1.63 KBandypost
#7 3087879-7.patch3.71 KBandypost
#2 3086794-13-follow-up-do-not-test.patch487 bytesandypost
#16 3087879-16.patch5.82 KBandypost
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andypost created an issue. See original summary.

andypost’s picture

jhodgdon’s picture

Title: Use admin theme annotation for help topics search » [PP-1] Use admin theme annotation for help topics search

Assuming that the patch from #13 on
#3086794: Search results pages plugins could display results in administrative theme
gets committed, I have already reviewed and tested this patch, so am +1 on marking this RTBC immediately after that gets committed.

We'll need to retest if a different patch gets committed though.

andypost’s picture

Title: [PP-1] Use admin theme annotation for help topics search » Use admin theme annotation for help topics search
Status: Postponed » Needs work

Parent commited, needs work for tests update

jhodgdon’s picture

Parent not actually committed yet, but we can still write tests. Keep in mind the test for this one has to stay in help topics module. Probably could add it to the existing Help Search test, as it would only add a line or two to that test?

andypost’s picture

Yes, just few lines

andypost’s picture

Version: 8.8.x-dev » 9.1.x-dev
Status: Needs work » Needs review
FileSize
2.33 KB
3.71 KB

Now blocker commited to 9.1

Here WIP patch and test extension idea to get how to unify the user permissions and can't recall what label test @TODO was for in comment #2 of #3086794-20: Search results pages plugins could display results in administrative theme

andypost’s picture

The last submitted patch, 7: 3087879-7.patch, failed testing. View results

jhodgdon’s picture

Issue tags: +Needs manual testing

This looks very good! I am +1 on RTBC, although I have not tested this manually to verify that help search does stay in the administration theme, so adding a "Needs manual testing" tag. (I believe the test is accurate, but I still think we should test it manually.)

One other idea: I think that when we get to the point of merging Help Topics into Help, we should also remove this separate test class, and add the help search to the base class SearchAdminThemeTest instead? We cannot do that now, because we don't want Experimental Module code mixed with the base code.

If that sounds like a good idea, then we need to add this to the final merge plan on
#3037230: Finalize the merge of Help Topics into Help
and/or make a sub-issue.

Thoughts?

andypost’s picture

jhodgdon’s picture

I'm only +1 on RTBC when the automated tests pass, and when someone does a manual test. Any thoughts on #10?

The last submitted patch, 8: 3087879-8.patch, failed testing. View results

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing

I just did a manual test, and the patch works as expected: searching Help results are shown in the admin theme.

RTBC assuming that the automated tests pass. We should still figure out about #10.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 11: 3087879-11.patch, failed testing. View results

andypost’s picture

Refactored test suite to allow contrib Configurable help to reuse the test as well

PS: it looks we can decouple node and user page-plugin tests out of search module later

andypost’s picture

FileSize
1.63 KB
5.89 KB

Improve docs a bit

andypost’s picture

FileSize
1.46 KB
6.02 KB

Do not create extra role if plugin does not require

andypost’s picture

FileSize
725 bytes
6.01 KB

CS clean-up and fix method name renamed in #16

jhodgdon’s picture

The code in this latest patch is exactly the same 1-line change as in the patch I tested manually, so that should still work.

The test code in help_topics module looks good -- very clean.

The additional/modified testing code in the search module is very nice and clearly written. It makes the code more reusable, and also adds tests for what happens if the user does not have permission to use the admin theme and the search plugin is supposed to use the admin theme (in which case it uses the default theme).

The only thing I would change is this documentation on the new method in the base test class:

+ * @return array
+ * Keyed array by $page_id of supported plugin and array of permissions to
+ * access the page content and expected admin theme requirement to allow
+ * the plugin to display results.
+ *
+ * @see \Drupal\search\SearchPageAccessControlHandler::checkAccess()
+ * @see \Drupal\search\Plugin\SearchInterface::usesAdminTheme()
+ */
+ protected function getSearchPagePlugins() {

I think the documentation should be:

Array whose keys are search page plugin IDs to test, and whose values are an associative array with two keys:
- use_admin_theme: (optional) TRUE if the admin theme should be used to display search results (default is FALSE).
- permissions: (optional) Array of permissions required for searching using this type of page. If omitted, the test verifies that this search plugin type has no access check.

andypost’s picture

FileSize
1.24 KB
6.26 KB

Fixed #20

jhodgdon’s picture

The last line of that documentation needs to be wrapped at 80 characters. Other than that, I think this is RTBC, unless you wanted to refactor the test in some way?

+   *   - permissions: (optional) Array of permissions required for searching
+   *     using this type of page. If omitted, the test verifies that this search plugin type has no access check.
andypost’s picture

FileSize
992 bytes
6.27 KB

Plugin can implement the interface https://git.drupalcode.org/project/drupal/-/blob/8.8.x/core/modules/sear...

That's why I mentioned it in

+++ b/core/modules/search/tests/src/Functional/SearchAdminThemeTest.php
@@ -102,4 +122,34 @@ protected function assertAdminTheme($is_admin) {
+   * @see \Drupal\search\SearchPageAccessControlHandler::checkAccess()
+   * @see \Drupal\search\Plugin\SearchInterface::usesAdminTheme()
+   */
+  protected function getSearchPagePlugins() {

most of plugins needs access check to nodes, users, topics

jhodgdon’s picture

OK, I think this is ready to go. Has been manually tested by me, the code looks good (1 line change), the test is comprehensive and the base test was improved.

Also added follow-up issue as part of roadmap #3144933: Add help_search plugin to the base admin theme test

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/help_topics/tests/src/Functional/SearchAdminThemeTest.php
    @@ -0,0 +1,33 @@
    +class SearchAdminThemeTest extends SearchAdminThemeTestBase {
    ...
    +        'permissions' => ['access administration pages'],
    

    Let's not call this SearchAdminThemeTest - then you don't need to rename the other class to base class.

    Also this get's a bit strange because we're adding the ['access administration pages'] permission but the underlying test adds and removes a role with that permission. I think this test inheritance is making things more complex that it should. I don't really support DRY principles in test code. It often makes it harder to understand what is actually being tested.

  2. +++ b/core/modules/search/tests/src/Functional/SearchAdminThemeTest.php
    @@ -65,25 +63,47 @@ public function testSearchUsingAdminTheme() {
    +    $role_admin_theme_access = $this->drupalCreateRole(['view the administration theme']);
    +    $account = $this->loggedInUser;
    ...
    +      if (isset($expected['permissions'])) {
    +        $this->assertInstanceOf(AccessibleInterface::class, $plugin);
    +        $role_plugin_access = $this->drupalCreateRole($expected['permissions']);
    +        $account->addRole($role_plugin_access);
    +      }
    +      else {
    +        $this->assertNotInstanceOf(AccessibleInterface::class, $plugin);
    +        $role_plugin_access = FALSE;
    +      }
    +      foreach ([TRUE, FALSE] as $admin_theme_access_allowed) {
    +        if ($admin_theme_access_allowed) {
    +          $account->addRole($role_admin_theme_access);
    +        }
    +        else {
    +          $account->removeRole($role_admin_theme_access);
    +        }
    +        $account->save();
    ...
    +      if ($role_plugin_access) {
    +        // Remove extra permissions to test next plugin with different set of
    +        // required permission.
    +        $account->removeRole($role_plugin_access);
    +      }
    

    Let's create a new account each time with the correct set of permissions. It'll be neater and less code and less to go wrong if this test is extended.

andypost’s picture

Status: Needs work » Needs review
FileSize
3.29 KB
6.34 KB

Here's changes to address #26

1) help topics are not stable, so we can't add its search plugin to search test. Renamed to HelpTopicSearchAdminThemeTest but we can have a follow-up to incorporate it into base test when topics will be stable

Moreover help topics heeds access administration pages to display topic but search using view the administration theme permission for theme tests. That's why add/remove role required in loop foreach ([TRUE, FALSE] as $admin_theme_access_allowed)

Also contrib (at least configurable help) can re-use the test for its plugin

2) extra permissions are needed when search plugin is of accessible interface (which is mostly entity view access), so removed optimization of test (it was idea to not create/login user as each plugin could have no extra permissions)

andypost’s picture

Status: Needs review » Needs work

The last submitted patch, 27: 3087879-27.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review
FileSize
860 bytes
6.39 KB

Fix permission addition

Test still fails on user search (not accessible now), probably caused by cache.

On sqlite locally I'm getting db locked exception running core/modules/help_topics/tests/src/Functional/HelpTopicSearchAdminThemeTest.php

Caused by
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 5 database is locked: UPDATE {users} SET "uuid"=:db_update_placeholder_0, "langcode"=:db_update_placeholder_1
WHERE "uid" = :db_condition_placeholder_0; Array
(
    [:db_update_placeholder_0] => 14a4673c-ab94-4ebd-9dad-bb261be06243
    [:db_update_placeholder_1] => en
    [:db_condition_placeholder_0] => 2
)

Status: Needs review » Needs work

The last submitted patch, 30: 3087879-30.patch, failed testing. View results

jhodgdon’s picture

The two errors I see in the test results are supposed to be verifying that the user can see the "more help with searching" links.

That's weird... those links have the exact same permissions as the parent search pages.

While looking at this, by the way, I noticed:

+        // Make sure help plugin rendered help link.
+        // @todo Test label in https://www.drupal.org/node/3086795

That @todo should be removed -- that issue is done and the label was tested.
#3086795: "Search help" link in search form is ambiguous and confusing

Actually I don't know why we are testing that this link is there in this patch. It is tested in that other issue with a clickLink. I think we can take these lines out of the test:

+        // Make sure help plugin rendered help link.
+        // @todo Test label in https://www.drupal.org/node/3086795
+        $path_help = $path . '/help';
+        $session->linkByHrefExists($path_help);

The point of this test is to verify that if you go to those pages, the admin theme is used or not used. I do not know why these lines are failing in this test, but I don't think we need to have them here and the other test verifies you can click the link.

andypost’s picture

The actual issue is that user search gives 403 on visit with new user

Initial idea of testing for "search help" to make sure that it also rendered in admin theme for any search plugin, because route subscriber affects both routes

jhodgdon’s picture

Oh, that's not good.

I agree we need to test that the search help page is rendered in the correct theme.

What I don't think we need to verify is that the search help link is present on the page. We could check that the response code when visiting both search and search help is 200.

Maybe to get around the 403 problem you could make all the needed user accounts in the setUp() function and then clear the cache? And make separate accounts with and without the role access. Cache stuff is annoying in tests often, and isn't that relevant when it comes to equating test results with how things actually behave on a real site.

andypost’s picture

Then we need to spin-up another follow-up to make test reusable and get rid of todo

jhodgdon’s picture

Couldn't the test have a similar for loop in the setUp that does something like this:

foreach ($this->getSearchPagePlugins() as $page_id => $expected) {
  $this->users[$page_id]['admin'] = ; // create user who can search and use admin theme
  $this->users[$page_id]['no admin'] = ; // create user who can search but not use admin theme
}
// clear cache

Then in the main test function, it could reference these users? I think it would still be reusable that way..

andypost’s picture

Status: Needs work » Needs review
FileSize
1.86 KB

Thinking a bit more about DRY and tests... it's search module's tests should test how admin_theme option works in integration.

So here's just kernel test to make sure plugin provides interfaces and has expected results

No interdiff because new patch

jhodgdon’s picture

That looks like a good course of action. You are right, the Search module is already verifying that search plugins that return TRUE for usesAdminTheme() actually use the admin theme for the search page and the help page. We also already have an issue to add HelpSearch into the existing Search admin test when we get out of Experimental for Help Topics, so we can integrate this plugin into that test then.

Assuming the tests pass, I have already manually tested the code change (see #24, and there has not been a change in the code since then).

So... I am +1 for RTBC assuming the tests pass.

andypost’s picture

Also filed follow-up for search module #3155221: Remove outdated todo and link to 3086795

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Sorry, I forgot to come back here and set this to RTBC. Had already reviewed the code, and manually tested in #24.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 33c16bf and pushed to 9.1.x. Thanks!

diff --git a/core/modules/help_topics/tests/src/Kernel/HelpSearchPluginTest.php b/core/modules/help_topics/tests/src/Kernel/HelpSearchPluginTest.php
index 297497a30e..eaea9fe2fc 100644
--- a/core/modules/help_topics/tests/src/Kernel/HelpSearchPluginTest.php
+++ b/core/modules/help_topics/tests/src/Kernel/HelpSearchPluginTest.php
@@ -7,7 +7,7 @@
 use Drupal\search\Plugin\SearchIndexingInterface;
 
 /**
- * Tests search plugin behaviours.
+ * Tests search plugin behaviors.
  *
  * @group help_topics
  *

Changed spelling to american spelling on commit.

  • alexpott committed 33c16bf on 9.1.x
    Issue #3087879 by andypost, jhodgdon, alexpott: Use admin theme...

Status: Fixed » Closed (fixed)

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