Browse Source

Merge pull request #20 from statonlab/chado_organism_tests

final organism api tests
Bradford Condon 6 years ago
parent
commit
ddc1b4ef5c

+ 1 - 4
tests/tripal_chado/api/TripalChadoAPITest.php

@@ -66,9 +66,6 @@ class TripalChadoAPITest extends TripalTestCase {
   public function test_tripal_get_chado_tokens(){
     $tokens = tripal_get_chado_tokens('organism');
     $this->assertNotEmpty($tokens);
-    $this->assertArrayHasKey('organism.organism_id', $tokens);
+    $this->assertArrayHasKey('[organism.organism_id]', $tokens);
   }
-
-
-
 }

+ 114 - 0
tests/tripal_chado/api/TripalChadoOrganismAPITest.php

@@ -0,0 +1,114 @@
+<?php
+
+
+use StatonLab\TripalTestSuite\DBTransaction;
+use StatonLab\TripalTestSuite\TripalTestCase;
+
+class TripalChadoOrganismAPITest extends TripalTestCase {
+
+  use DBTransaction;
+
+
+  /**
+   * Test tripal_get_organism.
+   *
+   * @group api
+   */
+  public function test_tripal_get_organism() {
+
+    $genus_string = 'a_genius_genus';
+    $species_string = 'fake_species';
+
+    $organism = factory('chado.organism')->create([
+      'genus' => $genus_string,
+      'species' => $species_string,
+    ]);
+
+    $results = [];
+
+    $results[] = tripal_get_organism(['organism_id' => $organism->organism_id]);
+    $results[] = tripal_get_organism([
+      'genus' => $genus_string,
+      'species' => $species_string,
+    ]);
+
+    foreach ($results as $result) {
+      $this->assertNotFalse($result);
+      $this->assertNotNull($result);
+      $this->assertObjectHasAttribute('genus', $result);
+      $this->assertEquals($genus_string, $result->genus);
+    }
+  }
+
+  public function test_tripal_get_organism_fails_gracefully() {
+    $result = tripal_get_organism([
+      'genus' => uniqid(),
+      'species' => uniqid(),
+    ]);
+
+    $this->assertNull($result);
+  }
+
+  /**
+   * Test tripal_get_organism_scientific_name
+   *
+   * @group  api
+   */
+  function test_tripal_get_organism_scientific_name() {
+
+    $genus_string = 'a_genius_genus';
+    $species_string = 'fake_species';
+    $infraspecific_name = "infrawhat?";
+    $term = factory('chado.cvterm')->create();
+
+    $organism = factory('chado.organism')->create([
+      'genus' => $genus_string,
+      'species' => $species_string,
+      'infraspecific_name' => $infraspecific_name,
+      'type_id' => $term->cvterm_id,
+    ]);
+
+    $sci_name = tripal_get_organism_scientific_name($organism);
+    $this->assertEquals(implode(" ", [
+      $genus_string,
+      $species_string,
+      $term->name,
+      $infraspecific_name,
+    ]), $sci_name);
+
+  }
+
+  //TODO: Can't test because it uses drupal_json_output.
+  //Need HTTP testing.
+  //
+  //  function test_tripal_autocomplete_organism(){
+  //
+  //    $genus_string = 'a_genius_genus';
+  //    $species_string = 'fake_species';
+  //
+  //    $organism = factory('chado.organism')->create([
+  //      'genus' => $genus_string,
+  //      'species' => $species_string,
+  //    ]);
+  //
+  //    tripal_autocomplete_organism(substr($genus_string, 0, 4));
+  //
+  //   //$this->assertEquals($genus_string, $auto_complete);
+  //  }
+
+  //This function is Tripal 2, and needs to be updated or deprecated
+
+  //  function test_tripal_get_organism_select_options_sycned_only_false(){
+  //
+  //    db_truncate('chado.organism');
+  //    factory('chado.organism', 20)->create();
+  //
+  //    $options = tripal_get_organism_select_options(FALSE);
+  //
+  //    $this->assertNotEmpty($options);
+  //    $this->assertGreaterThan(20, count($options));
+  //
+  //  }
+
+
+}

+ 2 - 2
tripal_chado/api/modules/tripal_chado.organism.api.inc

@@ -34,7 +34,7 @@
  * @return
  *   If unique values were passed in as an identifier then an object describing the organism
  *   will be returned (will be a chado variable from chado_generate_var()). Otherwise,
- *   FALSE will be returned.
+ *   NULL will be returned.
  *
  * @ingroup tripal_organism_api
  */
@@ -144,7 +144,7 @@ function tripal_get_organism_scientific_name($organism) {
     // For organism objects crated using chado_generate_var
     if (is_object($organism->type_id)) {
       if ($organism->type_id) {
-        $rank = $orgasnism->type_id->name;
+        $rank = $organism->type_id->name;
       }
     }
     else {