TripalChadoAPITest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Tests\tripal_chado\api;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class TripalChadoAPITest extends TripalTestCase {
  6. use DBTransaction;
  7. /**
  8. * Test the ability to publish Chado organism records as entities.
  9. *
  10. * @group api
  11. */
  12. public function test_tripal_chado_publish_records() {
  13. $genus_string = 'a_genius_genus';
  14. //create an organism, publish it
  15. $organism = factory('chado.organism')->create([
  16. 'genus' => $genus_string,
  17. 'species' => 'fake_species',
  18. ]);
  19. //get bundle ID for organism
  20. $bundle = db_select('public.chado_bundle', 'CB')
  21. ->fields('CB', ['bundle_id'])
  22. ->condition('data_table', 'organism')
  23. ->execute()->fetchField();
  24. $values = ['bundle_name' => 'bio_data_' . $bundle];
  25. ob_start();//dont display the job message
  26. $bool = tripal_chado_publish_records($values);
  27. ob_end_clean();
  28. $this->assertTrue($bool, 'Publishing a fake organism record failed');
  29. //ensure that our entity was created
  30. $query = db_select('chado.organism', 'O')
  31. ->fields('O', ['organism_id']);
  32. $query->join('public.chado_bio_data_' . $bundle, 'CBD', 'O.organism_id = CBD.record_id');
  33. $query->condition('O.genus', $genus_string);
  34. $organism_id = $query->execute()->fetchField();
  35. $this->assertNotNull($organism_id, 'Organism with record ID not found in chado_bio_data table.');
  36. }
  37. /**
  38. * Test chado_publish_records returns false given bad bundle.
  39. *
  40. * @group api
  41. */
  42. public function test_tripal_chado_publish_records_false_with_bad_bundle() {
  43. putenv("TRIPAL_SUPPRESS_ERRORS=TRUE");//this will fail, so we suppress the tripal error reporter
  44. $bool = tripal_chado_publish_records(['bundle_name' => 'never_in_a_million_years']);
  45. $this->assertFalse($bool);
  46. putenv("TRIPAL_SUPPRESS_ERRORS");//unset
  47. }
  48. /**
  49. * calls tripal_get_chado_tokens.
  50. *
  51. * @group api
  52. */
  53. public function test_tripal_get_chado_tokens() {
  54. $tokens = tripal_get_chado_tokens('organism');
  55. $this->assertNotEmpty($tokens);
  56. $this->assertArrayHasKey('[organism.organism_id]', $tokens);
  57. }
  58. }