From efc843140a52c862fe15b9785591642a4daedd81 Mon Sep 17 00:00:00 2001 From: Douglas Hammond Date: Wed, 3 Oct 2018 18:37:38 +0200 Subject: [PATCH] EZP-29510: allow last version to be removed if draft (#2414) Closes #2414. --- Repository/ContentService.php | 2 +- Repository/Tests/ContentServiceTest.php | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Repository/ContentService.php b/Repository/ContentService.php index 19907870e..3b2fd5724 100644 --- a/Repository/ContentService.php +++ b/Repository/ContentService.php @@ -308,7 +308,7 @@ public function publishVersion(VersionInfo $versionInfo); * Removes the given version. * * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in - * published state or is a last version of the Content + * published state or is a last version of Content in non draft state * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo diff --git a/Repository/Tests/ContentServiceTest.php b/Repository/Tests/ContentServiceTest.php index 1e117aef1..66b490fbe 100644 --- a/Repository/Tests/ContentServiceTest.php +++ b/Repository/Tests/ContentServiceTest.php @@ -3082,12 +3082,12 @@ public function testDeleteVersionThrowsBadStateExceptionOnPublishedVersion() * Test for the deleteVersion() method. * * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() - * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException + * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion */ - public function testDeleteVersionThrowsBadStateExceptionOnLastVersion() + public function testDeleteVersionWorksIfOnlyVersionIsDraft() { $repository = $this->getRepository(); @@ -3096,9 +3096,11 @@ public function testDeleteVersionThrowsBadStateExceptionOnLastVersion() /* BEGIN: Use Case */ $draft = $this->createContentDraftVersion1(); - // This call will fail with a "BadStateException", because the Content - // version is the last version of the Content. $contentService->deleteVersion($draft->getVersionInfo()); + + // This call will fail with a "NotFound", because we allow to delete content if remaining version is draft. + // Can normally only happen if there where always only a draft to begin with, simplifies UI edit API usage. + $contentService->loadContent($draft->id); /* END: Use Case */ }