File tree Expand file tree Collapse file tree 2 files changed +27
-12
lines changed Expand file tree Collapse file tree 2 files changed +27
-12
lines changed Original file line number Diff line number Diff line change @@ -138,20 +138,26 @@ protected function mediaExpandEntityFields($entity_type, $stub) {
138
138
protected function mediaExpandEntityFieldsFixtures ($ stub ) {
139
139
$ fixture_path = $ this ->getMinkParameter ('files_path ' ) ? rtrim (realpath ($ this ->getMinkParameter ('files_path ' )), DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR : NULL ;
140
140
141
- foreach (get_object_vars ($ stub ) as $ name => $ value ) {
141
+ $ fields = get_object_vars ($ stub );
142
+
143
+ $ field_types = $ this ->getDrupal ()->getDriver ()->getCore ()->getEntityFieldTypes ('media ' , array_keys ($ fields ));
144
+
145
+ foreach ($ fields as $ name => $ value ) {
142
146
if (strpos ($ name , 'field_ ' ) === FALSE ) {
143
147
continue ;
144
148
}
145
149
146
- if (is_array ($ value )) {
147
- if (!empty ($ value [0 ])) {
148
- if (is_file ($ fixture_path . $ value [0 ])) {
149
- $ stub ->{$ name }[0 ] = $ fixture_path . $ value [0 ];
150
+ if (!empty ($ field_types [$ name ]) && $ field_types [$ name ] == 'image ' ) {
151
+ if (is_array ($ value )) {
152
+ if (!empty ($ value [0 ])) {
153
+ if (is_file ($ fixture_path . $ value [0 ])) {
154
+ $ stub ->{$ name }[0 ] = $ fixture_path . $ value [0 ];
155
+ }
150
156
}
151
157
}
152
- }
153
- elseif ( is_file ( $ fixture_path . $ value)) {
154
- $ stub ->{ $ name } = $ fixture_path . $ value ;
158
+ elseif ( is_file ( $ fixture_path . $ value )) {
159
+ $ stub ->{ $ name } = $ fixture_path . $ value;
160
+ }
155
161
}
156
162
}
157
163
}
Original file line number Diff line number Diff line change @@ -3,9 +3,18 @@ Feature: Check that MediaTrait works for D8 or D9
3
3
4
4
@api
5
5
Scenario : Assert "When I attach the file :file to :field_name media field"
6
- Given "image" media:
7
- | name | field_media_image |
8
- | Test media | example_image .png |
6
+ Given managed file:
7
+ | path |
8
+ | example_document .pdf |
9
+
10
+ And "image" media:
11
+ | name | field_media_image |
12
+ | Test media image | example_image .png |
13
+ And "document" media:
14
+ | name | field_media_document |
15
+ | Test media document | example_document .pdf |
16
+
9
17
And I am logged in as a user with the "administrator" role
10
18
When I visit "/admin/content/media"
11
- Then I should see the text "Test media"
19
+ Then I should see the text "Test media image"
20
+ And I should see the text "Test media document"
You can’t perform that action at this time.
0 commit comments