Add functional tests

Created on 7 February 2024, 9 months ago

Problem/Motivation

As there are some issues when using this module. Some functional tests could help.

📌 Task
Status

Needs review

Version

4.1

Component

Code

Created by

🇪🇸Spain aleix

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @aleix
  • Status changed to Needs review 9 months ago
  • 🇪🇸Spain aleix

    Adding the test to be reviewed.

    To pass as it should it needs the included view like the one in MR of https://www.drupal.org/project/group_term/issues/3418042 💬 Groups content form available tags Needs review may help (it needs also the default argument plugin included in the MR too: https://git.drupaxlcode.org/issue/group_term-3418042/-/commit/7f7ea9f264... ).

    Also, it needs some way to alter the form that includes the term reference field, to add a dynamic argument to the view(something like): https://www.drupal.org/project/group_term/issues/3418042#comment-15425010 💬 Groups content form available tags Needs review , to let find the related group based on node membership (e.g. useful when using node edit form for a node previously related to a group).For example to alter the node page forms:

    /**
     * Restrict the terms on group documents to restrict per group only terms.
     *
     */
    function group_term_overrides_form_alter(&$form, FormStateInterface $form_state, $form_id){
      if ($form_id == 'node_page_edit_form' || $form_id == 'node_page_form') {
        $groups = [];
        $group = \Drupal::request()->attributes->get('group');
        if (empty($group) || !$group instanceof Group) {
          $node = \Drupal::request()->attributes->get('node');
          if (!empty($node) && $node instanceof Node) {
            foreach (GroupRelationship::loadByEntity($node) as $group_relationships) {
              // If it's linked to more than one then it will grab the group
              // entity->id of the last linked group only so push to groups array
              $group_id = $group_relationships->gid->entity->id();
              $groups[] = Group::load($group_id);
            }
          }
        } else {
          $groups[] = $group;
        }
        if(!empty($groups)) {
          // JUST USE the First group found here! No cardinality support.
          if ($groups[0] instanceof Group) {
            $form['field_group_tags']['widget'][0]['target_id']['#selection_settings']['view']['arguments'][0] = $groups[0]->id();
           }
        }
      }
    }
    
    

    When above changes are included, It will show how:
    A view makes possible to filter the terms based on group, as shown in test: testTermInsideGroupAutocomplete . Despite it has some issues too, as in https://git.drupalcode.org/issue/group_term-3419691/-/blame/0a6ddc639222... , where is not possible to use directly the group permission access. Also, despite it will add the basic functionality, it's restricted to autocomplete, as I find no way to get the options when rendering the form (as shown in https://git.drupalcode.org/issue/group_term-3419691/-/blame/0a6ddc639222... ) .

    The tests will check terms listing, isolation between groups, isolation between group scope and outside of group scope. Basic term creation, and basic operations check.

    So to conclude I find it possible to make it work the module for my basic use case, but to get a step further I think that It may need a dedicated field widget component or use something like entity browser to pick up the terms.

  • Merge request !13Resolve #3419691 "Functional tests" → (Open) created by aleix
Production build 0.71.5 2024