TripalChadoAPITest.php 2.1 KB

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