BlastDBNodeTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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' => 0,
  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. /**
  67. * Update an existing Blast Database Node.
  68. */
  69. public function testBlastDBNodeUpdate() {
  70. // Log in the god user.
  71. global $user;
  72. $user = user_load(1);
  73. // Create the node in the first place.
  74. $node = DatabaseSeeders\BlastDBNodeSeeder::seed();
  75. $node = get_blast_database(array('name' => 'Test Blast Database'));
  76. // Now use the form to edit it :-)
  77. // Specifically, we will change the name and type.
  78. $form_state = array(
  79. 'values' => array(
  80. 'db_name' => 'Test Protein Blast Database',
  81. 'db_path' => $node->db_path,
  82. 'db_dbtype' => 'protein',
  83. 'dbxref_linkout_type' => $node->dbxref_linkout_type,
  84. 'cvitjs_enabled' => $node->cvitjs_enabled,
  85. 'op' => t('Save'),
  86. ),
  87. );
  88. // Execute the node creation form.
  89. drupal_form_submit('blastdb_node_form', $form_state, $node);
  90. // Retrieve any errors.
  91. $errors = form_get_errors();
  92. print_r($errors);
  93. // Assert that there must not be any.
  94. $this->assertEmpty($errors);
  95. // Check that there is a test blast database.
  96. $result = db_query('SELECT * FROM {blastdb} WHERE name=:name AND dbtype=:type',
  97. array(':name' => $form_state['values']['db_name'], ':type' => $form_state['values']['db_dbtype']));
  98. $this->assertEquals($result->rowCount(), 1);
  99. // log out the god user.
  100. $user = drupal_anonymous_user();
  101. }
  102. /**
  103. * Test deleting a node.
  104. * NOTE: We cannot test this via drupal_form_submit() since it requires a confirmation.
  105. */
  106. }