| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614 | 
							- <?php
 
- 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;
 
-   /**
 
-    * Data Provider: provides entities matching important test cases.
 
-    *
 
-    * Specifically, we will cover three relationship tables, which represent
 
-    * the diversity in the chado schema v1.3:
 
-    *  organism_relationship: subject_id, type_id, object_id,
 
-    *  stock_relationship: subject_id, type_id, object_id, value, rank,
 
-    *  project_relationship: subject_project_id, type_id, object_project_id, rank
 
-    *
 
-    * @returns
 
-    *   Returns an array where each item to be tested has the paramaters
 
-    *   needed for initializeWidgetClass(). Specfically, $bundle_name,
 
-    *   $field_name, $widget_name, $entity_ids, $expect.
 
-    */
 
-   public function provideEntities() {
 
-      $data = [];
 
-      foreach (['organism', 'stock', 'project'] as $base_table) {
 
-        $field_name = 'sbo__relationship';
 
-        $widget_name = 'sbo__relationship_widget';
 
-        // 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.
 
-        $bundle_details = db_query("
 
-          SELECT bundle_id, type_column, type_id
 
-          FROM chado_bundle b
 
-          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;
 
-        // Create some entities so that we know there are some available to find.
 
-        if ($bundle_details->type_column == 'type_id') {
 
-          $chado_records = factory('chado.'. $base_table, 2)->create(['type_id' => $bundle_details->type_id]);
 
-        }
 
-        else {
 
-          $chado_records = factory('chado.'. $base_table, 2)->create();
 
-        }
 
-        // Then publish them so we have entities.
 
-        $this->publish($base_table);
 
-        // Find our fake entities from the above bundle.
 
-        $entity_ids = [];
 
-        $entity_ids[] = db_query('SELECT entity_id FROM chado_'.$bundle_name.' WHERE record_id=:chado_id',
 
-          array(':chado_id' => $chado_records[0]->{$base_table.'_id'}))->fetchField();
 
-        $entity_ids[] = db_query('SELECT entity_id FROM chado_'.$bundle_name.' WHERE record_id=:chado_id',
 
-          array(':chado_id' => $chado_records[1]->{$base_table.'_id'}))->fetchField();
 
-        // set variables to guide testing.
 
-        $expect = [
 
-          'has_rank' => TRUE,
 
-          'has_value' => FALSE,
 
-          'subject_key' => 'subject_id',
 
-          'object_key' => 'object_id',
 
-          'base_table' => $base_table,
 
-          'relationship_table' => $base_table.'_relationship'
 
-        ];
 
-        if ($base_table == 'organism') { $expect['has_rank'] = FALSE; }
 
-        if ($base_table == 'stock') { $expect['has_value'] = TRUE; }
 
-        if ($base_table == 'project') {
 
-          $expect['subject_key'] = 'subject_project_id';
 
-          $expect['object_key'] = 'object_project_id';
 
-        }
 
-        $data[] = [$bundle_name, $field_name, $widget_name, $entity_ids, $expect];
 
-      }
 
-      return $data;
 
-   }
 
-   /**
 
-    * Test that we can initialize the widget properly.
 
-    *
 
-    * @dataProvider provideEntities()
 
-    *
 
-    * @group widget
 
-    * @group sbo__relationship
 
-    */
 
-   public function testWidgetClassInitialization($bundle_name, $field_name, $widget_name, $entity_ids, $expect) {
 
-     $entity_id = $entity_ids[0];
 
-     // Load the entity.
 
-     $entity = entity_load('TripalEntity', [$entity_id]);
 
-     $entity = $entity[$entity_id];
 
-     // Initialize the widget class via the TripalFieldTestHelper class.
 
-     $machine_names = array(
 
-       'field_name' => $field_name,
 
-       'widget_name' => $widget_name,
 
-     );
 
-     $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.
 
-     $this->assertNotEmpty($helper->bundle,
 
-       "Could not load the bundle.");
 
-     $this->assertNotEmpty($helper->getFieldInfo($field_name),
 
-       "Could not lookup the field information.");
 
-     $this->assertNotEmpty($helper->getInstanceInfo($bundle_name, $field_name),
 
-       "Could not lookup the instance information.");
 
-     $this->assertNotEmpty($widget_class,
 
-       "Couldn't create a widget class instance.");
 
-     $this->assertNotEmpty($entity,
 
-       "Couldn't load an entity.");
 
-     // Check a little deeper...
 
-     $this->assertEquals($helper->instance_info['settings']['chado_table'], $expect['relationship_table'],
 
-       "Instance settings were not initialized fully.");
 
-   }
 
-   /**
 
-    * Test the widget Form.
 
-    *
 
-    * @dataProvider provideEntities()
 
-    *
 
-    * @group widget
 
-    * @group sbo__relationship
 
-    */
 
-   public function testWidgetForm($bundle_name, $field_name, $widget_name, $entity_ids, $expect) {
 
-     $entity_id = $entity_ids[0];
 
-     // Load the entity.
 
-     $entity = entity_load('TripalEntity', [$entity_ids]);
 
-     $entity = $entity[$entity_id];
 
-     // Initialize the widget class via the TripalFieldTestHelper class.
 
-     $machine_names = array(
 
-       'field_name' => $field_name,
 
-       'widget_name' => $widget_name,
 
-     );
 
-     $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;
 
-     // Stub out a fake objects.
 
-     $delta = 1;
 
-     $langcode = LANGUAGE_NONE;
 
-     $widget = $helper->mockElement($delta, $langcode);
 
-     $form = $helper->mockForm($delta, $langcode);
 
-     $form_state = $helper->mockFormState($delta, $langcode);
 
-     $element = $helper->mockElement($delta, $langcode);
 
-     $items = [
 
-       'value' => '',
 
-       'chado-'.$base_table.'_relationship__organism_relationship_id' => '',
 
-       'chado-'.$base_table.'_relationship__subject_id' => '',
 
-       'chado-'.$base_table.'_relationship__object_id' => '',
 
-       'chado-'.$base_table.'_relationship__type_id' => '',
 
-       'object_name' => '',
 
-       'subject_name' => '',
 
-       'type_name' => '',
 
-     ];
 
-     // Execute the form method.
 
-     $widget_class->form($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
-     // Check the resulting for array
 
-     $this->assertArrayHasKey('subject_name', $widget,
 
-       "The form for $bundle_name($base_table) does not have a subject element.");
 
-     $this->assertArrayHasKey('type_name', $widget,
 
-       "The form for $bundle_name($base_table) does not have a type element.");
 
-     $this->assertArrayHasKey('object_name', $widget,
 
-       "The form for $bundle_name($base_table) does not have a object element.");
 
-     // Check the subject/object keys were correctly determined.
 
-     $this->assertEquals($expect['subject_key'], $widget['#subject_id_key'],
 
-       "The form didn't determine the subject key correctly.");
 
-     $this->assertEquals($expect['object_key'], $widget['#object_id_key'],
 
-       "The form didn't determine the object key correctly.");
 
-   }
 
-   /**
 
-    * Case: WidgetValidate on existing relationship.
 
-    *
 
-    * @dataProvider provideEntities()
 
-    *
 
-    * @group widget
 
-    * @group sbo__relationship
 
-    */
 
-   public function testWidgetValidate_existing($bundle_name, $field_name, $widget_name, $entity_ids, $expect) {
 
-     // Load the entities.
 
-     $entities = entity_load('TripalEntity', $entity_ids);
 
-     $entity1 = $entities[$entity_ids[0]];
 
-     $entity2 = $entities[$entity_ids[1]];
 
-     $base_table = $entity1->chado_table;
 
-     // Initialize the widget class via the TripalFieldTestHelper class.
 
-     $machine_names = array(
 
-       'field_name' => $field_name,
 
-       'widget_name' => $widget_name,
 
-     );
 
-     $field_info = field_info_field($field_name);
 
-     $instance_info = field_info_instance('TripalEntity', $field_name, $bundle_name);
 
-     $helper = new \TripalFieldTestHelper($bundle_name, $machine_names, $entity1, $field_info, $instance_info);
 
-     $widget_class = $helper->getInitializedClass();
 
-     // Set some initial values.
 
-     $cvterm = factory('chado.cvterm')->create();
 
-     $initial_values = [
 
-       'subject_name' => $entity2->chado_record->name,
 
-       'type_name' => $cvterm->name,
 
-       'vocabulary' => $cvterm->cv_id,
 
-       'object_name' => $entity1->chado_record->name,
 
-       // Both the form and load set the chado values
 
-       // so we will set them here as well.
 
-       'chado-'.$base_table.'_relationship__'.$expect['subject_key'] => $entity2->chado_record->{$base_table.'_id'},
 
-       'chado-'.$base_table.'_relationship__type_id' => $cvterm->cvterm_id,
 
-       'chado-'.$base_table.'_relationship__'.$expect['object_key'] => $entity1->chado_record->{$base_table.'_id'},
 
-     ];
 
-     if ($base_table == 'organism') {
 
-       $initial_values['subject_name'] = $entity2->chado_record->species;
 
-       $initial_values['object_name'] = $entity1->chado_record->species;
 
-     }
 
-     // Mock objects.
 
-     $delta = 1;
 
-     $langcode = LANGUAGE_NONE;
 
-     $widget = $helper->mockElement($delta, $langcode);
 
-     $form = $helper->mockForm($delta, $langcode);
 
-     $form_state = $helper->mockFormState($delta, $langcode, $initial_values);
 
-     $element = $helper->mockElement($delta, $langcode);
 
-     $widget_class->validate($element, $form, $form_state, $langcode, $delta);
 
-     // @debug print_r($form_state['values'][$field_name][$langcode][$delta]);
 
-     // Ensure the chado-table__column entries are there.
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__'.$expect['subject_key'],
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the subject_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the subject.'
 
-     );
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__'.$expect['object_key'],
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the object_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the object.'
 
-     );
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__type_id',
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the type_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the type.'
 
-     );
 
