10
10
11
11
use Ibexa \AdminUi \Util \ContentTypeFieldsExtractorInterface ;
12
12
use Ibexa \Contracts \Core \Persistence \Content \Type \Handler as ContentTypeHandler ;
13
+ use Ibexa \Contracts \Core \Repository \ContentTypeService ;
14
+ use Ibexa \Contracts \Core \Repository \Values \ContentType \FieldDefinition ;
13
15
use Ibexa \Contracts \Core \Test \IbexaKernelTestCase ;
14
16
use LogicException ;
15
17
@@ -19,13 +21,16 @@ final class ContentTypeFieldsExtractorTest extends IbexaKernelTestCase
19
21
20
22
private ContentTypeHandler $ contentTypeHandler ;
21
23
24
+ private ContentTypeService $ contentTypeService ;
25
+
22
26
protected function setUp (): void
23
27
{
24
28
self ::bootKernel ();
25
29
self ::setAdministratorUser ();
26
30
27
31
$ this ->contentTypeFieldsExtractor = self ::getServiceByClassName (ContentTypeFieldsExtractorInterface::class);
28
32
$ this ->contentTypeHandler = self ::getServiceByClassName (ContentTypeHandler::class);
33
+ $ this ->contentTypeService = self ::getServiceByClassName (ContentTypeService::class);
29
34
}
30
35
31
36
public function testExtractWithContentTypeGroupNames (): void
@@ -75,4 +80,62 @@ public function testExtractWithContentTypeAndGroupNamesFailsWithTypesOutsideGrou
75
80
76
81
$ this ->contentTypeFieldsExtractor ->extractFieldsFromExpression ($ expression );
77
82
}
83
+
84
+ /**
85
+ * @dataProvider dataProviderForTestFieldIdWithinExpression
86
+ */
87
+ public function testFieldIdWithinExpression (string $ expression ): void
88
+ {
89
+ $ contentType = $ this ->contentTypeService ->loadContentTypeByIdentifier ('folder ' );
90
+ $ fieldDefinitions = $ contentType ->getFieldDefinitions ();
91
+ $ nameFieldDefinition = $ fieldDefinitions ->filter (
92
+ static fn (FieldDefinition $ fieldDefinition ): bool => $ fieldDefinition ->getIdentifier () === 'name '
93
+ )->first ();
94
+
95
+ $ result = $ this ->contentTypeFieldsExtractor ->isFieldWithinExpression ($ nameFieldDefinition ->getId (), $ expression );
96
+
97
+ self ::assertTrue ($ result );
98
+ }
99
+
100
+ /**
101
+ * @dataProvider dataProviderForTestFieldIdNotWithinExpression
102
+ */
103
+ public function testFieldIdNotWithinExpression (string $ expression ): void
104
+ {
105
+ $ contentType = $ this ->contentTypeService ->loadContentTypeByIdentifier ('folder ' );
106
+ $ fieldDefinitions = $ contentType ->getFieldDefinitions ();
107
+ $ nameFieldDefinition = $ fieldDefinitions ->filter (
108
+ static fn (FieldDefinition $ fieldDefinition ): bool => $ fieldDefinition ->getIdentifier () === 'name '
109
+ )->first ();
110
+
111
+ $ result = $ this ->contentTypeFieldsExtractor ->isFieldWithinExpression ($ nameFieldDefinition ->getId (), $ expression );
112
+
113
+ self ::assertFalse ($ result );
114
+ }
115
+
116
+ /**
117
+ * @return iterable<list<string>>
118
+ */
119
+ public function dataProviderForTestFieldIdWithinExpression (): iterable
120
+ {
121
+ yield '{Media,Content}/*/name ' => ['{Media,Content}/*/name ' ];
122
+
123
+ yield '*/folder/name ' => ['*/folder/name ' ];
124
+
125
+ yield '*/*/name ' => ['*/*/name ' ];
126
+
127
+ yield '*/folder/* ' => ['*/folder/* ' ];
128
+ }
129
+
130
+ /**
131
+ * @return iterable<list<string>>
132
+ */
133
+ public function dataProviderForTestFieldIdNotWithinExpression (): iterable
134
+ {
135
+ yield '{Users}/*/name ' => ['{Users}/*/name ' ];
136
+
137
+ yield '*/article/name ' => ['*/article/name ' ];
138
+
139
+ yield '*/user/* ' => ['*/user/* ' ];
140
+ }
78
141
}
0 commit comments