Przeglądaj źródła

Ensure data provider creates records of the correct type for the bundle.

Lacey Sanderson 6 lat temu
rodzic
commit
80ff523440

+ 19 - 14
tests/tripal_chado/fields/sbo__relationship_widgetTest.php

@@ -51,12 +51,10 @@ class sbo__relationship_widgetTest extends TripalTestCase {
 
        // Create some entities so that we know there are some available to find.
        if ($bundle_details->type_column == 'type_id') {
-         $record_1 = factory('chado.'. $base_table)->create(['type_id' => $bundle_details->type_id]);
-         $record_2 = factory('chado.'. $base_table)->create(['type_id' => $bundle_details->type_id]);
+         factory('chado.'. $base_table, 2)->create(['type_id' => $bundle_details->type_id]);
        }
        else {
-         $record_1 = factory('chado.'. $base_table)->create();
-         $record_2 = factory('chado.'. $base_table)->create();
+         factory('chado.'. $base_table, 2)->create();
        }
        // Then publish them so we have entities.
        $this->publish($base_table);
@@ -205,17 +203,18 @@ class sbo__relationship_widgetTest extends TripalTestCase {
       $field_name = 'sbo__relationship';
       $widget_name = 'sbo__relationship_widget';
 
-      // find a bundle which stores it's data in the given base table.
+      // Find a bundle which stores it's data in the given base table.
       // This will work on Travis since Tripal creates matching bundles by default.
-      // @todo ideally we would create a fake bundle here.
-      $bundle_id = db_query("
-        SELECT bundle_id
+      $bundle_details = db_query("
+        SELECT bundle_id, type_column, type_id
         FROM chado_bundle b
-        LEFT JOIN tripal_entity e ON e.bundle='bio_data_'||b.bundle_id
-        WHERE data_table=:table AND id IS NOT NULL LIMIT 1",
-          array(':table' => $base_table))->fetchField();
-
-      if (!$bundle_id) {
+        WHERE data_table=:table AND type_linker_table=''
+        ORDER BY bundle_id ASC LIMIT 1",
+          array(':table' => $base_table))->fetchObject();
+      if (isset($bundle_details->bundle_id)) {
+        $bundle_id = $bundle_details->bundle_id;
+      }
+      else {
         continue;
       }
       $bundle_name = 'bio_data_'.$bundle_id;
@@ -237,7 +236,13 @@ class sbo__relationship_widgetTest extends TripalTestCase {
       }
 
       // Create 5 fake records and publish them.
-      $records = factory('chado.'.$base_table, 5)->create();
+      if ($bundle_details->type_column == 'type_id') {
+        factory('chado.'. $base_table, 5)->create(['type_id' => $bundle_details->type_id]);
+      }
+      else {
+        factory('chado.'. $base_table, 5)->create();
+      }
+      // Then publish them so we have entities.
       $this->publish($base_table);
 
       $cvterm = factory('chado.cvterm')->create();