TripalContentTest.php 1.4 KB

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