TripalContentTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. /** @test */
  51. public function testGettingAFeatureResource() {
  52. // Create an mRNA feature
  53. $mRNA_term = db_query('SELECT * FROM chado.cvterm WHERE name=:name',
  54. [':name' => 'mRNA'])->fetchObject();
  55. $this->assertNotEmpty($mRNA_term);
  56. $feature = factory('chado.feature')->create([
  57. 'type_id' => $mRNA_term->cvterm_id,
  58. ]);
  59. $this->publish('feature', [$feature->feature_id]);
  60. // Get the entity to retrieve the ID
  61. $entity_id = chado_get_record_entity_by_table('feature', $feature->feature_id);
  62. $this->assertNotEmpty($entity_id);
  63. // Call the web services url
  64. $response = $this->get("/web-services/content/v0.1/mRNA/$entity_id");
  65. $response->assertSuccessful();
  66. $response->assertJsonStructure([
  67. '@context',
  68. '@id',
  69. '@type',
  70. 'label',
  71. 'ItemPage',
  72. 'type',
  73. ]);
  74. // Check that the feature name is what we have expected
  75. $data = $response->json();
  76. $this->assertEquals($feature->name, $data['name']);
  77. }
  78. }