Skip to content

Commit d827ecf

Browse files
committed
Apply suggestions from code review on tests
1 parent d29c13a commit d827ecf

1 file changed

Lines changed: 71 additions & 27 deletions

File tree

tests/integration/Core/Repository/ContentServiceTest.php

Lines changed: 71 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6241,46 +6241,66 @@ function (Location $parentLocation) {
62416241
}
62426242

62436243
/**
6244+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
62446245
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
62456246
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException
62466247
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
62476248
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
62486249
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException
62496250
*/
6250-
public function testHideContentDraft(): void
6251+
public function testPublishHiddenDraft(): void
62516252
{
6252-
$publishedContent = $this->createContentForHideRevealDraftTests(false);
6253-
$publishedContentMainLocationId = $publishedContent->getContentInfo()->getMainLocationId();
6253+
$draft = $this->createFolderDraft();
6254+
$draftContentInfo = $draft->getContentInfo();
6255+
$this->contentService->hideContent($draftContentInfo);
6256+
6257+
$publishedContent = $this->contentService->publishVersion($draft->getVersionInfo());
6258+
$contentInfo = $publishedContent->getContentInfo();
6259+
6260+
self::assertTrue($contentInfo->isHidden(), 'Content is not hidden');
6261+
6262+
$mainLocationId = $contentInfo->getMainLocationId();
6263+
62546264
self::assertNotNull(
6255-
$publishedContentMainLocationId,
6265+
$mainLocationId,
62566266
'Expected mainLocationId to be set for this test case.'
62576267
);
6258-
$location = $this->locationService->loadLocation($publishedContentMainLocationId);
62596268

6260-
$content = $this->contentService->loadContent($publishedContent->getContentInfo()->getId());
6261-
self::assertTrue($content->getContentInfo()->isHidden(), 'Content is not hidden');
6269+
$location = $this->locationService->loadLocation($mainLocationId);
62626270
self::assertTrue($location->isHidden(), 'Location is visible');
62636271
}
62646272

62656273
/**
6266-
* @covers \Ibexa\Contracts\Core\Repository\ContentService::revealContent
6267-
6268-
*
6274+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
6275+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
6276+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException
62696277
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
62706278
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
6279+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException
62716280
*/
6272-
public function testHideAndRevealContentDraft(): void
6281+
public function testPublishRevealedDraft(): void
62736282
{
6274-
$publishedContent = $this->createContentForHideRevealDraftTests(true);
6275-
$publishedContentMainLocationId = $publishedContent->getContentInfo()->getMainLocationId();
6283+
$draft = $this->createFolderDraft();
6284+
$draftContentInfo = $draft->getContentInfo();
6285+
6286+
$this->contentService->hideContent($draftContentInfo);
6287+
$this->contentService->revealContent($draftContentInfo);
6288+
6289+
$publishedContent = $this->contentService->publishVersion(
6290+
$draft->getVersionInfo()
6291+
);
6292+
6293+
$contentInfo = $publishedContent->getContentInfo();
6294+
$mainLocationId = $contentInfo->getMainLocationId();
6295+
6296+
self::assertFalse($contentInfo->isHidden(), 'Content is hidden');
62766297
self::assertNotNull(
6277-
$publishedContentMainLocationId,
6298+
$mainLocationId,
62786299
'Expected mainLocationId to be set for this test case.'
62796300
);
6280-
$location = $this->locationService->loadLocation($publishedContentMainLocationId);
62816301

6282-
$content = $this->contentService->loadContent($publishedContent->getContentInfo()->getId());
6283-
self::assertFalse($content->getContentInfo()->isHidden(), 'Content is hidden');
6302+
$location = $this->locationService->loadLocation($mainLocationId);
6303+
62846304
self::assertFalse($location->isHidden(), 'Location is hidden');
62856305
}
62866306

@@ -6292,7 +6312,39 @@ public function testHideAndRevealContentDraft(): void
62926312
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
62936313
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException
62946314
*/
6295-
private function createContentForHideRevealDraftTests(bool $reveal): Content
6315+
public function testHideAndRevealNeverPublishedDraft(): void
6316+
{
6317+
$draft = $this->createFolderDraft();
6318+
$draftContentInfo = $draft->getContentInfo();
6319+
6320+
$this->contentService->hideContent($draftContentInfo);
6321+
6322+
self::assertTrue(
6323+
$this->contentService
6324+
->loadContent($draftContentInfo->getId())
6325+
->getContentInfo()
6326+
->isHidden()
6327+
);
6328+
6329+
$this->contentService->revealContent($draftContentInfo);
6330+
6331+
self::assertFalse(
6332+
$this->contentService
6333+
->loadContent($draftContentInfo->getId())
6334+
->getContentInfo()
6335+
->isHidden()
6336+
);
6337+
}
6338+
6339+
/**
6340+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
6341+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
6342+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException
6343+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
6344+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
6345+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException
6346+
*/
6347+
private function createFolderDraft(): Content
62966348
{
62976349
$contentTypeService = $this->getRepository()->getContentTypeService();
62986350
$locationCreateStructs = $this->locationService->newLocationCreateStruct(2);
@@ -6301,18 +6353,10 @@ private function createContentForHideRevealDraftTests(bool $reveal): Content
63016353
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US);
63026354
$contentCreate->setField('name', 'Folder to hide');
63036355

6304-
$draft = $this->contentService->createContent(
6356+
return $this->contentService->createContent(
63056357
$contentCreate,
63066358
[$locationCreateStructs]
63076359
);
6308-
6309-
$draftContentInfo = $draft->getContentInfo();
6310-
$this->contentService->hideContent($draftContentInfo);
6311-
if ($reveal) {
6312-
$this->contentService->revealContent($draftContentInfo);
6313-
}
6314-
6315-
return $this->contentService->publishVersion($draft->getVersionInfo());
63166360
}
63176361

63186362
/**

0 commit comments

Comments
 (0)