-     // Check for errors.
 
-     $errors = form_get_errors();
 
-     // @debug print "Errors: " . print_r($errors, TRUE)."\n";
 
-     $this->assertEmpty($errors,
 
-       "There should be no form errors when subject and object are pre-existing and both are supplied. Initial values: ".print_r($initial_values,TRUE)." But these were registered: ".print_r($errors, TRUE));
 
-     // Clean up after ourselves by removing any errors we logged.
 
-     form_clear_error();
 
-   }
 
-   /**
 
-    * Case: WidgetValidate on new relationship filled out properly.
 
-    *
 
-    * @dataProvider provideEntities()
 
-    *
 
-    * @group widget
 
-    * @group sbo__relationship
 
-    */
 
-   public function testWidgetValidate_create($bundle_name, $field_name, $widget_name, $entity_ids, $expect) {
 
-     // Load the entities.
 
-     $entities = entity_load('TripalEntity', $entity_ids);
 
-     $entity1 = $entities[$entity_ids[0]];
 
-     $entity2 = $entities[$entity_ids[1]];
 
-     $base_table = $entity1->chado_table;
 
-     // Initialize the widget class via the TripalFieldTestHelper class.
 
-     $machine_names = array(
 
-       'field_name' => $field_name,
 
-       'widget_name' => $widget_name,
 
-     );
 
-     $field_info = field_info_field($field_name);
 
-     $instance_info = field_info_instance('TripalEntity', $field_name, $bundle_name);
 
-     $helper = new \TripalFieldTestHelper($bundle_name, $machine_names, $entity1, $field_info, $instance_info);
 
-     $widget_class = $helper->getInitializedClass();
 
-     // Set some initial values.
 
-     $cvterm = factory('chado.cvterm')->create();
 
-     $initial_values = [
 
-       'subject_name' => $entity2->chado_record->name,
 
-       'type_name' => $cvterm->name,
 
-       'vocabulary' => $cvterm->cv_id,
 
-       'object_name' => $entity1->chado_record->name,
 
-       // These are not set on the creation form.
 
-       'chado-'.$base_table.'_relationship__'.$expect['subject_key'] => NULL,
 
-       'chado-'.$base_table.'_relationship__type_id' => NULL,
 
-       'chado-'.$base_table.'_relationship__'.$expect['object_key'] => NULL,
 
-     ];
 
-     if ($base_table == 'organism') {
 
-       $initial_values['subject_name'] = $entity2->chado_record->species;
 
-       $initial_values['object_name'] = $entity1->chado_record->species;
 
-     }
 
-     // Mock objects.
 
-     $delta = 1;
 
-     $langcode = LANGUAGE_NONE;
 
-     $widget = $helper->mockElement($delta, $langcode);
 
-     $form = $helper->mockForm($delta, $langcode);
 
-     $form_state = $helper->mockFormState($delta, $langcode, $initial_values);
 
-     $element = $helper->mockElement($delta, $langcode);
 
-     $widget_class->validate($element, $form, $form_state, $langcode, $delta);
 
-     // @debug print_r($form_state['values'][$field_name][$langcode][$delta]);
 
-     // Ensure the chado-table__column entries are there.
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__'.$expect['subject_key'],
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the subject_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the subject.'
 
-     );
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__'.$expect['object_key'],
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the object_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the object.'
 
