Project

General

Profile

« Previous | Next » 

Revision 96614dfe

Added by Andreas Kohlbecker almost 5 years ago

ref #4177 test for improved and more consistet implementation of the inline representation of name relationships

View differences:

modules/cdm_dataportal/includes/name.inc
581 581
    $name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->nameRef->uuid);
582 582
    $render_array['published_name'] = markup_to_render_array('<p class="published-name">' . render_taxon_or_name($name) . '</p>', 0);
583 583
    $name_relations = cdm_ws_fetch_all(str_replace("$0", $registration_dto->nameRef->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
584
    $render_array['name_relations'] = compose_name_relationships_list($name_relations, $registration_dto->nameRef->uuid, null, false);
584
    $render_array['name_relations'] = compose_name_relationships_list($name_relations, $registration_dto->nameRef->uuid, null);
585 585
    $render_array['name_relations']['#weight'] = 10;
586 586
  } else {
587 587
    // in this case the registration must have a
......
915 915
 *    The nameCache will be shown instead of the titleCache if this parameter is true.
916 916
 * @return null|string
917 917
 */
918
function name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source, $show_name_cache_only = false){
918
function name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $show_name_cache_only = false){
919 919

  
920 920
  $relationship_markup = null;
921 921

  
......
945 945

  
946 946

  
947 947
/**
948
 * Renders an inline representation of selected name relationships
948
 * Composes an inline representation of selected name relationships
949 949
 *
950 950
 * The output of this function will be usually appended to taxon name representations.
951 951
 * Only the following types are displayed: LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR, ORTHOGRAPHIC_VARIANT
......
974 974
 *    an inverse relation. For this relation type the toName is taken in to account.
975 975
 * @param $current_taxon_uuid
976 976
 *    The taxon to be omitted from related taxa. This is only used to create links, see path_to_name()
977
 * @return String
978
 *    The markup for the name relationships
977
 * @return array
978
 *    A drupal render array
979
 *
980
 * @ingroup Compose
979 981
 */
980
function render_name_relationships_inline($name_relations, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source = true) {
982
function compose_name_relationships_inline($name_relations, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source = true) {
981 983

  
982 984
  RenderHints::pushToRenderStack('homonym');
983 985
  // the render stack element homonyms is being used in the default render templates !!!, see CDM_NAME_RENDER_TEMPLATES_DEFAULT
984 986

  
985 987
  $selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT));
986 988

  
987
  $relations_array = array();
988

  
989
  if ($name_relations) {
990
    foreach ($name_relations as $name_rel) {
991
      if (!(isset($selected_name_rel_uuids[$name_rel->type->uuid]) && $selected_name_rel_uuids[$name_rel->type->uuid])) {
992
        // skip if not selected in the settings
993
        continue;
994
      }
995

  
996
      $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source);
997
        
998
      if($relationship_markup){
999
        if($name_rel->type->uuid == UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT){
1000
          $prefix = 'ort. var.';
1001
        } else {
1002
          if (count($relations_array)) {
1003
            // lat: "non nec" == german: "weder noch"
1004
            $prefix = 'nec';
1005
          } else {
1006
            $prefix = 'non';
1007
          }
1008
        }
1009
        $relations_array [] = $prefix . ' ' . $relationship_markup;
1010
      }
1011

  
1012
    }
1013
  }
989
  $list_prefix = '<div class="name-relationships">[';
990
  $list_suffix = ']</div>';
991
  $item_prefix = '<span class="item">';
992
  $item_suffix = '</span> ';
993
  $show_relationship_symbol = true;
994
  $render_array = compose_name_relationships($name_relations, $selected_name_rel_uuids, $current_name_uuid, $current_taxon_uuid, $show_relationship_symbol, $list_prefix, $list_suffix, $item_prefix, $item_suffix);
1014 995

  
1015 996
  RenderHints::popFromRenderStack();
1016
  return (count($relations_array) ?'<div class="name-relationships">[' . trim(join(" ", $relations_array)) . ']</div>' : '');
997
  return $render_array;
1017 998
}
1018 999

  
1019 1000
/**
......
1031 1012
 * @param $current_name_uuid
1032 1013
 *    The Uuid of the name for which the relations are to be rendered, the current name will be hidden when
1033 1014
 *    rendering the relation an only the other name is shown. Parameter is REQUIRED.
1034
 * @param $suppress_if_current_name_is_source
1035
 *    The display of the relation will be
1036
 *    suppressed is the current name is on the source of the relation edge.
1037
 *    That is if it is on the from side of the relation. Except for 'blocking name for' which is
1038
 *    an inverse relation. For this relation type the toName is taken in to account.
1039 1015
 * @param $current_taxon_uuid
1040 1016
 *    The taxon to be omitted from related taxa. This is only used to create links, see path_to_name()
1041 1017
 * @return array
......
1043 1019
 *
1044 1020
 * @ingroup Compose
1045 1021
 */
