TaxonomyImporterTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. module_load_include('inc', 'tripal_chado', 'TripalImporter/TaxonomyImporter.inc');
  7. class TaxonomyImporterTest extends TripalTestCase {
  8. use DBTransaction;
  9. /*
  10. * Adds an organism and checks that the importer runs and adds some properties to it.
  11. *
  12. */
  13. public function testImportExistingTaxonomyLoader() {
  14. $org = [
  15. 'genus' => 'Armadillo',
  16. 'species' => 'officinalis',
  17. 'abbreviation' => 'A. officinalis',
  18. 'common_name' => 'pillbug',
  19. 'type_id' => null
  20. ];
  21. $organism = factory('chado.organism')->create($org);
  22. // $this->publish('organism');
  23. $file = [];
  24. $run_args = ['import_existing' => TRUE];
  25. $importer = new \TaxonomyImporter();
  26. ob_start();
  27. $importer->create($run_args, $file);
  28. $importer->run();
  29. ob_end_clean();
  30. $query = db_select('chado.organism', 'o');
  31. $query->join('chado.organismprop', 'op', 'o.organism_id = op.organism_id');
  32. $query->fields('op', ['value'])
  33. ->condition('o.organism_id', $organism->organism_id);
  34. $result = $query->execute()->fetchAll();
  35. $this->assertNotEmpty($result);
  36. }
  37. /**
  38. * the importer can also load an array of pubmed ids. We use the pillbug 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. $file = [];
  46. $run_args = ['taxonomy_ids' => '96821']; //its the pillbug again!
  47. $importer = new \TaxonomyImporter();
  48. ob_start();
  49. $importer->create($run_args, $file);
  50. $importer->run();
  51. ob_end_clean();
  52. $query = db_select('chado.organism', 'o');
  53. $query->fields('o', ['genus'])
  54. ->condition('o.species', 'officinalis');
  55. $result = $query->execute()->fetchField();
  56. $this->assertEquals('Armadillo', $result);
  57. }
  58. }