BlastDBNodeTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. // @todo move this into a data seeder.
  75. $node = new \stdClass();
  76. $node->title = "Test Blast Database";
  77. $node->type = "blastdb";
  78. node_object_prepare($node);
  79. $node->language = LANGUAGE_NONE;
  80. $node->uid = $user->uid;
  81. $node->status = 1; // published.
  82. $node->promote = 0; // not promoted.
  83. $node->comment = 0; // disabled.
  84. $node->db_name = 'Test Blast Database';
  85. $node->db_path = '/fake/path/here';
  86. $node->db_dbtype = 'nucleotide';
  87. $node->dbxref_linkout_type = 'none';
  88. $node->cvitjs_enabled = 0;
  89. $node = node_submit($node);
  90. node_save($node);
  91. // Now use the form to edit it :-)
  92. // Specifically, we will change the name and type.
  93. $form_state = array(
  94. 'values' => array(
  95. 'db_name' => 'Test Protein Blast Database',
  96. 'db_path' => '/fake/path/here',
  97. 'db_dbtype' => 'protein',
  98. 'dbxref_linkout_type' => 'none',
  99. 'cvitjs_enabled' => 0,
  100. 'op' => t('Save'),
  101. ),
  102. );
  103. // Execute the node creation form.
  104. drupal_form_submit('blastdb_node_form', $form_state, $node);
  105. // Retrieve any errors.
  106. $errors = form_get_errors();
  107. print_r($errors);
  108. // Assert that there must not be any.
  109. $this->assertEmpty($errors);
  110. // Check that there is a test blast database.
  111. $result = db_query('SELECT * FROM {blastdb} WHERE name=:name AND dbtype=:type',
  112. array(':name' => $form_state['values']['db_name'], ':type' => $form_state['values']['db_dbtype']));
  113. $this->assertEquals($result->rowCount(), 1);
  114. // log out the god user.
  115. $user = drupal_anonymous_user();
  116. }
  117. /**
  118. * Test deleting a node.
  119. * NOTE: We cannot test this via drupal_form_submit() since it requires a confirmation.
  120. */
  121. }