8
8
namespace Magento \TestFramework \Catalog \Model \Product \Option \DataProvider \Type ;
9
9
10
10
use Magento \Catalog \Api \Data \ProductCustomOptionInterface ;
11
- use Magento \TestFramework \ Catalog \Model \Product \Option \ DataProvider \ Type \ AbstractBase ;
11
+ use Magento \Catalog \Model \Product \Option ;
12
12
13
13
/**
14
14
* Data provider for options from file group with type "file".
@@ -20,41 +20,44 @@ class File extends AbstractBase
20
20
*/
21
21
public function getDataForCreateOptions (): array
22
22
{
23
- return array_merge_recursive (
24
- parent ::getDataForCreateOptions (),
25
- [
26
- "type_ {$ this ->getType ()}_option_file_extension " => [
27
- [
28
- 'record_id ' => 0 ,
29
- 'sort_order ' => 1 ,
30
- 'is_require ' => 1 ,
31
- 'sku ' => 'test-option-title-1 ' ,
32
- 'max_characters ' => 30 ,
33
- 'title ' => 'Test option title 1 ' ,
34
- 'type ' => $ this ->getType (),
35
- 'price ' => 10 ,
36
- 'price_type ' => 'fixed ' ,
37
- 'file_extension ' => 'gif ' ,
38
- 'image_size_x ' => 10 ,
39
- 'image_size_y ' => 20 ,
23
+ return $ this ->injectFileExtension (
24
+ array_merge_recursive (
25
+ parent ::getDataForCreateOptions (),
26
+ [
27
+ "type_ {$ this ->getType ()}_option_file_extension " => [
28
+ [
29
+ 'record_id ' => 0 ,
30
+ 'sort_order ' => 1 ,
31
+ 'is_require ' => 1 ,
32
+ 'sku ' => 'test-option-title-1 ' ,
33
+ 'max_characters ' => 30 ,
34
+ 'title ' => 'Test option title 1 ' ,
35
+ 'type ' => $ this ->getType (),
36
+ 'price ' => 10 ,
37
+ 'price_type ' => 'fixed ' ,
38
+ 'file_extension ' => 'gif ' ,
39
+ 'image_size_x ' => 10 ,
40
+ 'image_size_y ' => 20 ,
41
+ ],
40
42
],
41
- ],
42
- " type_ { $ this -> getType ()} _option_maximum_file_size " => [
43
- [
44
- ' record_id ' => 0 ,
45
- ' sort_order ' => 1 ,
46
- ' is_require ' => 1 ,
47
- ' sku ' => 'test- option- title- 1 ' ,
48
- ' title ' => ' Test option title 1 ' ,
49
- ' type ' => $ this -> getType () ,
50
- ' price ' => 10 ,
51
- ' price_type ' => 'fixed ' ,
52
- ' file_extension ' => ' gif ' ,
53
- ' image_size_x ' => 10 ,
54
- ' image_size_y ' => 20 ,
43
+ " type_ { $ this -> getType ()} _option_maximum_file_size " => [
44
+ [
45
+ ' record_id ' => 0 ,
46
+ ' sort_order ' => 1 ,
47
+ ' is_require ' => 1 ,
48
+ ' sku ' => ' test-option-title-1 ' ,
49
+ ' title ' => 'Test option title 1 ' ,
50
+ ' type ' => $ this -> getType () ,
51
+ ' price ' => 10 ,
52
+ ' price_type ' => ' fixed ' ,
53
+ ' file_extension ' => 'gif ' ,
54
+ ' image_size_x ' => 10 ,
55
+ ' image_size_y ' => 20 ,
56
+ ] ,
55
57
],
56
- ],
57
- ]
58
+ ]
59
+ ),
60
+ 'png '
58
61
);
59
62
}
60
63
@@ -63,21 +66,24 @@ public function getDataForCreateOptions(): array
63
66
*/
64
67
public function getDataForUpdateOptions (): array
65
68
{
66
- return array_merge_recursive (
67
- parent ::getDataForUpdateOptions (),
68
- [
69
- "type_ {$ this ->getType ()}_option_file_extension " => [
70
- [
71
- 'file_extension ' => 'jpg ' ,
69
+ return $ this ->injectFileExtension (
70
+ array_merge_recursive (
71
+ parent ::getDataForUpdateOptions (),
72
+ [
73
+ "type_ {$ this ->getType ()}_option_file_extension " => [
74
+ [
75
+ 'file_extension ' => 'jpg ' ,
76
+ ],
72
77
],
73
- ],
74
- " type_ { $ this -> getType ()} _option_maximum_file_size " => [
75
- [
76
- ' image_size_x ' => 300 ,
77
- ' image_size_y ' => 815 ,
78
+ " type_ { $ this -> getType ()} _option_maximum_file_size " => [
79
+ [
80
+ ' image_size_x ' => 300 ,
81
+ ' image_size_y ' => 815 ,
82
+ ] ,
78
83
],
79
- ],
80
- ]
84
+ ]
85
+ ),
86
+ ''
81
87
);
82
88
}
83
89
@@ -88,4 +94,24 @@ protected function getType(): string
88
94
{
89
95
return ProductCustomOptionInterface::OPTION_TYPE_FILE ;
90
96
}
97
+
98
+ /**
99
+ * Add 'file_extension' value to each option.
100
+ *
101
+ * @param array $data
102
+ * @param string $extension
103
+ * @return array
104
+ */
105
+ private function injectFileExtension (array $ data , string $ extension ): array
106
+ {
107
+ foreach ($ data as &$ caseData ) {
108
+ foreach ($ caseData as &$ option ) {
109
+ if (!isset ($ option [Option::KEY_FILE_EXTENSION ])) {
110
+ $ option [Option::KEY_FILE_EXTENSION ] = $ extension ;
111
+ }
112
+ }
113
+ }
114
+
115
+ return $ data ;
116
+ }
91
117
}
0 commit comments