1010
1111use Ibexa \AdminUi \Util \ContentTypeFieldsExtractorInterface ;
1212use 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 ;
1315use Ibexa \Contracts \Core \Test \IbexaKernelTestCase ;
1416use LogicException ;
1517
@@ -19,13 +21,16 @@ final class ContentTypeFieldsExtractorTest extends IbexaKernelTestCase
1921
2022 private ContentTypeHandler $ contentTypeHandler ;
2123
24+ private ContentTypeService $ contentTypeService ;
25+
2226 protected function setUp (): void
2327 {
2428 self ::bootKernel ();
2529 self ::setAdministratorUser ();
2630
2731 $ this ->contentTypeFieldsExtractor = self ::getServiceByClassName (ContentTypeFieldsExtractorInterface::class);
2832 $ this ->contentTypeHandler = self ::getServiceByClassName (ContentTypeHandler::class);
33+ $ this ->contentTypeService = self ::getServiceByClassName (ContentTypeService::class);
2934 }
3035
3136 public function testExtractWithContentTypeGroupNames (): void
@@ -75,4 +80,62 @@ public function testExtractWithContentTypeAndGroupNamesFailsWithTypesOutsideGrou
7580
7681 $ this ->contentTypeFieldsExtractor ->extractFieldsFromExpression ($ expression );
7782 }
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+ }
78141}
0 commit comments