Skip to content

Commit

Permalink
[Tests] Added integration coverage for REST load-subtree endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Feb 5, 2024
1 parent ef2c59c commit 11eb2be
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/integration/AdminUiIbexaTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Ibexa\Bundle\Search\IbexaSearchBundle;
use Ibexa\Bundle\Test\Rest\IbexaTestRestBundle;
use Ibexa\Bundle\User\IbexaUserBundle;
use Ibexa\Contracts\Core\Repository\BookmarkService;
use Ibexa\Contracts\Test\Core\IbexaTestKernel;
use Ibexa\Rest\Server\Controller\JWT;
use Knp\Bundle\MenuBundle\KnpMenuBundle;
Expand Down Expand Up @@ -49,6 +50,13 @@ public function registerBundles(): iterable
yield new IbexaAdminUiBundle();
}

protected static function getExposedServicesByClass(): iterable
{
yield from parent::getExposedServicesByClass();

yield BookmarkService::class;
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);
Expand Down
29 changes: 29 additions & 0 deletions tests/integration/REST/BaseAdminUiRestWebTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\AdminUi\REST;

use Ibexa\Contracts\Test\Rest\BaseRestWebTestCase;

/**
* Requires \Ibexa\Tests\Integration\AdminUi\AdminUiIbexaTestKernel kernel.
*
* @see \Ibexa\Tests\Integration\AdminUi\AdminUiIbexaTestKernel
*/
abstract class BaseAdminUiRestWebTestCase extends BaseRestWebTestCase
{
protected function getSchemaFileBasePath(string $resourceType, string $format): string
{
return dirname(__DIR__) . '/Resources/REST/Schemas/' . $resourceType;
}

protected static function getSnapshotDirectory(): ?string
{
return dirname(__DIR__) . '/Resources/REST/Snapshots';
}
}
52 changes: 52 additions & 0 deletions tests/integration/REST/PostPostLoadSubtreeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\AdminUi\REST;

use Ibexa\Contracts\Core\Repository\BookmarkService;
use Ibexa\Contracts\Test\Rest\Input\PayloadLoader;
use Ibexa\Contracts\Test\Rest\Request\Value\EndpointRequestDefinition;

/**
* Coverage for /location/load-subtree REST endpoint.
*/
final class PostPostLoadSubtreeTest extends BaseAdminUiRestWebTestCase
{
private const INPUT_MEDIA_TYPE = 'ContentTreeLoadSubtreeRequest';

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception
*/
protected function setUp(): void
{
parent::setUp();

$ibexaTestCore = $this->getIbexaTestCore();
$ibexaTestCore->setAdministratorUser();
$bookmarkService = $ibexaTestCore->getServiceByClassName(BookmarkService::class);
$locationService = $ibexaTestCore->getLocationService();
$location = $locationService->loadLocation(2);
$bookmarkService->createBookmark($location);
}

protected static function getEndpointsToTest(): iterable
{
$payloadLoader = new PayloadLoader(dirname(__DIR__) . '/Resources/REST/InputPayloads');

yield new EndpointRequestDefinition(
'POST',
'/api/ibexa/v2/location/tree/load-subtree',
'ContentTreeRoot',
'application/vnd.ibexa.api.ContentTreeRoot+json',
['HTTP_X-SiteAccess' => 'admin'],
$payloadLoader->loadPayload(self::INPUT_MEDIA_TYPE, 'json'),
null,
'ContentTreeRoot'
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"LoadSubtreeRequest": {
"_media-type": "application/vnd.ibexa.api.ContentTreeLoadSubtreeRequest",
"nodes": [
{
"_media-type": "application/vnd.ibexa.api.ContentTreeLoadSubtreeRequestNode",
"locationId": 2,
"limit": 30,
"offset": 0,
"children": [
{
"_media-type": "application/vnd.ibexa.api.ContentTreeLoadSubtreeRequestNode",
"locationId": 1,
"limit": 200,
"offset": 0,
"children": []
}
]
}
]
}
}
139 changes: 139 additions & 0 deletions tests/integration/Resources/REST/Schemas/ContentTreeRoot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"ContentTreeRoot": {
"type": "object",
"properties": {
"_media-type": {
"type": "string"
},
"ContentTreeNodeList": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"_media-type": {
"type": "string"
},
"locationId": {
"type": "integer"
},
"contentId": {
"type": "integer"
},
"name": {
"type": "string"
},
"contentTypeIdentifier": {
"type": "string"
},
"isContainer": {
"type": "boolean"
},
"isInvisible": {
"type": "boolean"
},
"displayLimit": {
"type": "integer"
},
"totalChildrenCount": {
"type": "integer"
},
"reverseRelationsCount": {
"type": "integer"
},
"isBookmarked": {
"type": "boolean"
},
"children": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"_media-type": {
"type": "string"
},
"locationId": {
"type": "integer"
},
"contentId": {
"type": "integer"
},
"name": {
"type": "string"
},
"contentTypeIdentifier": {
"type": "string"
},
"isContainer": {
"type": "boolean"
},
"isInvisible": {
"type": "boolean"
},
"displayLimit": {
"type": "integer"
},
"totalChildrenCount": {
"type": "integer"
},
"reverseRelationsCount": {
"type": "integer"
},
"isBookmarked": {
"type": "boolean"
},
"children": {
"type": "array",
"items": {}
}
},
"required": [
"_media-type",
"locationId",
"contentId",
"name",
"contentTypeIdentifier",
"isContainer",
"isInvisible",
"displayLimit",
"totalChildrenCount",
"reverseRelationsCount",
"isBookmarked",
"children"
]
}
]
}
},
"required": [
"_media-type",
"locationId",
"contentId",
"name",
"contentTypeIdentifier",
"isContainer",
"isInvisible",
"displayLimit",
"totalChildrenCount",
"reverseRelationsCount",
"isBookmarked",
"children"
]
}
]
}
},
"required": [
"_media-type",
"ContentTreeNodeList"
]
}
},
"required": [
"ContentTreeRoot"
]
}
36 changes: 36 additions & 0 deletions tests/integration/Resources/REST/Snapshots/ContentTreeRoot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"ContentTreeRoot": {
"_media-type": "application\/vnd.ibexa.api.ContentTreeRoot+json",
"ContentTreeNodeList": [
{
"_media-type": "application\/vnd.ibexa.api.ContentTreeNode+json",
"locationId": 2,
"contentId": 57,
"name": "Home",
"contentTypeIdentifier": "landing_page",
"isContainer": true,
"isInvisible": false,
"displayLimit": 30,
"totalChildrenCount": 1,
"reverseRelationsCount": 0,
"isBookmarked": true,
"children": [
{
"_media-type": "application\/vnd.ibexa.api.ContentTreeNode+json",
"locationId": 60,
"contentId": 58,
"name": "Contact Us",
"contentTypeIdentifier": "feedback_form",
"isContainer": true,
"isInvisible": false,
"displayLimit": 30,
"totalChildrenCount": 0,
"reverseRelationsCount": 0,
"isBookmarked": false,
"children": []
}
]
}
]
}
}
3 changes: 3 additions & 0 deletions tests/integration/Resources/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ ibexa.admin_ui.rest:
ibexa.rest:
resource: '@IbexaRestBundle/Resources/config/routing.yml'
prefix: '%ibexa.rest.path_prefix%'

ibexa.user:
resource: '@IbexaUserBundle/Resources/config/routing.yaml'

0 comments on commit 11eb2be

Please sign in to comment.