TripalWebServicesContentTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Tests\tripal_ws\http;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class TripalWebServicesContentTest extends TripalTestCase {
  6. // Uncomment to auto start and rollback db transactions per test method.
  7. use DBTransaction;
  8. /** @test */
  9. public function testGettingMainContentList() {
  10. $response = $this->get('web-services/content/v0.1');
  11. // Make sure it returned valid json
  12. $response->assertSuccessful();
  13. $response->assertJsonStructure([
  14. '@context',
  15. '@id',
  16. '@type',
  17. 'label',
  18. 'totalItems',
  19. 'member' => [
  20. [
  21. '@id',
  22. '@type',
  23. 'label',
  24. 'description',
  25. ],
  26. ],
  27. ]);
  28. }
  29. /** @test
  30. * @group ws
  31. */
  32. public function testGettingListOfEntitiesInABundle() {
  33. // Get bundle label
  34. $label = db_query('SELECT label FROM tripal_bundle LIMIT 1')->fetchField();
  35. // Call /web-services/content/v0.1/[label]
  36. $response = $this->get("web-services/content/v0.1/$label");
  37. // Verify the returned JSON matches the structure
  38. $response->assertSuccessful();
  39. $response->assertJsonStructure([
  40. '@context',
  41. '@id',
  42. '@type',
  43. 'label',
  44. 'totalItems',
  45. 'member',
  46. ]);
  47. // Verify the collection is of the correct type
  48. $json = $response->json();
  49. $this->assertEquals($json['label'], "$label Collection");
  50. }
  51. }