Currently, very little logic of the Admin Toolbar Tools' class \Drupal\admin_toolbar_tools\Plugin\Derivative\ExtraLinks
is being covered by automated tests.
The file is more than 800 lines long 😅, with one very large method:
\Drupal\admin_toolbar_tools\Plugin\Derivative\ExtraLinks::getDerivativeDefinitions()
containing a lot of cases and pieces of logic allowing to add extra links to the admin menu, such as all the extra links under 'Structure' for content entities, Edit, Manage display, Manage fields, etc...
It seems the function has grown with the superposition of layers of code, with duplications or redundancy and could use some refactoring at some point, see for example:
The 'Add {entity type}', 'All types' and other types of links could perhaps be grouped and/or refactored in more generic cases, see for example one of the issues above.
Mostly the function could be summed up to the following types of extra links:
Some cases related with content entity links are currently tested in the following classes:
\Drupal\Tests\admin_toolbar\Functional\AdminToolbarToolsSortTest:
https://git.drupalcode.org/project/admin_toolbar/-/blob/3.x/tests/src/Fu...
Testing the display, creation and deletion of a Media type and Menu.
Testing the display order of created menus in the admin menu ==> Ordered by label.
\Drupal\Tests\admin_toolbar_search\FunctionalJavascript\AdminToolbarToolsSearchTest:
https://git.drupalcode.org/project/admin_toolbar/-/blob/3.x/admin_toolba...
Testing some of module's features through its integration with Admin Toolbar Search: 'SearchLinks' class.
Display, creation and deletion of a Media type, Menu and Node type.
Testing specific entity types is really limited in terms of coverage, since the method getDerivativeDefinitions
has a lot of module specific code, such as:
if ($this->moduleHandler->moduleExists('node'))
for node types
if ($this->moduleHandler->moduleExists('taxonomy'))
for taxonomy vocabularies
if ($this->moduleHandler->moduleExists('menu_ui'))
for menus
if ($this->moduleHandler->moduleExists('block_content'))
for block content types
and so many more....
For example, there are specific cases for:
None of which are currently tested...
and everything is hard coded, with code duplication a bit everywhere 😅
Run PHPUNIT Tests for the admin_toolbar_tools
module.
Run PHPUNIT Tests for the admin_toolbar_search
module.
We should consider a more generic method to try executing as much of the classes' code as possible, enter in as many 'if' cases as possible and test all supported content entities.
Additionally, since the 'ExtraLinks' and 'SearchLinks' classes are very close, we should probably try covering them in the same test classes.
The 'SearchLinks' class should actually belong to the admin_toolbar_tools
module and there should be a more generic way to add extra links to the admin_toolbar_search
, but this should probably be addressed in a different issue and is not the object of this ticket.
What should be tested?
Test all the modules supported by classes 'ExtraLinks' and 'SearchLinks' except external integrations:
devel, devel_php, project_browser and webprofiler.
Creating custom entities for the tests (triggering 'entity_insert' hooks) should also allow testing all the code in file admin_toolbar_tools.module
, such as:
function admin_toolbar_tools_entity_insert:
https://git.drupalcode.org/project/admin_toolbar/-/blob/3.x/admin_toolba...
which also calls code in class \Drupal\admin_toolbar_tools\AdminToolbarToolsHelper
allowing to test this class as well completely, except for the "Show Local Tasks" feature (method 'buildLocalTasksToolbar').
Overall, except for the "Show Local Tasks" feature (to be addressed in related test ticket) and external (module) integrations, these tests should allow to almost completely cover the Admin Toolbar Tools and Admin Toolbar Search modules.
Needs review
3.0
Automated tests
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
No activities found.