Skip to content

Commit

Permalink
Merge eb77153 into bd6674a
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Sep 28, 2021
2 parents bd6674a + eb77153 commit 8d79321
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 33 deletions.
52 changes: 52 additions & 0 deletions Content/Infrastructure/Doctrine/RouteRemover.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Doctrine;

use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Events;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\RouteBundle\Entity\RouteRepositoryInterface;

class RouteRemover implements EventSubscriber
{
/**
* @var RouteRepositoryInterface
*/
private $routeRepository;

public function __construct(RouteRepositoryInterface $routeRepository)
{
$this->routeRepository = $routeRepository;
}

public function getSubscribedEvents()
{
return [Events::preRemove];
}

public function preRemove(LifecycleEventArgs $event): void
{
$object = $event->getObject();
if (!$object instanceof ContentRichEntityInterface) {
return; // @codeCoverageIgnore
}

$entityClass = ClassUtils::getRealClass(\get_class($object));
foreach ($this->routeRepository->findAllByEntity($entityClass, $object->getId()) as $route) {
$event->getEntityManager()->remove($route);
}
}
}
5 changes: 5 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<tag name="doctrine.event_subscriber" priority="100"/>
</service>

<service id="sulu_content.route_remover" class="Sulu\Bundle\ContentBundle\Content\Infrastructure\Doctrine\RouteRemover">
<argument type="service" id="sulu.repository.route"/>
<tag name="doctrine.event_subscriber"/>
</service>

<service id="sulu_content.content_view_builder_factory" class="Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Admin\ContentViewBuilderFactory">
<argument type="service" id="sulu_admin.view_builder_factory"/>
<argument type="service" id="sulu_preview.preview_object_provider_registry"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"plugins": [
["@babel/plugin-proposal-decorators", {"legacy": true}],
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-transform-flow-strip-types",
["@babel/plugin-proposal-class-properties", {"loose": true}]
]
}
73 changes: 40 additions & 33 deletions Tests/Application/assets/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,66 @@
"license": "MIT",
"repository": "https://github.com/sulu/skeleton.git",
"scripts": {
"preinstall": "node ../../../../vendor/sulu/sulu/preinstall.js",
"preinstall": "node ../../../../vendor/sulu/sulu/preinstall.js ../../../../vendor node_modules/@sulu/vendor",
"postinstall": "node ../../../../vendor/sulu/sulu/postinstall.js ../../../../vendor node_modules/@sulu/vendor",
"build": "webpack --mode production",
"watch": "webpack --mode development -w"
"watch": "webpack --mode development --watch"
},
"dependencies": {
"mobx": "^4.0.0",
"mobx-react": "^5.0.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"sulu-admin-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/AdminBundle/Resources/js",
"sulu-audience-targeting-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/AudienceTargetingBundle/Resources/js",
"sulu-category-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/CategoryBundle/Resources/js",
"sulu-contact-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/ContactBundle/Resources/js",
"sulu-custom-url-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/CustomUrlBundle/Resources/js",
"sulu-location-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/LocationBundle/Resources/js",
"sulu-media-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/MediaBundle/Resources/js",
"sulu-page-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/PageBundle/Resources/js",
"sulu-preview-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/PreviewBundle/Resources/js",
"sulu-route-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/RouteBundle/Resources/js",
"sulu-search-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/SearchBundle/Resources/js",
"sulu-security-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/SecurityBundle/Resources/js",
"sulu-snippet-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/SnippetBundle/Resources/js",
"sulu-website-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/WebsiteBundle/Resources/js"
"react": "^17.0.0",
"react-dom": "^17.0.0",
"sulu-admin-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/AdminBundle/Resources/js",
"sulu-audience-targeting-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/AudienceTargetingBundle/Resources/js",
"sulu-category-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/CategoryBundle/Resources/js",
"sulu-contact-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/ContactBundle/Resources/js",
"sulu-custom-url-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/CustomUrlBundle/Resources/js",
"sulu-location-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/LocationBundle/Resources/js",
"sulu-media-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/MediaBundle/Resources/js",
"sulu-page-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/PageBundle/Resources/js",
"sulu-preview-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/PreviewBundle/Resources/js",
"sulu-route-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/RouteBundle/Resources/js",
"sulu-search-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/SearchBundle/Resources/js",
"sulu-security-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/SecurityBundle/Resources/js",
"sulu-snippet-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/SnippetBundle/Resources/js",
"sulu-trash-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/TrashBundle/Resources/js",
"sulu-website-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/WebsiteBundle/Resources/js"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.2",
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"@ckeditor/ckeditor5-dev-utils": "^12.0.1",
"@ckeditor/ckeditor5-theme-lark": "^14.0.0",
"autoprefixer": "^9.6.1",
"@ckeditor/ckeditor5-dev-utils": "^24.4.2",
"@ckeditor/ckeditor5-theme-lark": "^27.1.0",
"autoprefixer": "^9.8.6",
"babel-loader": "^8.0.6",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^3.2.0",
"file-loader": "^4.2.0",
"core-js": "^3.18.0",
"css-loader": "^5.2.4",
"file-loader": "^6.0.0",
"glob": "^7.1.2",
"mini-css-extract-plugin": "^0.8.0",
"mini-css-extract-plugin": "^1.5.0",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"postcss-calc": "^7.0.1",
"postcss-hexrgba": "^1.0.0",
"postcss": "7.0.35",
"postcss-calc": "^7.0.5",
"postcss-hexrgba": "^2.0.0",
"postcss-import": "^12.0.1",
"postcss-loader": "^3.0.0",
"postcss-nested": "^4.1.2",
"postcss-nested": "^4.2.3",
"postcss-simple-vars": "^5.0.2",
"raw-loader": "^3.1.0",
"raw-loader": "^4.0.0",
"regenerator-runtime": "^0.13.3",
"webpack": "^4.20.2",
"webpack": "^4.27.0",
"webpack-clean-obsolete-chunks": "^0.4.0",
"webpack-cli": "^3.1.1",
"webpack-manifest-plugin": "^2.0.2"
"webpack-cli": "^4.7.0",
"webpack-manifest-plugin": "^3.1.1"
},
"engines": {
"node": ">=12",
"npm": ">=6 <7"
}
}
17 changes: 17 additions & 0 deletions Tests/Application/assets/admin/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable flowtype/require-valid-file-annotation */
/* eslint-disable import/no-nodejs-modules */
const path = require('path');

