소스 검색

Chado Field: get values list for fields storing their data in the base table of the bundle via foreign key.

Lacey Sanderson 6 년 전
부모
커밋
6cc7b75f2a
2개의 변경된 파일61개의 추가작업 그리고 22개의 파일을 삭제
  1. 54 0
      tests/tripal_chado/fields/ChadoFieldGetValuesListTest.php
  2. 7 22
      tripal_chado/includes/TripalFields/ChadoField.inc

+ 54 - 0
tests/tripal_chado/fields/ChadoFieldGetValuesListTest.php

@@ -66,6 +66,60 @@ class ChadoFieldGetValuesListTest extends TripalTestCase {
     }
   }
 
+  /**
+   * Test for fields based on columns in the base table that are also foreign keys.
+   *
+   * @group fields
+   * @group getValueList
+   */
+  public function testBaseTableForeignKey() {
+    include_once(drupal_get_path('tripal_chado', 'module') . '/includes/TripalFields/ChadoField.inc');
+
+    // Retrieve a list of fields to test.
+    // Note: this list is cached to improve performance.
+    $fields = $this->retrieveFieldList();
+
+    // Only iterate through fields that store their data in chado and
+    // specifically, where the field stores it's data in the base table of the bundle
+    // and IS a foreign key.
+    foreach ($fields['field_chado_storage']['foreign key'] as $key => $info) {
+        $field_name = $info['field_name'];
+        
+        // Construct the Field instance we want the values for.
+        // Specifying "ChadoField" here ensures we are only testing our 
+        // implementation of getValueList() and not the custom version for any
+        // given field.
+        // YOU SHOULD TEST CUSTOM FIELD IMPLEMENTATIONS SEPARATELY.
+        $instance = new \ChadoField($info['field_info'], $info['instance_info']);
+        
+        // Retrieve the values using defaults.
+        // $values will be an array containing the distinct set of values for this field instance.
+        $values = $instance->getValueList(array('limit' => 5));
+        
+        // Ensure we have values returned!
+        $this->assertTrue(
+          is_array($values),
+          t(
+            'No values returned for @field_name with no label string set (bundle: @bundle_name, bundle base table: @bundle_base_table, chado table: @chado_table, chado column: @chado_column).',
+            array(
+              '@field_name' => $field_name, 
+              '@bundle_name' => $info['bundle_name'], 
+              '@bundle_base_table' => $info['bundle_base_table'], 
+              '@chado_table' => $info['instance_info']['settings']['chado_table'], 
+              '@chado_column' => $info['instance_info']['settings']['chado_column'],
+            ) 
+          )   
+        );    
+      
+      // Ensure there are no more then 5 as specified in the limit above.
+      $this->assertLessThanOrEqual(5, sizeof($values),
+        t('Returned too many results for @field_name.', array('@field_name' => $field_name)));
+
+      // @todo Ensure it works with a label string set.
+
+    }
+  }
+
   /**
    * Returns a list of Fields sorted by their backend, etc. for use in tests.
    */

+ 7 - 22
tripal_chado/includes/TripalFields/ChadoField.inc

@@ -227,17 +227,7 @@ class ChadoField extends TripalField {
       // If so we would like to travel through the relationship
       // to capture a better human-readable option.
       if ($is_fk) {
-/*
-    dpm(array(
-      'chado table' => $chado_table,
-      'chado column' => $chado_column,
-      'base table' => $base_table,
-      'base schema' => $bschema,
-      'Is foreign key?' => $is_fk,
-      'Foreign Table' => $fk_table,
-      'Foreign column' => $fk_column,
-    ), 'info');
-*/
+
         // Determine the query.
         $sql = "SELECT base.$chado_column as id, fk.*
                 FROM {".$chado_table."} base
@@ -254,6 +244,12 @@ class ChadoField extends TripalField {
           elseif (isset($fkschema['fields']['uniquename'])) {
             $options['label_string'] = '[uniquename]';
           }
+          elseif (isset($fkschema['fields']['accession'])) {
+            $options['label_string'] = '[accession]';
+          }
+          elseif (isset($fkschema['fields']['title'])) {
+            $options['label_string'] = '[title]';
+          }
           elseif ($fk_table == 'organism') {
             $options['label_string'] = '[genus] [species]';
           }
@@ -291,17 +287,6 @@ class ChadoField extends TripalField {
       return FALSE;
     }
 
-/*
-    dpm(array(
-      'chado table' => $chado_table,
-      'chado column' => $chado_column,
-      'base table' => $base_table,
-      'base schema' => $bschema,
-      'Is foreign key?' => $is_fk,
-      'Foreign Table' => $fk_table,
-      'Foreign column' => $fk_column,
-    ), 'info');
-*/
     $results = chado_query($sql);
 
     // Pre-process the label string for better performance.