TaxonomyImporterTest.php 2.0 KB

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