// eslint-disable-next-line no-undef
module.exports = {
plugins: {
'postcss-import': {
path: path.resolve(process.cwd(), 'node_modules'),
},
'postcss-nested': {},
'postcss-simple-vars': {},
'postcss-calc': {},
'postcss-hexrgba': {},
'autoprefixer': {},
},
};
6 changes: 6 additions & 0 deletions Tests/Functional/Integration/ExampleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public function testPost(): int

$this->assertResponseSnapshot('example_post.json', $response, 201);

$routeRepository = $this->getContainer()->get('sulu.repository.route');
$this->assertCount(0, $routeRepository->findAll());

$id = \json_decode((string) $response->getContent(), true)['id'] ?? null;

return $id;
Expand Down Expand Up @@ -215,6 +218,9 @@ public function testDelete(int $id): void
$this->client->request('DELETE', '/admin/api/examples/' . $id . '?locale=en');
$response = $this->client->getResponse();
$this->assertHttpStatusCode(204, $response);

$routeRepository = $this->getContainer()->get('sulu.repository.route');
$this->assertCount(0, $routeRepository->findAll());
}

protected function getSnapshotFolder(): string
Expand Down
90 changes: 90 additions & 0 deletions Tests/Unit/Content/Infrastructure/Doctrine/RouteRemoverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Infrastructure\Doctrine;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Events;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Doctrine\RouteRemover;
use Sulu\Bundle\RouteBundle\Entity\RouteRepositoryInterface;
use Sulu\Bundle\RouteBundle\Model\RouteInterface;

class RouteRemoverTest extends TestCase
{
/**
* @var RouteRepositoryInterface|ObjectProphecy
*/
private $routeRepository;

protected function setUp(): void
{
parent::setUp();

$this->routeRepository = $this->prophesize(RouteRepositoryInterface::class);
}

protected function getRouteRemover(): RouteRemover
{
return new RouteRemover($this->routeRepository->reveal());
}

public function testGetSubscribedEvents(): void
{
$routeRemover = $this->getRouteRemover();

$this->assertSame([
Events::preRemove,
], $routeRemover->getSubscribedEvents());
}

public function testPreRemove(): void
{
$object = $this->prophesize(ContentRichEntityInterface::class);
$object->getId()->willReturn('123-123-123');

$entityManager = $this->prophesize(EntityManagerInterface::class);

$event = $this->prophesize(LifecycleEventArgs::class);
$event->getObject()->willReturn($object->reveal());
$event->getEntityManager()->willReturn($entityManager->reveal());

$route1 = $this->prophesize(RouteInterface::class);
$route2 = $this->prophesize(RouteInterface::class);
$this->routeRepository->findAllByEntity(Argument::any(), '123-123-123')
->willReturn([$route1->reveal(), $route2->reveal()]);

$entityManager->remove($route1->reveal())->shouldBeCalled();
$entityManager->remove($route2->reveal())->shouldBeCalled();

$routeRemover = $this->getRouteRemover();
$routeRemover->preRemove($event->reveal());
}

public function testPreRemoveNoContentRichEntity(): void
{
$object = $this->prophesize(\stdClass::class);
$event = $this->prophesize(LifecycleEventArgs::class);

$event->getObject()->willReturn($object->reveal());

$this->routeRepository->findAllByEntity(Argument::cetera())->shouldNotBeCalled();

$routeRemover = $this->getRouteRemover();
$routeRemover->preRemove($event->reveal());
}
}

0 comments on commit 8d79321

Please sign in to comment.