TaxonomyImporterTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. $prev_db = chado_set_active('chado');
  14. chado_query('TRUNCATE TABLE {organism} CASCADE');
  15. chado_set_active($prev_db);
  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. // $this->publish('organism');
  25. $file = [];
  26. $run_args = ['import_existing' => TRUE];
  27. $importer = new \TaxonomyImporter();
  28. $importer->create($run_args, $file);
  29. $importer->run();
  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
  39. * again.
  40. *
  41. * https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=96821
  42. *
  43. * @throws \Exception
  44. */
  45. public function testImportOrganismFromTaxID() {
  46. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/TaxonomyImporter');
  47. $file = [];
  48. $run_args = ['taxonomy_ids' => '96821']; //its the pillbug again!
  49. $importer = new \TaxonomyImporter();
  50. $importer->create($run_args, $file);
  51. $importer->run();
  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. }