1
1
<?php
2
+
2
3
/**
3
4
* Copyright © Magento, Inc. All rights reserved.
4
5
* See COPYING.txt for license details.
5
6
*/
7
+ declare (strict_types=1 );
8
+
9
+ namespace Magento \Catalog \Model ;
10
+
11
+ use Magento \Catalog \Api \Data \ProductInterface ;
12
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
13
+ use Magento \Framework \TranslateInterface ;
14
+ use Magento \Framework \View \Design \ThemeInterface ;
15
+ use Magento \Framework \View \DesignInterface ;
16
+ use Magento \TestFramework \Helper \Bootstrap ;
17
+ use Magento \Theme \Model \Theme ;
18
+ use PHPUnit \Framework \TestCase ;
6
19
7
20
/**
8
21
* Test class for \Magento\Catalog\Model\Design.
9
22
*/
10
- namespace Magento \Catalog \Model ;
11
-
12
- class DesignTest extends \PHPUnit \Framework \TestCase
23
+ class DesignTest extends TestCase
13
24
{
14
25
/**
15
- * @var \Magento\Catalog\Model\ Design
26
+ * @var Design
16
27
*/
17
- protected $ _model ;
28
+ private $ model ;
18
29
30
+ /**
31
+ * @var ProductRepositoryInterface
32
+ */
33
+ private $ productRepository ;
34
+
35
+ /**
36
+ * @inheriDoc
37
+ */
19
38
protected function setUp (): void
20
39
{
21
- $ this ->_model = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
22
- \Magento \Catalog \Model \Design::class
23
- );
40
+ $ this ->model = Bootstrap::getObjectManager ()->create (Design::class);
41
+ $ this ->productRepository = Bootstrap::getObjectManager ()->get (ProductRepositoryInterface::class);
24
42
}
25
43
26
44
/**
27
45
* @dataProvider getThemeModel
46
+ * @param Theme $theme
47
+ * @return void
28
48
*/
29
- public function testApplyCustomDesign ($ theme )
49
+ public function testApplyCustomDesign (Theme $ theme ): void
30
50
{
31
- $ this ->_model ->applyCustomDesign ($ theme );
32
- $ design = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
33
- \Magento \Framework \View \DesignInterface::class
34
- );
35
- $ translate = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
36
- \Magento \Framework \TranslateInterface::class
37
- );
51
+ $ this ->model ->applyCustomDesign ($ theme );
52
+ $ design = Bootstrap::getObjectManager ()->get (DesignInterface::class);
53
+ $ translate = Bootstrap::getObjectManager ()->get (TranslateInterface::class);
38
54
$ this ->assertEquals ('package ' , $ design ->getDesignTheme ()->getPackageCode ());
39
55
$ this ->assertEquals ('theme ' , $ design ->getDesignTheme ()->getThemeCode ());
40
56
$ this ->assertEquals ('themepackage/theme ' , $ translate ->getTheme ());
41
57
}
42
58
43
59
/**
44
- * @return \Magento\Theme\Model\Theme
60
+ * Verify design product settings will be generated correctly for PDP.
61
+ *
62
+ * @magentoDataFixture Magento/Catalog/_files/simple_product_with_custom_design.php
63
+ * @param array $designSettings
64
+ * @param array $expectedSetting
65
+ * @dataProvider getDesignSettingsForProductWithScheduleDesignTest
66
+ * @return void
67
+ */
68
+ public function testGetDesignSettingsForProductWithScheduleDesign (
69
+ array $ designSettings ,
70
+ array $ expectedSetting
71
+ ): void {
72
+ $ product = $ this ->productRepository ->get ('simple_with_custom_design ' , false , null , true );
73
+ $ this ->applyScheduleDesignUpdate ($ product , $ designSettings );
74
+ $ settings = $ this ->model ->getDesignSettings ($ product );
75
+ self ::assertEquals ($ expectedSetting ['page_layout ' ], $ settings ->getData ('page_layout ' ));
76
+ self ::assertEquals ($ expectedSetting ['custom_design ' ], $ settings ->getData ('custom_design ' ));
77
+ }
78
+
79
+ /**
80
+ * @return array[]
45
81
*/
46
- public function getThemeModel ()
82
+ public function getDesignSettingsForProductWithScheduleDesignTest (): array
47
83
{
48
- $ theme = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
49
- \Magento \Framework \View \Design \ThemeInterface::class
50
- );
84
+ $ datetime = new \DateTime ();
85
+ $ datetime ->modify ('-10 day ' );
86
+ $ fromApplied = $ datetime ->format ('Y-m-d ' );
87
+ $ datetime ->modify ('+20 day ' );
88
+ $ fromNotApplied = $ datetime ->format ('Y-m-d ' );
89
+ $ datetime ->modify ('+30 day ' );
90
+ $ to = $ datetime ->format ('Y-m-d ' );
91
+
92
+ return [
93
+ 'schedule_design_applied ' => [
94
+ 'design_settings ' => [
95
+ 'custom_layout ' => '2columns-left ' ,
96
+ 'custom_design ' => '2 ' ,
97
+ 'custom_design_from ' => $ fromApplied ,
98
+ 'custom_design_to ' => $ to ,
99
+ ],
100
+ 'expected_settings ' => [
101
+ 'page_layout ' => '2columns-left ' ,
102
+ 'custom_design ' => '2 ' ,
103
+ ]
104
+ ],
105
+ 'schedule_design_not_applied ' => [
106
+ 'design_settings ' => [
107
+ 'custom_layout ' => '2columns-left ' ,
108
+ 'custom_design ' => '2 ' ,
109
+ 'custom_design_from ' => $ fromNotApplied ,
110
+ 'custom_design_to ' => $ to ,
111
+ ],
112
+ 'expected_settings ' => [
113
+ 'page_layout ' => '3columns ' ,
114
+ 'custom_design ' => null ,
115
+ ]
116
+ ],
117
+ ];
118
+ }
119
+
120
+ /**
121
+ * @return array
122
+ */
123
+ public function getThemeModel (): array
124
+ {
125
+ $ theme = Bootstrap::getObjectManager ()->create (ThemeInterface::class);
51
126
$ theme ->setData ($ this ->_getThemeData ());
127
+
52
128
return [[$ theme ]];
53
129
}
54
130
@@ -65,7 +141,22 @@ protected function _getThemeData()
65
141
'parent_theme ' => null ,
66
142
'is_featured ' => true ,
67
143
'preview_image ' => '' ,
68
- 'theme_directory ' => __DIR__ . '_files/design/frontend/default/default '
144
+ 'theme_directory ' => __DIR__ . '_files/design/frontend/default/default ' ,
69
145
];
70
146
}
147
+
148
+ /**
149
+ * Apply provided setting to product scheduled design update.
150
+ *
151
+ * @param ProductInterface $product
152
+ * @param array $designSettings
153
+ * @return void
154
+ */
155
+ private function applyScheduleDesignUpdate (ProductInterface $ product , array $ designSettings ): void
156
+ {
157
+ $ product ->setCustomLayout ($ designSettings ['custom_layout ' ]);
158
+ $ product ->setCustomDesign ($ designSettings ['custom_design ' ]);
159
+ $ product ->setCustomDesignFrom ($ designSettings ['custom_design_from ' ]);
160
+ $ product ->setCustomDesignTo ($ designSettings ['custom_design_to ' ]);
161
+ }
71
162
}
0 commit comments