-     );
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__type_id',
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the type_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the type.'
 
-     );
 
-     // Check for errors.
 
-     $errors = form_get_errors();
 
-     // @debug print "Errors: " . print_r($errors, TRUE)."\n";
 
-     $this->assertEmpty($errors,
 
-       "There should be no form errors when subject and object are pre-existing and both are supplied. Initial values: ".print_r($initial_values,TRUE)." But these were registered: ".print_r($errors, TRUE));
 
-     // Clean up after ourselves by removing any errors we logged.
 
-     form_clear_error();
 
-   }
 
-   /**
 
-    * Case: WidgetValidate on new relationship missing subject.
 
-    *
 
-    * @dataProvider provideEntities()
 
-    *
 
-    * @group widget
 
-    * @group sbo__relationship
 
-    */
 
-   public function testWidgetValidate_nosubject($bundle_name, $field_name, $widget_name, $entity_ids, $expect) {
 
-     // Load the entities.
 
-     $entities = entity_load('TripalEntity', $entity_ids);
 
-     $entity1 = $entities[$entity_ids[0]];
 
-     $entity2 = $entities[$entity_ids[1]];
 
-     $base_table = $entity1->chado_table;
 
-     // Initialize the widget class via the TripalFieldTestHelper class.
 
-     $machine_names = array(
 
-       'field_name' => $field_name,
 
-       'widget_name' => $widget_name,
 
-     );
 
-     $field_info = field_info_field($field_name);
 
-     $instance_info = field_info_instance('TripalEntity', $field_name, $bundle_name);
 
-     $helper = new \TripalFieldTestHelper($bundle_name, $machine_names, $entity1, $field_info, $instance_info);
 
-     $widget_class = $helper->getInitializedClass();
 
-     // Set some initial values.
 
-     $cvterm = factory('chado.cvterm')->create();
 
-     $initial_values = [
 
-       'subject_name' => '',
 
-       'type_name' => $cvterm->name,
 
-       'vocabulary' => $cvterm->cv_id,
 
-       'object_name' => $entity1->chado_record->name,
 
-       // Both the form and load set the chado values
 
-       // so we will set them here as well.
 
-       'chado-'.$base_table.'_relationship__'.$expect['subject_key'] => NULL,
 
-       'chado-'.$base_table.'_relationship__type_id' => $cvterm->cvterm_id,
 
-       'chado-'.$base_table.'_relationship__'.$expect['object_key'] => $entity1->chado_record->{$base_table.'_id'},
 
-     ];
 
-     if ($base_table == 'organism') {
 
-       $initial_values['object_name'] = $entity1->chado_record->species;
 
-     }
 
-     // Mock objects.
 
-     $delta = 1;
 
-     $langcode = LANGUAGE_NONE;
 
-     $widget = $helper->mockElement($delta, $langcode);
 
-     $form = $helper->mockForm($delta, $langcode);
 
-     $form_state = $helper->mockFormState($delta, $langcode, $initial_values);
 
-     $element = $helper->mockElement($delta, $langcode);
 
-     $widget_class->validate($element, $form, $form_state, $langcode, $delta);
 
-     // @debug print_r($form_state['values'][$field_name][$langcode][$delta]);
 
-     // Ensure the chado-table__column entries are there.
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__'.$expect['subject_key'],
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the subject_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the subject.'
 
-     );
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__'.$expect['object_key'],
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the object_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the object.'
 
