TripalWebServicesContentTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. public function testGettingListOfEntitiesInABundle() {
  31. // Get bundle label
  32. $label = db_query('SELECT label FROM tripal_bundle LIMIT 1')->fetchField();
  33. // Call /web-services/content/v0.1/[label]
  34. $response = $this->get("web-services/content/v0.1/$label");
  35. // Verify the returned JSON matches the structure
  36. $response->assertSuccessful();
  37. $response->assertJsonStructure([
  38. '@context',
  39. '@id',
  40. '@type',
  41. 'label',
  42. 'totalItems',
  43. 'member',
  44. ]);
  45. // Verify the collection is of the correct type
  46. $json = $response->json();
  47. $this->assertEquals($json['label'], "$label Collection");
  48. }
  49. }