TaxonomyImporterTest.php 1.9 KB

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