1046
function compose_name_relationships_list($name_relations, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source = true) {
1022
function compose_name_relationships_list($name_relations, $current_name_uuid, $current_taxon_uuid) {
1047 1023

  
1048
  $non_nec_name_reltype_uuids = array(UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
1049
    UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
1050
    UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR);
1051 1024
  // $ordered_name_relation_type_uuids = array_keys(cdm_terms_by_type_as_option('NameRelationshipType', CDM_ORDER_BY_ORDER_INDEX_ASC));
1052 1025

  
1053 1026
  RenderHints::pushToRenderStack('name_relationships');
......
1056 1029

  
1057 1030
  $selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, unserialize(CDM_NAME_RELATIONSHIP_LIST_TYPES_DEFAULT));
1058 1031

  
1032
  $list_prefix = '<div class="relationships_list name_relationships">';
1033
  $list_suffix = '</div>';
1034
  $item_prefix = '<div class="item">';
1035
  $item_suffix = '</div>';
1036
  $show_relationship_symbol = true;
1037

  
1038
  $render_array = compose_name_relationships($name_relations, $selected_name_rel_uuids, $current_name_uuid, $current_taxon_uuid, $show_relationship_symbol, $list_prefix, $list_suffix, $item_prefix, $item_suffix);
1039

  
1040
  RenderHints::popFromRenderStack();
1041
  $render_array['footnotes'] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey())));
1042
  RenderHints::clearFootnoteListKey();
1043

  
1044
  return $render_array;
1045
}
1046

  
1047
/**
1048
 * @param $name_relations
1049
 * @param $selected_name_rel_uuids
1050
 * @param $current_name_uuid
1051
 * @param $current_taxon_uuid
1052
 * @param $show_relationship_symbol
1053
 * @param $list_prefix
1054
 * @param $list_suffix
1055
 * @param $item_prefix
1056
 * @param $item_suffix
1057
 * @return array
1058
 *
1059
 * @ingroup Compose
1060
 */
