Skip to content

Commit

Permalink
Merge pull request #81 from roberto-butti/fix/avoid_array_cast
Browse files Browse the repository at this point in the history
Fix/avoid array cast
  • Loading branch information
roberto-butti authored Jan 10, 2023
2 parents e8082af + 1f29305 commit d67a198
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Storyblok/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ function getResolvedLinks($data, array $queryString)
/**
* Enrich the Stories with resolved links and stories.
*
* @param array|string $data
* @param array|\stdClass|string $data
*
* @return array|string
*/
Expand All @@ -735,7 +735,7 @@ public function enrichContent($data)
foreach ($data as $fieldName => $fieldValue) {
$enrichedContent[$fieldName] = $this->insertRelations($data['component'], $fieldName, $fieldValue);
$enrichedContent[$fieldName] = $this->insertLinks($enrichedContent[$fieldName]);
$enrichedContent[$fieldName] = $this->enrichContent((array) $enrichedContent[$fieldName]);
$enrichedContent[$fieldName] = $this->enrichContent($enrichedContent[$fieldName]);
}
}
} elseif (\is_array($data)) {
Expand Down
26 changes: 26 additions & 0 deletions tests/Storyblok/Integration/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@
$this->assertCount(1, $responses);
})->group('integration');

test('Integration: check casting after enriching content', function () {
$client = new Client('Iw3XKcJb6MwkdZEwoQ9BCQtt');
$client->editMode();
$options = $client->getApiParameters();
$response = $client->getStoryBySlug('home');
$body = $response->getBody();
expect($body)->toBeArray()
->toHaveKey('story')
->toHaveCount(4)
;
$story = $body['story'];
expect($story)->toBeArray()
->toHaveKey('content')
->toHaveCount(22)
;
$content = $story['content'];
expect($content)->toBeArray()
->toHaveKey('_uid')
->toHaveKey('body')
->toHaveKey('component')
->toHaveCount(4)
;
expect($content['_uid'])->toBeString();
expect($content['component'])->toBeString();
})->group('integration');

test('Integration: get one story with option with cache', function () {
unset($_GET['_storyblok_published']);
$client = new Client('Iw3XKcJb6MwkdZEwoQ9BCQtt');
Expand Down

0 comments on commit d67a198

Please sign in to comment.