TaxonomyImporterTest.php 2.1 KB

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