TaxonomyImporterTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Tests\tripal_chado;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. /**
  6. *
  7. */
  8. class TaxonomyImporterTest extends TripalTestCase {
  9. use DBTransaction;
  10. /**
  11. * Adds an organism and checks that the importer runs and adds some properties to it.
  12. *
  13. * @group waffle
  14. */
  15. public function testImportExistingTaxonomyLoader() {
  16. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/TaxonomyImporter');
  17. $org = [
  18. 'genus' => 'Armadillo',
  19. 'species' => 'officinalis',
  20. 'abbreviation' => 'A. officinalis',
  21. 'common_name' => 'pillbug',
  22. 'type_id' => NULL,
  23. ];
  24. // Speed up test an ensure no organisms
  25. // in db since it will check all.
  26. $prev_db = chado_set_active('chado');
  27. chado_query('TRUNCATE TABLE {organism} CASCADE');
  28. chado_set_active($prev_db);
  29. $organism = factory('chado.organism')->create($org);
  30. // $this->publish('organism');.
  31. $file = [];
  32. $run_args = ['import_existing' => TRUE];
  33. $importer = new \TaxonomyImporter();
  34. ob_start();
  35. $importer->create($run_args, $file);
  36. $importer->run();
  37. ob_end_clean();
  38. $query = db_select('chado.organism', 'o');
  39. $query->join('chado.organismprop', 'op', 'o.organism_id = op.organism_id');
  40. $query->fields('op', ['value'])
  41. ->condition('o.organism_id', $organism->organism_id);
  42. $result = $query->execute()->fetchAll();
  43. $this->assertNotEmpty($result);
  44. }
  45. /**
  46. * The importer can also load an array of pubmed ids. We use the pillbug
  47. * again.
  48. *
  49. * Https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=96821
  50. *
  51. * @throws \Exception
  52. */
  53. public function testImportOrganismFromTaxID() {
  54. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/TaxonomyImporter');
  55. $file = [];
  56. // Its the pillbug again!
  57. $run_args = ['taxonomy_ids' => '96821'];
  58. $importer = new \TaxonomyImporter();
  59. ob_start();
  60. $importer->create($run_args, $file);
  61. $importer->run();
  62. ob_end_clean();
  63. $query = db_select('chado.organism', 'o');
  64. $query->fields('o', ['genus'])
  65. ->condition('o.species', 'officinalis');
  66. $result = $query->execute()->fetchField();
  67. $this->assertEquals('Armadillo', $result);
  68. }
  69. }