BlastDBApiTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Tests\api;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class BlastDBApiTest extends TripalTestCase {
  6. // Uncomment to auto start and rollback db transactions per test method.
  7. use DBTransaction;
  8. /**
  9. * Tests get_blast_database().
  10. */
  11. public function testGetBlastDB() {
  12. // Create a node to fetch.
  13. $seeder = \Tests\DatabaseSeeders\BlastDBNodeSeeder::seed();
  14. $node = $seeder->getNode();
  15. // Using the nid?
  16. $resultdb = get_blast_database(['nid' => $node->nid]);
  17. $this->assertEquals($node->nid, $resultdb->nid,
  18. "Unable to find the correct blast database based on nid.");
  19. // Using the name.
  20. $resultdb = get_blast_database(['name' => $node->db_name]);
  21. $this->assertEquals($node->nid, $resultdb->nid,
  22. "Unable to find the correct blast database based on name.");
  23. // Using the path.
  24. $resultdb = get_blast_database(['path' => $node->db_path]);
  25. $this->assertEquals($node->nid, $resultdb->nid,
  26. "Unable to find the correct blast database based on path.");
  27. }
  28. /**
  29. * Tests get_blast_database_options().
  30. * @todo test for protein as well.
  31. * @todo test with permissions.
  32. */
  33. public function testGetBlastDBOptions() {
  34. // Create 3 nodes to fetch.
  35. $nodes = array();
  36. $seeder = \Tests\DatabaseSeeders\BlastDBNodeSeeder::seed();
  37. $nodes[] = $seeder->getNode();
  38. $seeder = \Tests\DatabaseSeeders\BlastDBNodeSeeder::seed();
  39. $nodes[] = $seeder->getNode();
  40. $seeder = \Tests\DatabaseSeeders\BlastDBNodeSeeder::seed();
  41. $nodes[] = $seeder->getNode();
  42. $options = get_blast_database_options('nucleotide');
  43. $this->assertGreaterThanOrEqual(3, sizeof($options),
  44. "Did not retrieve all 3 nodes we inserted as options.");
  45. // Check each node we inserted is in the options.
  46. foreach ($nodes as $node) {
  47. $this->assertArrayHasKey($node->nid, $options,
  48. "Unable to find a specific node option that we know should be there.");
  49. }
  50. // Also check get_blast_database_nodes() directly.
  51. $retrieved_nodes = get_blast_database_nodes();
  52. $this->assertGreaterThanOrEqual(3, sizeof($retrieved_nodes),
  53. "Unable to retrieve the nodes at all.");
  54. foreach ($nodes as $node) {
  55. $this->assertArrayHasKey($node->nid, $retrieved_nodes,
  56. "Unable to find a specific node option that we know should be there.");
  57. }
  58. }
  59. }