BlastDBApiTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. */
  31. public function testGetBlastDBOptions() {
  32. // Create 3 nodes to fetch.
  33. $nodes = array();
  34. $seeder = \Tests\DatabaseSeeders\BlastDBNodeSeeder::seed();
  35. $nodes[] = $seeder->getNode();
  36. $seeder = \Tests\DatabaseSeeders\BlastDBNodeSeeder::seed();
  37. $nodes[] = $seeder->getNode();
  38. $seeder = \Tests\DatabaseSeeders\BlastDBNodeSeeder::seed();
  39. $nodes[] = $seeder->getNode();
  40. $options = get_blast_database_options('nucleotide');
  41. $this->assertGreaterThanOrEqual(3, sizeof($options),
  42. "Did not retrieve all 3 nodes we inserted as options.");
  43. // Check each node we inserted is in the options.
  44. foreach ($nodes as $node) {
  45. $this->assertArrayHasKey($node->nid, $options,
  46. "Unable to find a specific node option that we know should be there.");
  47. }
  48. }
  49. }