TripalChadoAPITest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * @group failing
  12. */
  13. public function test_tripal_chado_publish_records() {
  14. $genus_string = 'a_genius_genus';
  15. //create an organism, publish it
  16. $organism = factory('chado.organism')->create([
  17. 'genus' => $genus_string,
  18. 'species' => 'fake_species',
  19. ]);
  20. //get bundle ID for organism
  21. $bundle = db_select('public.chado_bundle', 'CB')
  22. ->fields('CB', ['bundle_id'])
  23. ->condition('data_table', 'organism')
  24. ->execute()->fetchField();
  25. var_dump($bundle);
  26. $values = ['bundle_name' => 'bio_data_' . $bundle];
  27. // ob_start();//dont display the job message
  28. $bool = chado_publish_records($values);
  29. // ob_end_clean();
  30. $this->assertTrue($bool, 'Publishing a fake organism record failed');
  31. //ensure that our entity was created
  32. $query = db_select('chado.organism', 'O')
  33. ->fields('O', ['organism_id']);
  34. $query->join('public.chado_bio_data_' . $bundle, 'CBD', 'O.organism_id = CBD.record_id');
  35. $query->condition('O.genus', $genus_string);
  36. $organism_id = $query->execute()->fetchField();
  37. $this->assertNotNull($organism_id, 'Organism with record ID not found in chado_bio_data table.');
  38. }
  39. /**
  40. * Test chado_publish_records returns false given bad bundle.
  41. *
  42. * @group api
  43. */
  44. public function test_tripal_chado_publish_records_false_with_bad_bundle() {
  45. putenv("TRIPAL_SUPPRESS_ERRORS=TRUE");//this will fail, so we suppress the tripal error reporter
  46. $bool = chado_publish_records(['bundle_name' => 'never_in_a_million_years']);
  47. $this->assertFalse($bool);
  48. putenv("TRIPAL_SUPPRESS_ERRORS");//unset
  49. }
  50. /**
  51. * calls chado_get_tokens.
  52. *
  53. * @group api
  54. */
  55. public function test_chado_get_tokens() {
  56. $tokens = chado_get_tokens('organism');
  57. $this->assertNotEmpty($tokens);
  58. $this->assertArrayHasKey('[organism.organism_id]', $tokens);
  59. }
  60. }