TaxonomyImporterTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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
  12. * properties to it.
  13. *
  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. $organism = factory('chado.organism')->create($org);
  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. // Its the pillbug again!
  51. $run_args = ['taxonomy_ids' => '96821'];
  52. $importer = new \TaxonomyImporter();
  53. ob_start();
  54. $importer->create($run_args, $file);
  55. $importer->run();
  56. ob_end_clean();
  57. $query = db_select('chado.organism', 'o');
  58. $query->fields('o', ['genus'])
  59. ->condition('o.species', 'officinalis');
  60. $result = $query->execute()->fetchField();
  61. $this->assertEquals('Armadillo', $result);
  62. }
  63. }