-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSectionTest.php
More file actions
50 lines (40 loc) · 2.01 KB
/
SectionTest.php
File metadata and controls
50 lines (40 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace Netgen\IbexaScheduledVisibility\Tests\Integration;
use Ibexa\Contracts\Core\Repository\Values\Content\Section as SectionValue;
use Netgen\Bundle\IbexaScheduledVisibilityBundle\Core\VisibilityHandler\Section;
use PHPUnit\Framework\Attributes\DataProvider;
final class SectionTest extends BaseTest
{
#[DataProvider('provideCases')]
public function testUpdateVisibility(array $configuration, bool $expectedHidden)
{
$scheduledVisibilityService = $this->getScheduledVisibilityService();
$content = $this->createContent($configuration['publish_from'], $configuration['publish_to']);
$hiddenSection = $this->createSection();
$visibleSectionId = 1;
$handler = $this->getSectionHandler($hiddenSection->id, $visibleSectionId);
if ($scheduledVisibilityService->shouldBeHidden($content) && !$handler->isHidden($content)) {
$handler->hide($content);
}
if ($scheduledVisibilityService->shouldBeVisible($content) && $handler->isHidden($content)) {
$handler->reveal($content);
}
$content = $this->getRepository()->getContentService()->loadContent($content->contentInfo->id);
self::assertEquals($content->contentInfo->sectionId, $expectedHidden ? $hiddenSection->id : $visibleSectionId);
}
private function getSectionHandler(int $hiddenSectionId, int $visibleSectionId): Section
{
$repository = $this->getRepository();
return new Section($repository, $repository->getSectionService(), $hiddenSectionId, $visibleSectionId);
}
private function createSection(): SectionValue
{
$repository = $this->getRepository();
$sectionService = $repository->getSectionService();
$sectionCreate = $sectionService->newSectionCreateStruct();
$sectionCreate->name = 'Test Scheduled Visibility section';
$sectionCreate->identifier = 'scheduled_visibility_section_';
return $sectionService->createSection($sectionCreate);
}
}