protected function EntityShareClientFunctionalTestBase::discoverJsonApiEndpoints in Entity Share 8.3
Same name and namespace in other branches
- 8.2 modules/entity_share_client/tests/src/Functional/EntityShareClientFunctionalTestBase.php \Drupal\Tests\entity_share_client\Functional\EntityShareClientFunctionalTestBase::discoverJsonApiEndpoints()
Helper function to populate the request service with responses.
Parameters
string $url: The url to request.
7 calls to EntityShareClientFunctionalTestBase::discoverJsonApiEndpoints()
- ContentEntityReferenceTest::populateRequestService in modules/
entity_share_client/ tests/ src/ Functional/ ContentEntityReferenceTest.php - Helper function to populate the request service with responses.
- EmbeddedEntityTest::populateRequestService in modules/
entity_share_client/ tests/ src/ Functional/ EmbeddedEntityTest.php - Helper function to populate the request service with responses.
- EntityShareAsyncFunctionalTest::populateRequestService in modules/
entity_share_async/ tests/ src/ Functional/ EntityShareAsyncFunctionalTest.php - Helper function to populate the request service with responses.
- EntityShareClientFunctionalTestBase::populateRequestService in modules/
entity_share_client/ tests/ src/ Functional/ EntityShareClientFunctionalTestBase.php - Helper function to populate the request service with responses.
- InfiniteLoopTest::populateRequestService in modules/
entity_share_client/ tests/ src/ Functional/ InfiniteLoopTest.php - Helper function to populate the request service with responses.
File
- modules/
entity_share_client/ tests/ src/ Functional/ EntityShareClientFunctionalTestBase.php, line 561
Class
- EntityShareClientFunctionalTestBase
- Base class for Entity Share Client functional tests.
Namespace
Drupal\Tests\entity_share_client\FunctionalCode
protected function discoverJsonApiEndpoints($url) {
// Prevents infinite loop.
if (in_array($url, $this->visitedUrlsDuringSetup)) {
return;
}
$this->visitedUrlsDuringSetup[] = $url;
$response = $this->remoteManager
->jsonApiRequest($this->remote, 'GET', $url);
$json_response = Json::decode((string) $response
->getBody());
// Loop on the data and relationships to get expected endpoints.
if (is_array($json_response['data'])) {
foreach (EntityShareUtility::prepareData($json_response['data']) as $data) {
if (isset($data['relationships'])) {
foreach ($data['relationships'] as $field_data) {
// Do not check related endpoints if there are no referenced
// entities.
if ($field_data['data'] == NULL || empty($field_data['data'])) {
continue;
}
// Do not check related endpoints for config entities or users.
$prepared_field_data = EntityShareUtility::prepareData($field_data['data']);
$config_or_user = FALSE;
foreach ($prepared_field_data as $field_data_value) {
$parsed_type = explode('--', $field_data_value['type']);
$entity_type_id = $parsed_type[0];
if ($entity_type_id == 'user') {
$config_or_user = TRUE;
break;
}
elseif ($this->entityDefinitions[$entity_type_id]
->getGroup() == 'configuration') {
$config_or_user = TRUE;
break;
}
}
if ($config_or_user) {
continue;
}
if (isset($field_data['links']['related']['href'])) {
$this
->discoverJsonApiEndpoints($field_data['links']['related']['href']);
}
}
}
// File entity.
if ($data['type'] == 'file--file' && isset($data['attributes']['uri']['url'])) {
// Need to handle exception for the test where the physical file has
// been deleted.
try {
$this->remoteManager
->request($this->remote, 'GET', $data['attributes']['uri']['url']);
} catch (ClientException $exception) {
// Do nothing.
}
}
}
}
// Handle pagination.
if (isset($json_response['links']['next']['href'])) {
$this
->discoverJsonApiEndpoints($json_response['links']['next']['href']);
}
}