TripalChadoOrganismAPITest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. use StatonLab\TripalTestSuite\DBTransaction;
  3. use StatonLab\TripalTestSuite\TripalTestCase;
  4. class TripalChadoOrganismAPITest extends TripalTestCase {
  5. use DBTransaction;
  6. /**
  7. * Test tripal_get_organism.
  8. *
  9. * @group api
  10. */
  11. public function test_tripal_get_organism() {
  12. $genus_string = 'a_genius_genus';
  13. $species_string = 'fake_species';
  14. $organism = factory('chado.organism')->create([
  15. 'genus' => $genus_string,
  16. 'species' => $species_string,
  17. ]);
  18. $results = [];
  19. $results[] = tripal_get_organism(['organism_id' => $organism->organism_id]);
  20. $results[] = tripal_get_organism([
  21. 'genus' => $genus_string,
  22. 'species' => $species_string,
  23. ]);
  24. foreach ($results as $result) {
  25. $this->assertNotFalse($result);
  26. $this->assertNotNull($result);
  27. $this->assertObjectHasAttribute('genus', $result);
  28. $this->assertEquals($genus_string, $result->genus);
  29. }
  30. }
  31. public function test_tripal_get_organism_fails_gracefully() {
  32. $result = tripal_get_organism([
  33. 'genus' => uniqid(),
  34. 'species' => uniqid(),
  35. ]);
  36. $this->assertNull($result);
  37. }
  38. /**
  39. * Test tripal_get_organism_scientific_name
  40. *
  41. * @group api
  42. */
  43. function test_tripal_get_organism_scientific_name() {
  44. $genus_string = 'a_genius_genus';
  45. $species_string = 'fake_species';
  46. $infraspecific_name = "infrawhat?";
  47. $term = factory('chado.cvterm')->create();
  48. $organism = factory('chado.organism')->create([
  49. 'genus' => $genus_string,
  50. 'species' => $species_string,
  51. 'infraspecific_name' => $infraspecific_name,
  52. 'type_id' => $term->cvterm_id,
  53. ]);
  54. $sci_name = tripal_get_organism_scientific_name($organism);
  55. $this->assertEquals(implode(" ", [
  56. $genus_string,
  57. $species_string,
  58. $term->name,
  59. $infraspecific_name,
  60. ]), $sci_name);
  61. }
  62. //TODO: Can't test because it uses drupal_json_output.
  63. //Need HTTP testing.
  64. //
  65. // function test_tripal_autocomplete_organism(){
  66. //
  67. // $genus_string = 'a_genius_genus';
  68. // $species_string = 'fake_species';
  69. //
  70. // $organism = factory('chado.organism')->create([
  71. // 'genus' => $genus_string,
  72. // 'species' => $species_string,
  73. // ]);
  74. //
  75. // tripal_autocomplete_organism(substr($genus_string, 0, 4));
  76. //
  77. // //$this->assertEquals($genus_string, $auto_complete);
  78. // }
  79. //This function is Tripal 2, and needs to be updated or deprecated
  80. // function test_tripal_get_organism_select_options_sycned_only_false(){
  81. //
  82. // db_truncate('chado.organism');
  83. // factory('chado.organism', 20)->create();
  84. //
  85. // $options = tripal_get_organism_select_options(FALSE);
  86. //
  87. // $this->assertNotEmpty($options);
  88. // $this->assertGreaterThan(20, count($options));
  89. //
  90. // }
  91. }