Преглед на файлове

Chado api tests (#18)

* add exception to error handler for testing purposes
* finalize simple chado api test
Bradford Condon преди 7 години
родител
ревизия
4c35799308
променени са 2 файла, в които са добавени 44 реда и са изтрити 7 реда
  1. 42 7
      tests/tripal_chado/api/TripalChadoAPITest.php
  2. 2 0
      tripal/api/tripal.notice.api.inc

+ 42 - 7
tests/tripal_chado/api/TripalChadoAPITest.php

@@ -10,22 +10,24 @@ class TripalChadoAPITest extends TripalTestCase {
 
 
   /**
+   * Test the ability to publish Chado organism records as entities.
    *
-   *@test
+   * @group api
    */
 
-  public function test_tripal_chado_publish_records(){
+  public function test_tripal_chado_publish_records() {
 
+    $genus_string = 'a_genius_genus';
     //create an organism, publish it
     $organism = factory('chado.organism')->create([
-      'genus' => 'a_genius_genus',
+      'genus' => $genus_string,
       'species' => 'fake_species',
     ]);
     //get bundle ID for organism
     $bundle = db_select('public.chado_bundle', 'CB')
-    ->fields('CB', ['bundle_id'])
-    ->condition('data_table', 'organism')
-    ->execute()->fetchField();
+      ->fields('CB', ['bundle_id'])
+      ->condition('data_table', 'organism')
+      ->execute()->fetchField();
 
     $values = ['bundle_name' => 'bio_data_' . $bundle];
 
@@ -34,6 +36,39 @@ class TripalChadoAPITest extends TripalTestCase {
     ob_end_clean();
 
     $this->assertTrue($bool, 'Publishing a fake organism record failed');
-}
+
+    //ensure that our entity was created
+    $query = db_select('chado.organism', 'O')
+      ->fields('O', ['organism_id']);
+    $query->join('public.chado_bio_data_' . $bundle, 'CBD', 'O.organism_id = CBD.record_id');
+    $query->condition('O.genus', $genus_string);
+    $organism_id = $query->execute()->fetchField();
+    $this->assertNotNull($organism_id, 'Organism with record ID not found in chado_bio_data table.');
+  }
+
+  /**
+   * Test chado_publish_records returns false given bad bundle.
+   *
+   * @group api
+   */
+  public function test_tripal_chado_publish_records_false_with_bad_bundle() {
+    putenv("TRIPAL_SUPPRESS_ERRORS=TRUE");//this will fail, so we suppress the tripal error reporter
+    $bool = tripal_chado_publish_records(['bundle_name' => 'never_in_a_million_years']);
+    $this->assertFalse($bool);
+    putenv("APP_ENV");//unset
+  }
+
+  /**
+   * calls tripal_get_chado_tokens.
+   *
+   * @group api
+   */
+  public function test_tripal_get_chado_tokens(){
+    $tokens = tripal_get_chado_tokens('organism');
+    $this->assertNotEmpty($tokens);
+    $this->assertArrayHasKey('organism.organism_id', $tokens);
+  }
+
+
 
 }

+ 2 - 0
tripal/api/tripal.notice.api.inc

@@ -63,6 +63,8 @@ define('TRIPAL_DEBUG',7);
  */
 function tripal_report_error($type, $severity, $message, $variables = array(), $options = array()) {
 
+  if(getenv('TRIPAL_SUPPRESS_ERRORS') === 'TRUE') return;
+
   // Get human-readable severity string
   $severity_string = '';
   switch ($severity) {