Kaynağa Gözat

Fixed tests by making field/instance_info() called from the testCase.

Lacey Sanderson 6 yıl önce
ebeveyn
işleme
f09803abf3

+ 27 - 26
tests/TripalFieldTestHelper.php

@@ -40,30 +40,15 @@ class TripalFieldTestHelper {
    *    - field_name: the name of the field (REQUIRED)
    *    - widget_name: the name of the widget (Only required for widget testing)
    *    - formatter_name: the name of the formatter (Only required for formatter testing)
-   * @param $field_info (OPTIONAL)
-   *   The Drupal information for the field you want to test. @see getFieldInfo
-   * @param $instance_info (OPTIONAL)
-   *   The Drupal information for the field instance you want to test. @see getInstanceInfo
+   * @param $field_info
+   *   The Drupal information for the field you want to test.
+   * @param $instance_info
+   *   The Drupal information for the field instance you want to test.
    */
-  public function __construct($bundle_name, $machine_names, $entity, $field_info = NULL, $instance_info = NULL) {
+  public function __construct($bundle_name, $machine_names, $entity, $field_info, $instance_info) {
 
     // @debug print "BUNDLE: " .$bundle_name."\n";
 
-    // Save the field information.
-    if (!$field_info) {
-      $field_info = $this->getFieldInfo($machine_names['field_name']);
-    }
-    $this->field_info = $field_info;
-
-    // Save the field instance information.
-    if (!$instance_info) {
-      $instance_info = $this->getFieldInfo($bundle_name, $machine_names['field_name']);
-    }
-    $this->instance_info = $instance_info;
-
-    // Load the bundle.
-    $this->bundle = tripal_load_bundle_entity(array('name'=> $bundle_name));
-
     // What type of class are we initializing?
     $this->type = 'field';
     $this->class_name = $machine_names['field_name'];
@@ -76,16 +61,32 @@ class TripalFieldTestHelper {
       $this->class_name = $machine_names['formatter_name'];
     }
 
-    // The entity from the specified bundle that the field should be attached to.
-    $this->entity = $entity;
-
-    // @debug print_r($instance_info);
-
-    // Initialize the class.
     $class_name = '\\' . $this->class_name;
     $class_path = DRUPAL_ROOT . '/' . drupal_get_path('module', 'tripal_chado')
       . '/includes/TripalFields/'.$machine_names['field_name'].'/'.$this->class_name.'.inc';
     if ((include_once($class_path)) == TRUE) {
+
+      // Save the field information.
+      if (!$field_info) {
+        $field_info = $this->getFieldInfo($machine_names['field_name']);
+      }
+      $this->field_info = $field_info;
+
+      // Save the field instance information.
+      if (!$instance_info) {
+        $instance_info = $this->getFieldInfo($bundle_name, $machine_names['field_name']);
+      }
+      $this->instance_info = $instance_info;
+
+      // Load the bundle.
+      $this->bundle = tripal_load_bundle_entity(array('name'=> $bundle_name));
+
+      // The entity from the specified bundle that the field should be attached to.
+      $this->entity = $entity;
+
+      // @debug print_r($instance_info);
+
+      // Initialize the class.
       $this->initialized_class = new $class_name($this->field_info, $this->instance_info);
     }
 

+ 9 - 5
tests/tripal_chado/fields/sbo__relationship_widgetTest.php

@@ -4,6 +4,8 @@ namespace Tests\tripal_chado\fields;
 use StatonLab\TripalTestSuite\DBTransaction;
 use StatonLab\TripalTestSuite\TripalTestCase;
 
+module_load_include('php', 'tripal_chado', '../tests/TripalFieldTestHelper');
+
 class sbo__relationship_widgetTest extends TripalTestCase {
   // Uncomment to auto start and rollback db transactions per test method.
   use DBTransaction;
@@ -92,8 +94,9 @@ class sbo__relationship_widgetTest extends TripalTestCase {
       'field_name' => $field_name,
       'widget_name' => $widget_name,
     );
-    module_load_include('php', 'tripal_chado', '../tests/TripalFieldTestHelper');
-    $helper = new \TripalFieldTestHelper($bundle_name, $machine_names, $entity);
+    $field_info = field_info_field($field_name);
+    $instance_info = field_info_instance('TripalEntity', $field_name, $bundle_name);
+    $helper = new \TripalFieldTestHelper($bundle_name, $machine_names, $entity, $field_info, $instance_info);
     $widget_class = $helper->getInitializedClass();
 
     // Check we have the variables we initialized.
@@ -133,8 +136,9 @@ class sbo__relationship_widgetTest extends TripalTestCase {
       'field_name' => $field_name,
       'widget_name' => $widget_name,
     );
-    module_load_include('php', 'tripal_chado', '../tests/TripalFieldTestHelper');
-    $helper = new \TripalFieldTestHelper($bundle_name, $machine_names, $entity);
+    $field_info = field_info_field($field_name);
+    $instance_info = field_info_instance('TripalEntity', $field_name, $bundle_name);
+    $helper = new \TripalFieldTestHelper($bundle_name, $machine_names, $entity, $field_info, $instance_info);
     $widget_class = $helper->getInitializedClass();
 
     $base_table = $entity->chado_table;
@@ -224,7 +228,7 @@ class sbo__relationship_widgetTest extends TripalTestCase {
     $this->assertArrayHasKey('object_name', $widget,
       "The form for $bundle_name($base_table) does not have a object element.");
 
-    //@ debug print_r($widget);
+    // @debug print_r($widget);
 
     // Check the subject/object keys were correctly determined.
     $this->assertEquals($expect['subject_key'], $widget['#subject_id_key'],