-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathObjectStateTest.php
More file actions
66 lines (55 loc) · 2.83 KB
/
ObjectStateTest.php
File metadata and controls
66 lines (55 loc) · 2.83 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace Netgen\IbexaScheduledVisibility\Tests\Integration;
use Ibexa\Contracts\Core\Repository\Values\ObjectState\ObjectState as ObjectStateValue;
use Netgen\Bundle\IbexaScheduledVisibilityBundle\Core\VisibilityHandler\ObjectState;
use PHPUnit\Framework\Attributes\DataProvider;
final class ObjectStateTest extends BaseTest
{
#[DataProvider('provideCases')]
public function testUpdateVisibility(array $configuration, bool $expectedHidden)
{
$scheduledVisibilityService = $this->getScheduledVisibilityService();
$content = $this->createContent($configuration['publish_from'], $configuration['publish_to']);
$hiddenObjectState = $this->createObjectState();
$visibleObjectStateId = 1;
$objectStateGroupId = 2;
$handler = $this->getObjectStateHandler($objectStateGroupId, $hiddenObjectState->id, $visibleObjectStateId);
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);
$objectStateService = $this->getRepository()->getObjectStateService();
$objectStateGroup = $objectStateService->loadObjectStateGroup(2);
$objectState = $this->getRepository()->sudo(
static fn (): ObjectStateValue => $objectStateService->getContentState($content->contentInfo, $objectStateGroup),
);
self::assertEquals($objectState->id, $expectedHidden ? $hiddenObjectState->id : $visibleObjectStateId);
}
private function getObjectStateHandler(int $objectStateGroupId, int $hiddenObjectStateId, int $visibleObjectStateId): ObjectState
{
$repository = $this->getRepository();
return new ObjectState($repository, $repository->getObjectStateService(), $objectStateGroupId, $hiddenObjectStateId, $visibleObjectStateId);
}
private function createObjectState(): ObjectStateValue
{
$repository = $this->getRepository();
$objectStateService = $repository->getObjectStateService();
$objectStateGroup = $objectStateService->loadObjectStateGroup(2);
$objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct(
'scheduled_visibility_object_state',
);
$objectStateCreateStruct->priority = 23;
$objectStateCreateStruct->defaultLanguageCode = 'eng-GB';
$objectStateCreateStruct->names = [
'eng-GB' => 'Scheduled visibility object state',
];
return $objectStateService->createObjectState(
$objectStateGroup,
$objectStateCreateStruct,
);
}
}