jbrowseInstanceNodeTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace Tests\tripal_jbrowse;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. use Faker\Factory;
  6. /**
  7. * Tests the JBrowse Instance Node Type.
  8. */
  9. class jbrowseInstanceNodeTest extends TripalTestCase {
  10. // Uncomment to auto start and rollback db transactions per test method.
  11. use DBTransaction;
  12. /**
  13. * JBrowse Instance Node Type exists.
  14. *
  15. * Check that the JBrowse Instance node type exists. It should be created
  16. * when the module is installed by the Drupal Node API.
  17. */
  18. public function testJbrowseInstanceNodeTypeExists() {
  19. if (!module_exists('tripal_jbrowse')) {
  20. $this->markTestSkipped('No need to test if not enabled.');
  21. }
  22. // Get a list of all types available.
  23. $types = node_type_get_types();
  24. // The JBrowse Instance node type must be in the list.
  25. $this->assertArrayHasKey('jbrowse_instance', $types, '"JBrowse Instance" node type is not registered with Drupal.');
  26. // Check that the expected fields exist and are attached to the JBrowse instance node type.
  27. // First retrieve all fields for this node type.
  28. $fields = field_info_instances('node', 'jbrowse_instance');
  29. // Now check that those important to us, exist.
  30. $this->assertArrayHasKey('field_jburl', $fields,
  31. 'The "Existing JBrowse URL" field is not attached to the JBrowse Instance node type.');
  32. $this->assertArrayHasKey('field_datadir', $fields,
  33. 'The "Data Directory" field is not attached to the JBrowse Instance node type.');
  34. $this->assertArrayHasKey('field_jbloc', $fields,
  35. 'The "Start Location" field is not attached to the JBrowse Instance node type.');
  36. $this->assertArrayHasKey('field_jbtracks', $fields,
  37. 'The "Tracks to Display" field is not attached to the JBrowse Instance node type.');
  38. }
  39. /**
  40. * Test Creating a JBrowse Instance Node.
  41. *
  42. * Note: We can't test this by submitting the form via PUT because it requires
  43. * permission to access /node/add/jbrowse_instance; however, we don't yet have a
  44. * way to do this with TripalTestSuite. Furthermore, testing HTTP Requests
  45. * would not give us access to the data added via the test due to database
  46. * transactions.
  47. */
  48. public function testJBrowseInstanceNodeCreate() {
  49. module_load_include('inc', 'node', 'node.pages');
  50. if (!module_exists('tripal_jbrowse')) {
  51. $this->markTestSkipped('No need to test if not enabled.');
  52. }
  53. // Log in the god user.
  54. global $user;
  55. $user = user_load(1);
  56. $node = array('type' => 'jbrowse_instance');
  57. // Fill in the form.
  58. $faker = Factory::create();
  59. $form_state = array('values' => array());
  60. $form_state['values']['title'] = $faker->words(3, true);
  61. $form_state['values']['field_jburl']['und'][0]['url'] = 'https://jbrowse.org/code/JBrowse-1.15.4/';
  62. $form_state['values']['field_datadir']['und'][0] = 'sample_data/json/volvox';
  63. $form_state['values']['field_jbloc']['und'][0] = 'ctgA:1..11000';
  64. $form_state['values']['field_jbtracks']['und'][0] = 'DNA,Genes,volvox-sorted-vcf,volvox_microarray_bw_density,volvox_bb';
  65. $form_state['values']['op'] = t('Save');
  66. // Execute the node creation form.
  67. drupal_form_submit('jbrowse_instance_node_form', $form_state, (object) $node);
  68. // Retrieve any errors.
  69. $errors = form_get_errors();
  70. // Assert that there must not be any.
  71. $this->assertEmpty($errors, 'Form submission returned the following errors:'.print_r($errors,TRUE));
  72. // Check that there is a test jbrowse instance.
  73. $result = db_query('SELECT * FROM {node} WHERE title=:name',
  74. array(':name' => $form_state['values']['title']));
  75. $this->assertEquals(1, $result->rowCount(), 'Unable to select the JBrowse Instance using the name.');
  76. // log out the god user.
  77. $user = drupal_anonymous_user();
  78. }
  79. /**
  80. * Update an existing Blast Database Node.
  81. */
  82. public function testJBrowseInstanceNodeUpdate() {
  83. module_load_include('inc', 'node', 'node.pages');
  84. if (!module_exists('tripal_jbrowse')) {
  85. $this->markTestSkipped('No need to test if not enabled.');
  86. }
  87. // Log in the god user.
  88. global $user;
  89. $user = user_load(1);
  90. // Create the node in the first place.
  91. $seeder = \Tests\DatabaseSeeders\JBrowseInstanceNodeSeeder::seed();
  92. $node = $seeder->getNode();
  93. // Now use the form to edit it :-)
  94. // Specifically, we will change the name, url and data directory.
  95. $faker = Factory::create();
  96. $form_state = array('values' => array());
  97. $form_state['values']['title'] = $faker->words(5, true);
  98. $form_state['values']['field_jburl']['und'][0]['url'] = 'https://jbrowse.org/code/JBrowse-1.15.4/';
  99. $form_state['values']['field_datadir']['und'][0] = 'sample_data/json/modencode';
  100. $form_state['values']['op'] = t('Save');
  101. // Execute the node creation form.
  102. drupal_form_submit('jbrowse_instance_node_form', $form_state, $node);
  103. // Retrieve any errors.
  104. $errors = form_get_errors();
  105. // Assert that there must not be any.
  106. $this->assertEmpty($errors, 'Form submission returned the following errors:'.print_r($errors,TRUE));
  107. // Check that there is a test jbrowse instance.
  108. $result = db_query('SELECT * FROM {node} WHERE title=:name',
  109. array(':name' => $form_state['values']['title']));
  110. $this->assertEquals(1, $result->rowCount(), 'Unable to select the JBrowse Instance using the name.');
  111. // log out the god user.
  112. $user = drupal_anonymous_user();
  113. }
  114. /**
  115. * Test deleting a node.
  116. * NOTE: We cannot test this via drupal_form_submit() since it requires a confirmation.
  117. */
  118. }