BlastDBNodeTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Tests;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. /**
  6. * Tests BlastDB Node CRUD
  7. */
  8. class BlastDBNodeTest extends TripalTestCase {
  9. // Uncomment to auto start and rollback db transactions per test method.
  10. use DBTransaction;
  11. /**
  12. * BlastDB Node Type exists.
  13. *
  14. * Check that the BlastDB node type exists. It should be created
  15. * when the module is installed by the Drupal Node API.
  16. */
  17. public function testBlastDBNodeExists() {
  18. // Get a list of all types available.
  19. $types = node_type_get_types();
  20. // The BlastDB node type must be in the list.
  21. $this->assertArrayHasKey('blastdb', $types);
  22. // Additionally, the blastdb node type should be created by blast_ui.\
  23. // This checks the case where the node type might be created by
  24. // a different module.
  25. $this->assertEquals($types['blastdb']->module, 'blast_ui');
  26. }
  27. /**
  28. * Test Creating a BlastDB Node.
  29. *
  30. * Note: We can't test this by submitting the form via PUT because it requires
  31. * permission to access /node/add/blastdb; however, we don't yet have a
  32. * way to do this with TripalTestSuite. Furthermore, testing HTTP Requests
  33. * would not give us access to the data added via the test due to database
  34. * transactions.
  35. */
  36. public function testBlastDBNodeCreate() {
  37. // Log in the god user.
  38. global $user;
  39. $user = user_load(1);
  40. $node = array('type' => 'blastdb');
  41. // Fill in the form.
  42. $form_state = array(
  43. 'values' => array(
  44. 'db_name' => 'Test Blast Database',
  45. 'db_path' => '/fake/path/here',
  46. 'db_dbtype' => 'nucleotide',
  47. 'dbxref_linkout_type' => 'none',
  48. 'cvitjs_enabled' => FALSE,
  49. 'op' => t('Save'),
  50. ),
  51. );
  52. // Execute the node creation form.
  53. drupal_form_submit('blastdb_node_form', $form_state, (object) $node);
  54. // Retrieve any errors.
  55. $errors = form_get_errors();
  56. //print_r($errors);
  57. // Assert that there must not be any.
  58. $this->assertEmpty($errors);
  59. // Check that there is a test blast database.
  60. $result = db_query('SELECT * FROM {blastdb} WHERE name=:name',
  61. array(':name' => $form_state['values']['db_name']));
  62. $this->assertEquals($result->rowCount(), 1);
  63. // log out the god user.
  64. $user = drupal_anonymous_user();
  65. }
  66. }