Bläddra i källkod

Tests: Added database seeder and update test.

Lacey Sanderson 6 år sedan
förälder
incheckning
5cf4a2c876

+ 55 - 0
tests/DatabaseSeeders/JBrowseInstanceNodeSeeder.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace Tests\DatabaseSeeders;
+
+use StatonLab\TripalTestSuite\Database\Seeder;
+use Faker\Factory;
+
+class JBrowseInstanceNodeSeeder extends Seeder
+{
+    /**
+     * Seeds the database with users.
+     *
+     * @return void
+     */
+    public function up()
+    {
+      $faker = Factory::create();
+
+      // Log in the god user.
+      global $user;
+      $user = user_load(1);
+      $node = new \stdClass();
+
+      if (!isset($node->title)) $node->title = $faker->name();
+
+      $node->type = 'jbrowse_instance';
+      node_object_prepare($node);
+
+      $node->language = LANGUAGE_NONE;
+      $node->uid = $user->uid;
+      $node->status = 1;  // published.
+      $node->promote = 0; // not promoted.
+      $node->comment = 0; // disabled.
+
+      $node->field_jburl['und'][0]['url'] = $faker->url();
+      $node->field_datadir['und'][0] = 'fake/path';
+      $node->field_jbloc['und'][0] = $faker->word() .':'. rand(0,1000).'..'.rand(2000, 10000);
+      $node->field_jbtracks['und'][0] = str_replace(' ',',',$faker->words(5,true));
+
+      $node = node_submit($node);
+      node_save($node);
+
+      // log out the god user.
+      $user = drupal_anonymous_user();
+      $this->node = $node;
+
+    }
+
+    /**
+     * Returns the node created by up().
+     */
+     public function getNode() {
+       return $this->node;
+     }
+}

+ 44 - 0
tests/tripal_jbrowse/jbrowseInstanceNodeTest.php

@@ -85,4 +85,48 @@ class jbrowseInstanceNodeTest extends TripalTestCase {
     $user = drupal_anonymous_user();
   }
 
+  /**
+   * Update an existing Blast Database Node.
+   */
+  public function testJBrowseInstanceNodeUpdate() {
+    module_load_include('inc', 'node', 'node.pages');
+
+    // Log in the god user.
+    global $user;
+    $user = user_load(1);
+
+    // Create the node in the first place.
+    $seeder = \Tests\DatabaseSeeders\JBrowseInstanceNodeSeeder::seed();
+    $node = $seeder->getNode();
+
+    // Now use the form to edit it :-)
+    // Specifically, we will change the name, url and data directory.
+    $faker = Factory::create();
+    $form_state = array('values' => array());
+    $form_state['values']['title'] = $faker->words(5, true);
+    $form_state['values']['field_jburl']['und'][0]['url'] = 'https://jbrowse.org/code/JBrowse-1.15.4/';
+    $form_state['values']['field_datadir']['und'][0] = 'sample_data/json/modencode';
+    $form_state['values']['op'] = t('Save');
+
+    // Execute the node creation form.
+    drupal_form_submit('jbrowse_instance_node_form', $form_state, $node);
+
+    // Retrieve any errors.
+    $errors = form_get_errors();
+    // Assert that there must not be any.
+    $this->assertEmpty($errors, 'Form submission returned the following errors:'.print_r($errors,TRUE));
+
+    // Check that there is a test jbrowse instance.
+    $result = db_query('SELECT * FROM {node} WHERE title=:name',
+      array(':name' => $form_state['values']['title']));
+    $this->assertEquals(1, $result->rowCount(), 'Unable to select the JBrowse Instance using the name.');
+
+    // log out the god user.
+    $user = drupal_anonymous_user();
+  }
+
+  /**
+   * Test deleting a node.
+   * NOTE: We cannot test this via drupal_form_submit() since it requires a confirmation.
+   */
 }