Skip to content

Commit

Permalink
EZP-29510: allow last version to be removed if draft (#2414)
Browse files Browse the repository at this point in the history
Closes #2414.
  • Loading branch information
wizhippo authored and andrerom committed Oct 3, 2018
1 parent 813ae07 commit efc8431
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Repository/ContentService.php
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions Repository/Tests/ContentServiceTest.php
Expand Up @@ -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();

Expand All @@ -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 */
}

Expand Down

0 comments on commit efc8431

Please sign in to comment.