I'm trying to understand how to create tests for REST Endpoint that a custom module creates.
I managed to create a Unit Test for the Get method of the Rest-resource and now I want to create a Functional test for the REST-endpoint.
The idea of the test is the following. The test should create a user account with required roles and permissions, authenticate it on the site and send a GET request on behalf of it. And after that, the test should check up the content of the response in JSON format and compare it with the expected.
I would be grateful if you could clarify the following questions:
- How to give anonymous users some permissions? I tried to do it via import of the user.role.anonymous.config with needed permissions into my test config table but without any success.
- How to send requests to the REST-endpoint correctly? As far as I'm concerned, the drupalGet method is not the best solution for that. I had an idea to use exec('curl ...') for that, but I haven't found a true entry point to the Drupal test environment, and moreover, I'm not sure that it's the correct way.
- How to perform a sequence of requests in this case? I mean requests for Oauth2/Token authentication and after that, requests to REST-endpoints.
Thanks in advance.