-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseTest.php
More file actions
152 lines (131 loc) · 5.38 KB
/
BaseTest.php
File metadata and controls
152 lines (131 loc) · 5.38 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
declare(strict_types=1);
namespace Netgen\IbexaScheduledVisibility\Tests\Integration;
use DateTime;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use Ibexa\Tests\Integration\Core\Repository\BaseTestCase as APIBaseTest;
use Netgen\Bundle\IbexaScheduledVisibilityBundle\Core\ScheduledVisibilityService;
abstract class BaseTest extends APIBaseTest
{
public static function provideCases(): iterable
{
return [
[
[
'publish_from' => null,
'publish_to' => null,
],
false,
],
[
[
'publish_from' => null,
'publish_to' => new DateTime('tomorrow', new \DateTimeZone('UTC')),
],
false,
],
[
[
'publish_from' => null,
'publish_to' => new DateTime('yesterday', new \DateTimeZone('UTC')),
],
true,
],
[
[
'publish_from' => new DateTime('2 days ago', new \DateTimeZone('UTC')),
'publish_to' => new DateTime('yesterday', new \DateTimeZone('UTC')),
],
true,
],
[
[
'publish_from' => new DateTime('yesterday', new \DateTimeZone('UTC')),
'publish_to' => new DateTime('tomorrow', new \DateTimeZone('UTC')),
],
false,
],
[
[
'publish_from' => new DateTime('tomorrow', new \DateTimeZone('UTC')),
'publish_to' => null,
],
true,
],
[
[
'publish_from' => new DateTime('tomorrow', new \DateTimeZone('UTC')),
'publish_to' => new DateTime('2 day', new \DateTimeZone('UTC')),
],
true,
],
];
}
protected function getScheduledVisibilityService(): ScheduledVisibilityService
{
/** @var \Netgen\Bundle\IbexaScheduledVisibilityBundle\Core\ScheduledVisibilityService $service */
$service = $this->getSetupFactory()->getServiceContainer()->get(ScheduledVisibilityService::class);
return $service;
}
protected function createContentType(): ContentType
{
$repository = $this->getRepository();
$contentTypeService = $repository->getContentTypeService();
$permissionResolver = $repository->getPermissionResolver();
$typeCreate = $contentTypeService->newContentTypeCreateStruct('test-scheduled-visibility');
$typeCreate->mainLanguageCode = 'eng-GB';
$typeCreate->remoteId = '384b94a1bd6bc06826410e284dd9684887bf56fc';
$typeCreate->urlAliasSchema = 'url|scheme';
$typeCreate->nameSchema = 'name|scheme';
$typeCreate->names = [
'eng-GB' => 'Test Scheduled Visibility',
];
$typeCreate->creatorId = $this->generateId('user', $permissionResolver->getCurrentUserReference()->getUserId());
$typeCreate->creationDate = $this->createDateTime();
$publishFromFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('publish_from', 'ibexa_date');
$publishFromFieldCreate->names = [
'eng-GB' => 'Publish from',
];
$publishFromFieldCreate->position = 1;
$typeCreate->addFieldDefinition($publishFromFieldCreate);
$publishToFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('publish_to', 'ibexa_datetime');
$publishToFieldCreate->names = [
'eng-GB' => 'Publish to',
];
$publishToFieldCreate->position = 2;
$typeCreate->addFieldDefinition($publishToFieldCreate);
$groups = [
$contentTypeService->loadContentTypeGroupByIdentifier('Media'),
];
$contentTypeDraft = $contentTypeService->createContentType(
$typeCreate,
$groups,
);
$contentTypeService->publishContentTypeDraft($contentTypeDraft);
$contentType = $contentTypeService->loadContentType($contentTypeDraft->id);
self::assertInstanceOf(
ContentType::class,
$contentType,
);
return $contentType;
}
protected function createContent(?DateTime $publishFrom, ?DateTime $publishTo): Content
{
$contentService = $this->getRepository()->getContentService();
$contentType = $this->createContentType();
$contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-GB');
$contentCreate->setField('publish_from', $publishFrom);
$contentCreate->setField('publish_to', $publishTo);
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
$contentCreate->alwaysAvailable = true;
$locationService = $this->getRepository()->getLocationService();
$content = $contentService->createContent(
$contentCreate,
[$locationService->newLocationCreateStruct(2)],
);
$publishedContent = $contentService->publishVersion($content->getVersionInfo());
self::assertInstanceOf(Content::class, $publishedContent);
return $publishedContent;
}
}