TripalChadoOrganismAPITest.php 2.9 KB

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