1061
function compose_name_relationships($name_relations, $selected_name_rel_uuids, $current_name_uuid, $current_taxon_uuid, $show_relationship_symbol, $list_prefix, $list_suffix, $item_prefix, $item_suffix)
1062
{
1063
  $non_nec_name_reltype_uuids = array(UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
1064
    UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
1065
    UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR);
1066

  
1059 1067
  $render_array = array(
1060 1068
    'list' => array(
1061
      '#prefix' => '<div class="relationships_list name_relationships">',
1062
      '#suffix' => '</div>',
1069
      '#prefix' => $list_prefix,
1070
      '#suffix' => $list_suffix,
1063 1071
      'items' => array()
1064 1072
    ),
1065 1073
    'footnotes' => array()
1066 1074
  );
1067 1075

  
1068
  if($name_relations) {
1076
  if ($name_relations) {
1069 1077

  
1070 1078
    // remove all relations which are not selected in the settings and
1071
    // sepearate all LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR relations and ORTHOGRAPHIC_VARIANTs
1079
    // separate all LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR relations and ORTHOGRAPHIC_VARIANTs
1072 1080
    // for special handling
1073 1081
    $filtered_name_rels = array();
1074 1082
    $non_nec_name_rels = array();
1075 1083
    $orthographic_variants = array();
1076
    foreach($name_relations as $name_rel) {
1077
      if (isset($selected_name_rel_uuids[$name_rel->type->uuid]) && $selected_name_rel_uuids[$name_rel->type->uuid]) {
1078
        if(array_search($name_rel->type->uuid, $non_nec_name_reltype_uuids) !== false){
1084
    foreach ($name_relations as $name_rel) {
1085
      $rel_type_uuid = $name_rel->type->uuid;
1086
      if (isset($selected_name_rel_uuids[$rel_type_uuid]) && $selected_name_rel_uuids[$rel_type_uuid]) {
1087
        if (array_search($rel_type_uuid, $non_nec_name_reltype_uuids) !== false && (
1088
            $current_name_uuid == $name_rel->fromName->uuid && $rel_type_uuid != UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
1089
            || $current_name_uuid == $name_rel->toName->uuid && $rel_type_uuid == UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
1090
          )
1091
        ){
1079 1092
          $non_nec_name_rels[] = $name_rel;
1080
        } else if(UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT == $name_rel->type->uuid) {
1093
        } else if (UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT == $rel_type_uuid) {
1081 1094
          $orthographic_variants[] = $name_rel;
1082 1095
        } else {
1096

  
1083 1097
          $filtered_name_rels[] = $name_rel;
1084 1098
        }
1085 1099
      }
......
1088 1102

  
1089 1103
    usort($name_relations, 'compare_name_relations_by_term_order_index');
1090 1104

  
1091
    foreach($name_relations as $name_rel) {
1105
    foreach ($name_relations as $name_rel) {
1092 1106

  
1093
      $current_name_is_toName = $current_name_uuid == $name_rel->toName->uuid;
1107
      $is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
1094 1108

  
1095 1109
      $footnote_key_markup = name_relationship_footnote_markup($name_rel);
1096
      $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source);
1097
      $is_inverse_relation = $current_name_is_toName;
1110
      $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid);
1098 1111

  
1099 1112
      $label = cdm_relationship_type_term_abbreviated_label($name_rel->type, $is_inverse_relation);
1100 1113
      $symbol = cdm_relationship_type_term_symbol($name_rel->type, $is_inverse_relation);
1101

  
1102
      $relationship_markup = '<span class="symbol" title="' . $label . '">' . $symbol . '</span> ' . $relationship_markup . $footnote_key_markup;
1103
      if($relationship_markup){
1114
      $symbol_markup = $show_relationship_symbol ? '<span class="symbol" title="' . $label . '">' . $symbol . '</span> ' : '';
1115
      $relationship_markup = $symbol_markup . $relationship_markup . $footnote_key_markup;
1116
      if ($relationship_markup) {
1104 1117
        $render_array['list']['items'][] = markup_to_render_array($relationship_markup,
1105 1118
          null,
1106
          '<div class="item">',
1107
          '</div>');
1119
          $item_prefix,
1120
          $item_suffix);
1108 1121
      }
1109 1122
    }
1110 1123

  
1111 1124
    // name relationships to be displayed as non nec
1112
    if(count($non_nec_name_rels) > 0){
1125
    if (count($non_nec_name_rels) > 0) {
1113 1126
      $non_nec_markup = '';
1114
      foreach($non_nec_name_rels as $name_rel){
1127
      foreach ($non_nec_name_rels as $name_rel) {
1128
        $is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
1115 1129
        $footnote_key_markup = name_relationship_footnote_markup($name_rel);
1116
        $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source);
1130
        $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid);
1131
        $label = cdm_relationship_type_term_abbreviated_label($name_rel->type, $is_inverse_relation);
1117 1132
        $symbol = $non_nec_markup ? ' nec ' : 'non';
1118
        $non_nec_markup .= '<span class="symbol" title="' . $label . '">' . $symbol . '</span> ' . $relationship_markup . $footnote_key_markup;
1133
        $symbol_markup = $show_relationship_symbol ? '<span class="symbol" title="' . $label . '">' . $symbol . '</span> ' : '';
1134
        $non_nec_markup .= $symbol_markup . $relationship_markup . $footnote_key_markup;
1135
      }
1136
      if ($non_nec_markup) {
1137
        $render_array['list']['items'][] = markup_to_render_array($non_nec_markup,
1138
          null,
1139
          $item_prefix,
1140
          $item_suffix);
1119 1141
      }
1120
       if($non_nec_markup){
1121
         $render_array['list']['items'][] = markup_to_render_array($non_nec_markup,
1122
           null,
1123
           '<div class="item">',
1124
           '</div>');
1125
       }
1126 1142
    }
1127 1143

  
1128 1144
    // orthographic variants
1129
    if(count($orthographic_variants) > 0){
1130
      foreach($orthographic_variants as $name_rel){
1145
    if (count($orthographic_variants) > 0) {
1146
      foreach ($orthographic_variants as $name_rel) {
1147

  
1148
        $is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
1131 1149
        $footnote_key_markup = name_relationship_footnote_markup($name_rel);
1132 1150
        $footnote_key_markup .= ($footnote_key_markup ? ', ' : '') . nomenclatural_reference_footnote_markup($name_rel->toName);
1133
        $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source, TRUE);
1151
        $relationship_markup = name_relationship_markup($name_rel, $current_name_uuid, $current_taxon_uuid, TRUE);
1152
        $label = cdm_relationship_type_term_abbreviated_label($name_rel->type, $is_inverse_relation);
1134 1153
        $symbol = cdm_relationship_type_term_symbol($name_rel->type, $is_inverse_relation);
1135
        $relationship_markup = '<span class="symbol" title="' . $label . '">' . $symbol . '</span> ' . $relationship_markup . $footnote_key_markup;
1154
        $symbol_markup = $show_relationship_symbol ? '<span class="symbol" title="' . $label . '">' . $symbol . '</span> ' : '';
1155
        $relationship_markup = $symbol_markup . $relationship_markup . $footnote_key_markup;
1136 1156
      }
1137
      if($relationship_markup){
1157
      if ($relationship_markup) {
1138 1158
        $render_array['list']['items'][] = markup_to_render_array($relationship_markup,
1139 1159
          null,
1140
          '<div class="item">',
1141
          '</div>');
1160
          $item_prefix,
1161
          $item_suffix);
1142 1162
      }
1143 1163
    }
1144 1164
  }
1145

  
1146
  RenderHints::popFromRenderStack();
1147
  $render_array['footnotes'] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey())));
1148
  RenderHints::clearFootnoteListKey();
1149

  
1150 1165
  return $render_array;
1151 1166
}
1152 1167

  
modules/cdm_dataportal/includes/taxon.inc
382 382

  
383 383

  
384 384
  $name_relations = cdm_name_relationships_for_taxon($taxon);
385
  $homonyms = render_name_relationships_inline($name_relations, $taxon->name->uuid, $taxon->uuid);
385
  $name_relations_render_array = compose_name_relationships_inline($name_relations, $taxon->name->uuid, $taxon->uuid);
386 386

  
387 387
  $out = '<span class="relation_sign" title="' . $reltype_representation . '">' . $relsign . '</span>'
388
    . $out_taxon_part . $taxon_footnotes . ' '  . $homonyms;
388
    . $out_taxon_part . $taxon_footnotes . ' '  . drupal_render($name_relations_render_array);
389 389

  
390 390
  $out = uuid_anchor($taxon->uuid, $out);
391 391

  
modules/cdm_dataportal/theme/cdm_dataportal.page.theme
194 194
    $accepted_name .= render_taxon_or_name($taxon, NULL, $referenceUri);
195 195

  
196 196
    $name_relations = cdm_name_relationships_for_taxon($taxon);
197
    $name_relationships = render_name_relationships_inline($name_relations, $taxon->name->uuid, $taxon->uuid);
197
    $name_relationships = compose_name_relationships_inline($name_relations, $taxon->name->uuid, $taxon->uuid);
198 198
    // Render relationships of accepted name.
199
    if($name_relationships){
200

  
201
      $accepted_name .= ' <span class="name_relationships">' . $name_relationships . '</span>';
199
    if(isset($name_relationships['list']['items'][0])){
200
      $accepted_name .= ' <span class="name_relationships">' . drupal_render($name_relationships) . '</span>';
202 201
    }
203 202

  
204 203
      // handle annotations of the name and taxon
src/test/java/eu/etaxonomy/dataportal/selenium/tests/reference/NameRelationshipsTest.java
11 11
import java.io.UnsupportedEncodingException;
12 12
import java.net.MalformedURLException;
13 13
import java.util.List;
14
import java.util.UUID;
14 15

  
15 16
import org.junit.Before;
16 17
import org.junit.Test;
18
import org.openqa.selenium.By;
19
import org.openqa.selenium.WebElement;
17 20

  
18 21
import eu.etaxonomy.dataportal.DataPortalSite;
19 22
import eu.etaxonomy.dataportal.elements.BaseElement;
......
21 24
import eu.etaxonomy.dataportal.junit.CdmDataPortalTestBase;
22 25
import eu.etaxonomy.dataportal.junit.DataPortalContextSuite.DataPortalContexts;
23 26
import eu.etaxonomy.dataportal.pages.RegistrationPage;
27
import eu.etaxonomy.dataportal.pages.TaxonSynonymyPage;
24 28

  
25 29
/**
26 30
 * @author a.kohlbecker
......
32 36

  
33 37
    private static final String reg_nodosilinea_sensensia_id = "http://testbank.org/100009";
34 38

  
39
    private static final UUID taxon_nodosilinea_sensensia_uuid = UUID.fromString("7094ea13-2a95-46d9-bfca-8c0e0848e44c");
40

  
35 41
    String titleSuffix = " | Integration test reference";
36 42

  
37 43
    @Before
......
61 67
        assertEquals("is new name for Nepenthes blancoi Blume in Mus. Bot. Lugd.-Bat. 2: 10. 1852", nameRelationshipElements.get(1).getText());
62 68
        assertEquals("is validating Nodosilinea radiophila Heidari & Hauer in Fottea 18(2): 142. fig. 5C, D. 1.11.20181", nameRelationshipElements.get(2).getText());
63 69
        assertEquals("non Nodosilinea blockensis, New Species in the solar system nec Nodosilinea sensensia, Plantas vasculares de Oz nec Nodosilinea sensensia, Species solaris", nameRelationshipElements.get(3).getText());
64
        assertEquals("has orthographic variant Nodosilinea sensensi2, 3", nameRelationshipElements.get(4).getText());
70
        BaseElement orthVarElement = nameRelationshipElements.get(4);
71
        assertEquals("orth. var. Nodosilinea sensensi2, 3", orthVarElement.getText());
72
        assertEquals("has orthographic variant", orthVarElement.getElement().findElement(By.className("symbol")).getAttribute("title"));
65 73

  
66 74
        List<BaseElement> nameRelationshipFootnotes = regItem.getNameRelationsipFootnotes();
67 75
        assertEquals(3, nameRelationshipFootnotes.size());
......
71 79

  
72 80
    }
73 81

  
82
    @Test
83
    public void testNodosilinea_sensensia_SynonymPage() throws MalformedURLException, UnsupportedEncodingException {
84

  
85
        TaxonSynonymyPage p = new TaxonSynonymyPage(driver, getContext(), taxon_nodosilinea_sensensia_uuid);
86

  
87
        WebElement accName = p.getAcceptedName();
88
        assertEquals("Nodosilinea sensensia (Blanco) Heidari & Hauer ex Lem, Nonsens species of the developers Vol1\n[non Nodosilinea sensensia nec Nodosilinea sensensia nec Nodosilinea blockensis orth. var. Nodosilinea sensensi1, 2 ]", accName.getText());
89

  
90
        List<BaseElement> footnotes = p.getHomotypicalGroupFootNotes();
91
        assertEquals("1. Art. 88.9 Turland, Wiersema, Barrie, Greuter, D.Hawksw., Herend., S.Knapp, Kusber, D.Z.Li, Marhold, T.W.May, McNeill, A.M.Monro, J.Prado, M.J.Price & Gideon F.Sm., International Code of Nomenclature for algae, fungi, and plants (Shenzhen Code) adopted by the Nineteenth International Botanical Congress Shenzhen, China, July 2017:33", footnotes.get(0).getText());
92
        assertEquals("2. Lem, Nonsens species of the developers Vol1", footnotes.get(1).getText());
93

  
94
    }
95

  
74 96
}

Also available in: Unified diff