Jelajahi Sumber

Merge pull request #573 from statonlab/567-add_ws_tests

Add tripal web services http tests
Lacey-Anne Sanderson 6 tahun lalu
induk
melakukan
93f0c3a9b0
5 mengubah file dengan 390 tambahan dan 220 penghapusan
  1. 4 4
      .travis.yml
  2. 324 216
      composer.lock
  3. 2 0
      tests/.travis.env
  4. 1 0
      tests/example.env
  5. 59 0
      tests/tripal_ws/http/TripalWebServicesContentTest.php

+ 4 - 4
.travis.yml

@@ -12,7 +12,7 @@ php:
   - 7.1
 
 env:
-  - BASE_URL="http://localhost:8080"
+  - BASE_URL="http://127.0.0.1:8080"
 
 install:
   - composer global require drush/drush:8
@@ -31,6 +31,8 @@ before_script:
   - drush dl drupal-7 -y
   - mv drupal-7* drupal
   - cd drupal
+  # Run the php server
+  - php -S 127.0.0.1:8080 &
   - drush si -y --db-url='pgsql://postgres:dbpass@localhost:5432/test_db'
                 --account-name='admin'
                 --account-pass='admin_pass'
@@ -45,9 +47,6 @@ before_script:
   - drush en -y field_group, field_group_table, field_formatter_class, field_formatter_settings, ctools, date, devel,
               ds, link, entity, libraries, redirect, token uuid, jquery_update, views, webform
 
-  # Run the drush server
-  - drush runserver localhost:8080 &
-
 script:
   # Link our repo to the modules directory
   - mv ../tripal sites/all/modules/tripal
@@ -73,6 +72,7 @@ script:
 
   # Run PHPUnit tests
   - composer update
+  - cp tests/.travis.env tests/.env
   - ./vendor/bin/phpunit
 
   # Test Tripal v2 to v3 upgrade steps

File diff ditekan karena terlalu besar
+ 324 - 216
composer.lock


+ 2 - 0
tests/.travis.env

@@ -0,0 +1,2 @@
+BASE_URL=http://127.0.0.1:8080
+FAKER_LOCALE=en_US

+ 1 - 0
tests/example.env

@@ -1,2 +1,3 @@
+BASE_URL=http://localhost
 DRUPAL_ROOT=/var/www/html
 FAKER_LOCALE=en_US

+ 59 - 0
tests/tripal_ws/http/TripalWebServicesContentTest.php

@@ -0,0 +1,59 @@
+<?php
+
+namespace Tests\tripal_ws\http;
+
+use StatonLab\TripalTestSuite\DBTransaction;
+use StatonLab\TripalTestSuite\TripalTestCase;
+
+class TripalWebServicesContentTest extends TripalTestCase{
+
+  // Uncomment to auto start and rollback db transactions per test method.
+  use DBTransaction;
+
+  /** @test */
+  public function testGettingMainContentList() {
+    $response = $this->get('web-services/content/v0.1');
+
+    // Make sure it returned valid json
+    $response->assertSuccessful();
+    $response->assertJsonStructure([
+      '@context',
+      '@id',
+      '@type',
+      'label',
+      'totalItems',
+      'member' => [
+        [
+          '@id',
+          '@type',
+          'label',
+          'description',
+        ],
+      ],
+    ]);
+  }
+
+  /** @test */
+  public function testGettingListOfEntitiesInABundle() {
+    // Get bundle label
+    $label = db_query('SELECT label FROM tripal_bundle LIMIT 1')->fetchField();
+
+    // Call /web-services/content/v0.1/[label]
+    $response = $this->get("web-services/content/v0.1/$label");
+
+    // Verify the returned JSON matches the structure
+    $response->assertSuccessful();
+    $response->assertJsonStructure([
+      '@context',
+      '@id',
+      '@type',
+      'label',
+      'totalItems',
+      'member',
+    ]);
+
+    // Verify the collection is of the correct type
+    $json = $response->json();
+    $this->assertEquals($json['label'], "$label Collection");
+  }
+}

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini