TripalChadoAPITest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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()
  25. ->fetchField();
  26. $values = ['bundle_name' => 'bio_data_' . $bundle];
  27. // Don't display the job message
  28. $bool = silent(function () use ($values) {
  29. return chado_publish_records($values);
  30. });
  31. $this->assertTrue($bool->getReturnValue(),
  32. 'Publishing a fake organism record failed');
  33. // Ensure that our entity was created
  34. $query = db_select('chado.organism', 'O')->fields('O', ['organism_id']);
  35. $query->join('public.chado_bio_data_' . $bundle, 'CBD',
  36. 'O.organism_id = CBD.record_id');
  37. $query->condition('O.genus', $genus_string);
  38. $organism_id = $query->execute()->fetchField();
  39. $this->assertNotNull($organism_id,
  40. 'Organism with record ID not found in chado_bio_data table.');
  41. }
  42. /**
  43. * Test chado_publish_records returns false given bad bundle.
  44. *
  45. * @group api
  46. */
  47. public function test_tripal_chado_publish_records_false_with_bad_bundle() {
  48. $bool = silent(function () {
  49. return chado_publish_records(['bundle_name' => 'never_in_a_million_years']);
  50. });
  51. $this->assertFalse($bool->getReturnValue());
  52. }
  53. /**
  54. * calls chado_get_tokens.
  55. *
  56. * @group api
  57. */
  58. public function test_chado_get_tokens() {
  59. $tokens = chado_get_tokens('organism');
  60. $this->assertNotEmpty($tokens);
  61. $this->assertArrayHasKey('[organism.organism_id]', $tokens);
  62. }
  63. }