11<?php
2+
23/**
34 * Copyright © Magento, Inc. All rights reserved.
45 * See COPYING.txt for license details.
56 */
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 ;
619
720/**
821 * Test class for \Magento\Catalog\Model\Design.
922 */
10- namespace Magento \Catalog \Model ;
11-
12- class DesignTest extends \PHPUnit \Framework \TestCase
23+ class DesignTest extends TestCase
1324{
1425 /**
15- * @var \Magento\Catalog\Model\ Design
26+ * @var Design
1627 */
17- protected $ _model ;
28+ private $ model ;
1829
30+ /**
31+ * @var ProductRepositoryInterface
32+ */
33+ private $ productRepository ;
34+
35+ /**
36+ * @inheriDoc
37+ */
1938 protected function setUp (): void
2039 {
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);
2442 }
2543
2644 /**
2745 * @dataProvider getThemeModel
46+ * @param Theme $theme
47+ * @return void
2848 */
29- public function testApplyCustomDesign ($ theme )
49+ public function testApplyCustomDesign (Theme $ theme ): void
3050 {
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);
3854 $ this ->assertEquals ('package ' , $ design ->getDesignTheme ()->getPackageCode ());
3955 $ this ->assertEquals ('theme ' , $ design ->getDesignTheme ()->getThemeCode ());
4056 $ this ->assertEquals ('themepackage/theme ' , $ translate ->getTheme ());
4157 }
4258
4359 /**
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[]
4581 */
46- public function getThemeModel ()
82+ public function getDesignSettingsForProductWithScheduleDesignTest (): array
4783 {
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);
51126 $ theme ->setData ($ this ->_getThemeData ());
127+
52128 return [[$ theme ]];
53129 }
54130
@@ -65,7 +141,22 @@ protected function _getThemeData()
65141 'parent_theme ' => null ,
66142 'is_featured ' => true ,
67143 'preview_image ' => '' ,
68- 'theme_directory ' => __DIR__ . '_files/design/frontend/default/default '
144+ 'theme_directory ' => __DIR__ . '_files/design/frontend/default/default ' ,
69145 ];
70146 }
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+ }
71162}
0 commit comments