-     );
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__type_id',
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the type_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the type.'
 
-     );
 
-     // Check for errors.
 
-     $errors = form_get_errors();
 
-     // @debug print "Errors: " . print_r($errors, TRUE)."\n";
 
-     $this->assertNotEmpty($errors,
 
-       "There should be form errors when subject is not supplied. Initial values: ".print_r($initial_values,TRUE)." But these were registered: ".print_r($errors, TRUE));
 
-     // Clean up after ourselves by removing any errors we logged.
 
-     form_clear_error();
 
-   }
 
-   /**
 
-    * Case: WidgetValidate on new relationship missing object.
 
-    *
 
-    * @dataProvider provideEntities()
 
-    *
 
-    * @group widget
 
-    * @group sbo__relationship
 
-    */
 
-   public function testWidgetValidate_noobject($bundle_name, $field_name, $widget_name, $entity_ids, $expect) {
 
-     // Load the entities.
 
-     $entities = entity_load('TripalEntity', $entity_ids);
 
-     $entity1 = $entities[$entity_ids[0]];
 
-     $entity2 = $entities[$entity_ids[1]];
 
-     $base_table = $entity1->chado_table;
 
-     // Initialize the widget class via the TripalFieldTestHelper class.
 
-     $machine_names = array(
 
-       'field_name' => $field_name,
 
-       'widget_name' => $widget_name,
 
-     );
 
-     $field_info = field_info_field($field_name);
 
-     $instance_info = field_info_instance('TripalEntity', $field_name, $bundle_name);
 
-     $helper = new \TripalFieldTestHelper($bundle_name, $machine_names, $entity1, $field_info, $instance_info);
 
-     $widget_class = $helper->getInitializedClass();
 
-     // Set some initial values.
 
-     $cvterm = factory('chado.cvterm')->create();
 
-     $initial_values = [
 
-       'subject_name' => $entity2->chado_record->name,
 
-       'type_name' => $cvterm->name,
 
-       'vocabulary' => $cvterm->cv_id,
 
-       'object_name' => '',
 
-       // Both the form and load set the chado values
 
-       // so we will set them here as well.
 
-       'chado-'.$base_table.'_relationship__'.$expect['subject_key'] => $entity2->chado_record->{$base_table.'_id'},
 
-       'chado-'.$base_table.'_relationship__type_id' => $cvterm->cvterm_id,
 
-       'chado-'.$base_table.'_relationship__'.$expect['object_key'] => NULL,
 
-     ];
 
-     if ($base_table == 'organism') {
 
-       $initial_values['subject_name'] = $entity2->chado_record->species;
 
-     }
 
-     // Mock objects.
 
-     $delta = 1;
 
-     $langcode = LANGUAGE_NONE;
 
-     $widget = $helper->mockElement($delta, $langcode);
 
-     $form = $helper->mockForm($delta, $langcode);
 
-     $form_state = $helper->mockFormState($delta, $langcode, $initial_values);
 
-     $element = $helper->mockElement($delta, $langcode);
 
-     $widget_class->validate($element, $form, $form_state, $langcode, $delta);
 
-     // @debug print_r($form_state['values'][$field_name][$langcode][$delta]);
 
-     // Ensure the chado-table__column entries are there.
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__'.$expect['subject_key'],
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the subject_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the subject.'
 
-     );
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__'.$expect['object_key'],
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the object_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the object.'
 
