Browse Source

minor changes and a base test for collections

Bradford Condon 7 years ago
parent
commit
0274de25b1

+ 38 - 0
tests/TripalEntityCollection.test

@@ -0,0 +1,38 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+class TripalEntityCollectionTest extends TestCase {
+
+  protected $collection = NULL;
+
+
+  public function setUp() {
+    $details = ['uid' => 1, 'collection_name' => "test_collection_name"];
+    $collection = new TripalEntityCollection();
+    $collection->create($details);
+    $this->collection = $collection;
+  }
+
+  public function testCreateCollectionAndBaseGetters() {
+
+    $collection = $this->collection;
+
+    $name = $collection->getName();
+    $collection_id = $collection->getCollectionID();
+    $this->assertEquals($name, "test_collection_name");
+    $this->assertNotNull($collection_id);
+    $this->assertInternalType("int", (int) $collection_id);
+  }
+
+  public function testAddBundle() {
+//create two entities, AND their fields.  annoying.
+
+    $details = ['bundle_name' => 'organism'];
+
+  }
+
+  public function tearDown() {
+    $this->collection->delete();
+  }
+}

+ 2 - 1
tripal/api/tripal.collections.api.inc

@@ -41,6 +41,7 @@
  * @ingroup tripal_data_collections_api
  */
 function tripal_create_collection($details) {
+
   global $user;
 
   try {
@@ -48,7 +49,7 @@ function tripal_create_collection($details) {
     $collection->create($details);
     $collection_id = $collection->getCollectionID();
 
-    drupal_set_message(t("Collection '%name' created with %num_recs record(s). Check the !view for generate file links.",
+    drupal_set_message(t("Collection '%name' created with %num_recs record(s). Check the !view to generate file links.",
       array(
         '%name' => $details['collection_name'],
         '%num_recs' => count($details['ids']),

+ 5 - 2
tripal/includes/TripalEntityCollection.inc

@@ -165,7 +165,7 @@ class TripalEntityCollection {
     }
 
 
-    // Before inserting the new collection make sure we don't violote the unique
+    // Before inserting the new collection make sure we don't violate the unique
     // constraint that a user can only have one collection of the give name.
     $has_match = db_select('tripal_collection', 'tc')
       ->fields('tc', array('collection_id'))
@@ -207,7 +207,9 @@ class TripalEntityCollection {
    *
    * @throws Exception
    */
-  public function addBundle($details, $collection_id) {
+  public function addBundle($details) {
+    $collection_id = $this->collection_id;
+
     if (!$details['bundle_name']) {
       throw new Exception("Must provide a 'bundle_name' to TripalEntityCollection::addFields().");
     }
@@ -219,6 +221,7 @@ class TripalEntityCollection {
     }
 
     try {
+
       $collection_bundle_id = db_insert('tripal_collection_bundle')
         ->fields(array(
           'bundle_name' => $details['bundle_name'],