Browse Source

Tests: Create blastdb node.

Lacey Sanderson 6 years ago
parent
commit
0946b60abf
3 changed files with 82 additions and 26 deletions
  1. 1 1
      includes/blast_ui.node.inc
  2. 81 0
      tests/BlastDBNodeTest.php
  3. 0 25
      tests/ExampleTest.php

+ 1 - 1
includes/blast_ui.node.inc

@@ -302,7 +302,7 @@ function blastdb_form_validate($form, $form_state) {
   }
 
   // Check that there is a cvitjs section for the current
-  if ($form_state['values']['cvitjs_enabled']) {
+  if (isset($form_state['values']['cvitjs_enabled']) AND $form_state['values']['cvitjs_enabled']) {
     $conf_section = blast_ui_get_cvit_conf_text('data.'.$form_state['values']['db_name']);
     if (!$conf_section) {
       drupal_set_message('There is no section for this genome target defined in the CViTjs

+ 81 - 0
tests/BlastDBNodeTest.php

@@ -0,0 +1,81 @@
+<?php
+namespace Tests;
+
+use StatonLab\TripalTestSuite\DBTransaction;
+use StatonLab\TripalTestSuite\TripalTestCase;
+
+/**
+ * Tests BlastDB Node CRUD
+ */
+class BlastDBNodeTest extends TripalTestCase {
+  // Uncomment to auto start and rollback db transactions per test method.
+  use DBTransaction;
+
+  /**
+   * BlastDB Node Type exists.
+   *
+   * Check that the BlastDB node type exists. It should be created
+   * when the module is installed by the Drupal Node API.
+   */
+  public function testBlastDBNodeExists() {
+
+    // Get a list of all types available.
+    $types = node_type_get_types();
+
+    // The BlastDB node type must be in the list.
+    $this->assertArrayHasKey('blastdb', $types);
+
+    // Additionally, the blastdb node type should be created by blast_ui.\
+    // This checks the case where the node type might be created by
+    // a different module.
+    $this->assertEquals($types['blastdb']->module, 'blast_ui');
+  }
+
+  /**
+   * Test Creating a BlastDB Node.
+   *
+   * Note: We can't test this by submitting the form via PUT because it requires
+   *  permission to access /node/add/blastdb; however, we don't yet have a
+   *  way to do this with TripalTestSuite. Furthermore, testing HTTP Requests
+   *  would not give us access to the data added via the test due to database
+   *  transactions.
+   */
+  public function testBlastDBNodeCreate() {
+
+    // Log in the god user.
+    global $user;
+	  $user = user_load(1);
+
+	  $node = array('type' => 'blastdb');
+
+	  // Fill in the form.
+	  $form_state = array(
+	    'values' => array(
+  	    'db_name' => 'Test Blast Database',
+	      'db_path' => '/fake/path/here',
+	      'db_dbtype' => 'nucleotide',
+	      'dbxref_linkout_type' => 'none',
+	      'cvitjs_enabled' => FALSE,
+	      'op' => t('Save'),
+	    ),
+	  );
+
+	  // Execute the node creation form.
+	  drupal_form_submit('blastdb_node_form', $form_state, (object) $node);
+
+    // Retrieve any errors.
+    $errors = form_get_errors();
+    //print_r($errors);
+
+    // Assert that there must not be any.
+    $this->assertEmpty($errors);
+
+    // Check that there is a test blast database.
+    $result = db_query('SELECT * FROM {blastdb} WHERE name=:name',
+      array(':name' => $form_state['values']['db_name']));
+    $this->assertEquals($result->rowCount(), 1);
+
+	  // log out the god user.
+	  $user = drupal_anonymous_user();
+  }
+}

+ 0 - 25
tests/ExampleTest.php

@@ -1,25 +0,0 @@
-<?php
-
-namespace Tests;
-
-use StatonLab\TripalTestSuite\DBTransaction;
-use StatonLab\TripalTestSuite\TripalTestCase;
-
-/**
- * Class ExampleTest
- *
- * Note that test classes must have a suffix of Test.php and the filename
- * must match the class name.
- *
- * @package Tests
- */
-class ExampleTest extends TripalTestCase {
-  /**
-   * Basic test example.
-   * Tests must begin with the word "test".
-   * See https://phpunit.readthedocs.io/en/latest/ for more information.
-   */
-  public function testBasicExample() {
-    $this->assertTrue(true);
-  }
-}