-     );
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__type_id',
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the type_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the type.'
 
-     );
 
-     // Check for errors.
 
-     $errors = form_get_errors();
 
-     // @debug print "Errors: " . print_r($errors, TRUE)."\n";
 
-     $this->assertNotEmpty($errors,
 
-       "There should be form errors when the object is not supplied. Initial values: ".print_r($initial_values,TRUE)." But these were registered: ".print_r($errors, TRUE));
 
-     // Clean up after ourselves by removing any errors we logged.
 
-     form_clear_error();
 
-   }
 
-   /**
 
-    * Case: WidgetValidate on new relationship missing type.
 
-    *
 
-    * @dataProvider provideEntities()
 
-    *
 
-    * @group widget
 
-    * @group sbo__relationship
 
-    */
 
-   public function testWidgetValidate_notype($bundle_name, $field_name, $widget_name, $entity_ids, $expect) {
 
-     // Load the entities.
 
-     $entities = entity_load('TripalEntity', $entity_ids);
 
-     $entity1 = $entities[$entity_ids[0]];
 
-     $entity2 = $entities[$entity_ids[1]];
 
-     $base_table = $entity1->chado_table;
 
-     // Initialize the widget class via the TripalFieldTestHelper class.
 
-     $machine_names = array(
 
-       'field_name' => $field_name,
 
-       'widget_name' => $widget_name,
 
-     );
 
-     $field_info = field_info_field($field_name);
 
-     $instance_info = field_info_instance('TripalEntity', $field_name, $bundle_name);
 
-     $helper = new \TripalFieldTestHelper($bundle_name, $machine_names, $entity1, $field_info, $instance_info);
 
-     $widget_class = $helper->getInitializedClass();
 
-     // Set some initial values.
 
-     $initial_values = [
 
-       'subject_name' => $entity2->chado_record->name,
 
-       'type_name' => '',
 
-       'vocabulary' => NULL,
 
-       'object_name' => $entity1->chado_record->name,
 
-       // Both the form and load set the chado values
 
-       // so we will set them here as well.
 
-       'chado-'.$base_table.'_relationship__'.$expect['subject_key'] => $entity2->chado_record->{$base_table.'_id'},
 
-       'chado-'.$base_table.'_relationship__type_id' => NULL,
 
-       'chado-'.$base_table.'_relationship__'.$expect['object_key'] => $entity1->chado_record->{$base_table.'_id'},
 
-     ];
 
-     if ($base_table == 'organism') {
 
-       $initial_values['subject_name'] = $entity2->chado_record->species;
 
-       $initial_values['object_name'] = $entity1->chado_record->species;
 
-     }
 
-     // Mock objects.
 
-     $delta = 1;
 
-     $langcode = LANGUAGE_NONE;
 
-     $widget = $helper->mockElement($delta, $langcode);
 
-     $form = $helper->mockForm($delta, $langcode);
 
-     $form_state = $helper->mockFormState($delta, $langcode, $initial_values);
 
-     $element = $helper->mockElement($delta, $langcode);
 
-     $widget_class->validate($element, $form, $form_state, $langcode, $delta);
 
-     // @debug print_r($form_state['values'][$field_name][$langcode][$delta]);
 
-     // Ensure the chado-table__column entries are there.
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__'.$expect['subject_key'],
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the subject_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the subject.'
 
-     );
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__'.$expect['object_key'],
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the object_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the object.'
 
-     );
 
-     $this->assertArrayHasKey(
 
-       'chado-'.$base_table.'_relationship__type_id',
 
-       $form_state['values'][$field_name][$langcode][$delta],
 
-       'Failed to find the type_id in the processed values (Base: '.$base_table.'). This implies the validate function was not able to validate the type.'
 
-     );
 
-     // Check for errors.
 
-     $errors = form_get_errors();
 
-     // @debug print "Errors: " . print_r($errors, TRUE)."\n";
 
-     $this->assertNotEmpty($errors,
 
-       "There should be form errors when type is not supplied. Initial values: ".print_r($initial_values,TRUE)." But these were registered: ".print_r($errors, TRUE));
 
-     // Clean up after ourselves by removing any errors we logged.
 
-     form_clear_error();
 
-   }
 
- }
 
 
  |