Skip to content

Commit

Permalink
IBX-6815: [REST] Fixed isBookmarked property in load-subtree response (
Browse files Browse the repository at this point in the history
…#1139)

* Fixed isBookmarked property in load-subtree response

* [PHPStan] Aligned baseline after the changes

* [Composer] Installed ibexa/test-rest

* [Composer] Auto-loaded integration tests namespace

* [Composer] Added missing symfony/webpack-encore-bundle requirement

* [Tests] Configured integration tests framework

* [PHPStan] Aligned baseline with the changes

* [Tests] Added integration coverage for REST load-subtree endpoint
  • Loading branch information
alongosz authored Feb 6, 2024
1 parent 7629b7e commit 11849cf
Show file tree
Hide file tree
Showing 15 changed files with 516 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ package-lock.json
.DS_Store
.phpunit.result.cache
composer.lock
/var
15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
"autoload-dev": {
"psr-4": {
"Ibexa\\Tests\\Bundle\\AdminUi\\": "tests/bundle/",
"Ibexa\\Tests\\AdminUi\\": "tests/lib/",
"EzSystems\\EzPlatformAdminUi\\Tests\\": "tests/lib/",
"Ibexa\\Platform\\Tests\\Assets\\": "tests/lib/"
"Ibexa\\Tests\\Integration\\AdminUi\\": "tests/integration/",
"Ibexa\\Tests\\AdminUi\\": "tests/lib/"
}
},
"require": {
Expand All @@ -46,6 +45,7 @@
"symfony/options-resolver": "^5.0",
"symfony/asset": "^5.0",
"symfony/yaml": "^5.0",
"symfony/webpack-encore-bundle": "^v1.17",
"jms/translation-bundle": "^1.5",
"ibexa/core": "~4.5.0@dev",
"ibexa/content-forms": "~4.5.0@dev",
Expand All @@ -71,6 +71,8 @@
"ibexa/doctrine-schema": "~4.5.0@dev",
"ibexa/http-cache": "~4.5.0@dev",
"ibexa/code-style": "^1.0",
"ibexa/test-rest": "^0.1.x-dev",
"ibexa/test-core": "^0.1.x-dev",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-symfony": "^1.3"
Expand All @@ -84,7 +86,12 @@
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
"check-cs": "@fix-cs --dry-run",
"phpstan": "phpstan analyse",
"test": "phpunit -c phpunit.xml"
"test-unit": "phpunit -c phpunit.xml",
"test-integration": "phpunit -c phpunit.integration.xml",
"test": [
"@test-unit",
"@test-integration"
]
},
"extra": {
"branch-alias": {
Expand Down
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3700,16 +3700,6 @@ parameters:
count: 1
path: src/lib/Event/Options.php

-
message: "#^Call to method getEntrypointLookup\\(\\) on an unknown class Symfony\\\\WebpackEncoreBundle\\\\Asset\\\\EntrypointLookupCollectionInterface\\.$#"
count: 1
path: src/lib/EventListener/AdminExceptionListener.php

-
message: "#^Call to method reset\\(\\) on an unknown class Symfony\\\\WebpackEncoreBundle\\\\Asset\\\\TagRenderer\\.$#"
count: 1
path: src/lib/EventListener/AdminExceptionListener.php

-
message: "#^Cannot call method log\\(\\) on Psr\\\\Log\\\\LoggerInterface\\|null\\.$#"
count: 1
Expand All @@ -3730,26 +3720,6 @@ parameters:
count: 1
path: src/lib/EventListener/AdminExceptionListener.php

-
message: "#^Parameter \\$encoreTagRenderer of method Ibexa\\\\AdminUi\\\\EventListener\\\\AdminExceptionListener\\:\\:__construct\\(\\) has invalid type Symfony\\\\WebpackEncoreBundle\\\\Asset\\\\TagRenderer\\.$#"
count: 2
path: src/lib/EventListener/AdminExceptionListener.php

-
message: "#^Parameter \\$entrypointLookupCollection of method Ibexa\\\\AdminUi\\\\EventListener\\\\AdminExceptionListener\\:\\:__construct\\(\\) has invalid type Symfony\\\\WebpackEncoreBundle\\\\Asset\\\\EntrypointLookupCollectionInterface\\.$#"
count: 2
path: src/lib/EventListener/AdminExceptionListener.php

-
message: "#^Property Ibexa\\\\AdminUi\\\\EventListener\\\\AdminExceptionListener\\:\\:\\$encoreTagRenderer has unknown class Symfony\\\\WebpackEncoreBundle\\\\Asset\\\\TagRenderer as its type\\.$#"
count: 1
path: src/lib/EventListener/AdminExceptionListener.php

-
message: "#^Property Ibexa\\\\AdminUi\\\\EventListener\\\\AdminExceptionListener\\:\\:\\$entrypointLookupCollection has unknown class Symfony\\\\WebpackEncoreBundle\\\\Asset\\\\EntrypointLookupCollectionInterface as its type\\.$#"
count: 1
path: src/lib/EventListener/AdminExceptionListener.php

-
message: "#^Property Ibexa\\\\AdminUi\\\\EventListener\\\\AdminExceptionListener\\:\\:\\$siteAccessGroups type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -9920,11 +9890,6 @@ parameters:
count: 1
path: src/lib/UI/Module/ContentTree/NodeFactory.php

-
message: "#^Property Ibexa\\\\AdminUi\\\\UI\\\\Module\\\\ContentTree\\\\NodeFactory\\:\\:\\$bookmarkService is never read, only written\\.$#"
count: 1
path: src/lib/UI/Module/ContentTree/NodeFactory.php

-
message: "#^Generator expects value type Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\FieldType, Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\FieldType given\\.$#"
count: 1
Expand Down
18 changes: 18 additions & 0 deletions phpunit.integration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="tests/integration/bootstrap.php"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnWarning="true"
verbose="true">
<php>
<env name="KERNEL_CLASS" value="Ibexa\Tests\Integration\AdminUi\AdminUiIbexaTestKernel" />
<env name="SEARCH_ENGINE" value="legacy" />
<env name="DATABASE_URL" value="sqlite://i@i/var/test.db" />
</php>
<testsuites>
<testsuite name="integration">
<directory>tests/integration</directory>
</testsuite>
</testsuites>
</phpunit>
7 changes: 6 additions & 1 deletion src/lib/UI/Module/ContentTree/NodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public function createNode(
): Node {
$uninitializedContentInfoList = [];
$containerLocations = [];

$userBookmarks = $this->bookmarkService->loadBookmarks(0, -1);
$bookmarkedLocations = array_flip(array_column($userBookmarks->items, 'id'));

$node = $this->buildNode(
$location,
$uninitializedContentInfoList,
Expand All @@ -103,7 +107,8 @@ public function createNode(
$loadChildren,
$depth,
$sortClause,
$sortOrder
$sortOrder,
$bookmarkedLocations
);
$versionInfoById = $this->contentService->loadVersionInfoListByContentInfo($uninitializedContentInfoList);

Expand Down
106 changes: 106 additions & 0 deletions tests/integration/AdminUiIbexaTestKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?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;

use Hautelook\TemplatedUriBundle\HautelookTemplatedUriBundle;
use Ibexa\Bundle\AdminUi\IbexaAdminUiBundle;
use Ibexa\Bundle\ContentForms\IbexaContentFormsBundle;
use Ibexa\Bundle\DesignEngine\IbexaDesignEngineBundle;
use Ibexa\Bundle\Rest\IbexaRestBundle;
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;
use Swift_Mailer;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Yaml\Yaml;
use Symfony\WebpackEncoreBundle\WebpackEncoreBundle;

/**
* @internal
*/
final class AdminUiIbexaTestKernel extends IbexaTestKernel
{
public function registerBundles(): iterable
{
yield from parent::registerBundles();

yield new HautelookTemplatedUriBundle();
yield new KnpMenuBundle();
yield new WebpackEncoreBundle();

yield new IbexaContentFormsBundle();
yield new IbexaDesignEngineBundle();
yield new IbexaRestBundle();
yield new IbexaSearchBundle();
yield new IbexaTestRestBundle();
yield new IbexaUserBundle();

yield new IbexaAdminUiBundle();
}

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

yield BookmarkService::class;
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);

$loader->load(static function (ContainerBuilder $container): void {
self::configureIbexaBundles($container);
self::configureThirdPartyBundles($container);
});
}

private static function configureIbexaBundles(ContainerBuilder $container): void
{
// REST
$resource = new FileResource(__DIR__ . '/Resources/routing.yaml');
$container->addResource($resource);
$container->loadFromExtension('framework', [
'router' => [
'resource' => $resource->getResource(),
],
]);
self::addSyntheticService($container, JWT::class);

$configFileName = __DIR__ . '/Resources/ibexa_test_config.yaml';
$resource = new FileResource($configFileName);
$container->addResource($resource);

$extensionConfig = Yaml::parseFile($resource->getResource());
foreach ($extensionConfig as $extensionName => $config) {
$container->loadFromExtension($extensionName, $config);
}
}

private static function configureThirdPartyBundles(ContainerBuilder $container): void
{
$container->loadFromExtension('webpack_encore', [
'output_path' => dirname(__DIR__, 2) . '/var/encore/output',
]);

self::addSyntheticService($container, Swift_Mailer::class);

// bazinga's locale_fallback
$container->setParameter('locale_fallback', 'en');

// Symfony
$container->setParameter('form.type_extension.csrf.enabled', false);
}
}
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": []
}
]
}
]
}
}
Loading

0 comments on commit 11849cf

Please sign in to comment.