TaxonomyImporterTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. */
  14. public function testImportExistingTaxonomyLoader() {
  15. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/TaxonomyImporter');
  16. $org = [
  17. 'genus' => 'Armadillo',
  18. 'species' => 'officinalis',
  19. 'abbreviation' => 'A. officinalis',
  20. 'common_name' => 'pillbug',
  21. 'type_id' => NULL,
  22. ];
  23. $organism = factory('chado.organism')->create($org);
  24. $file = [];
  25. $run_args = ['import_existing' => TRUE];
  26. $importer = new \TaxonomyImporter();
  27. ob_start();
  28. $importer->create($run_args, $file);
  29. $importer->run();
  30. ob_end_clean();
  31. $query = db_select('chado.organism', 'o');
  32. $query->join('chado.organismprop', 'op', 'o.organism_id = op.organism_id');
  33. $query->fields('op', ['value'])
  34. ->condition('o.organism_id', $organism->organism_id);
  35. $result = $query->execute()->fetchAll();
  36. $this->assertNotEmpty($result);
  37. }
  38. /**
  39. * The importer can also load an array of pubmed ids. We use the pillbug
  40. * again.
  41. *
  42. * Https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=96821
  43. *
  44. * @throws \Exception
  45. */
  46. public function testImportOrganismFromTaxID() {
  47. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/TaxonomyImporter');
  48. $file = [];
  49. // Its the pillbug again!
  50. $run_args = ['taxonomy_ids' => '96821'];
  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. }