3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Catalog \Model \Category ;
7
8
9
+ use Magento \Catalog \Model \Category ;
10
+ use Magento \Catalog \Model \Category \Attribute \Backend \LayoutUpdate ;
11
+ use Magento \Catalog \Model \CategoryFactory ;
12
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
13
+ use Magento \Framework \Exception \NoSuchEntityException ;
14
+ use Magento \Framework \Registry ;
15
+ use Magento \Store \Model \ScopeInterface ;
16
+ use Magento \Store \Model \StoreManagerInterface ;
8
17
use Magento \TestFramework \Catalog \Model \CategoryLayoutUpdateManager ;
9
18
use Magento \TestFramework \Helper \Bootstrap ;
10
- use Magento \Framework \Registry ;
11
19
use PHPUnit \Framework \TestCase ;
12
- use Magento \Catalog \Model \Category ;
13
- use Magento \Catalog \Model \CategoryFactory ;
14
- use Magento \Catalog \Model \Category \Attribute \Backend \LayoutUpdate ;
15
20
16
21
/**
17
22
* @magentoDbIsolation enabled
@@ -40,6 +45,16 @@ class DataProviderTest extends TestCase
40
45
*/
41
46
private $ fakeFiles ;
42
47
48
+ /**
49
+ * @var ScopeConfigInterface
50
+ */
51
+ private $ scopeConfig ;
52
+
53
+ /**
54
+ * @var StoreManagerInterface
55
+ */
56
+ private $ storeManager ;
57
+
43
58
/**
44
59
* Create subject instance.
45
60
*
@@ -58,7 +73,7 @@ private function createDataProvider(): DataProvider
58
73
}
59
74
60
75
/**
61
- * { @inheritDoc}
76
+ * @inheritDoc
62
77
*/
63
78
protected function setUp (): void
64
79
{
@@ -68,12 +83,14 @@ protected function setUp(): void
68
83
$ this ->registry = $ objectManager ->get (Registry::class);
69
84
$ this ->categoryFactory = $ objectManager ->get (CategoryFactory::class);
70
85
$ this ->fakeFiles = $ objectManager ->get (CategoryLayoutUpdateManager::class);
86
+ $ this ->scopeConfig = $ objectManager ->get (ScopeConfigInterface::class);
87
+ $ this ->storeManager = $ objectManager ->get (StoreManagerInterface::class);
71
88
}
72
89
73
90
/**
74
91
* @return void
75
92
*/
76
- public function testGetMetaRequiredAttributes ()
93
+ public function testGetMetaRequiredAttributes (): void
77
94
{
78
95
$ requiredAttributes = [
79
96
'general ' => ['name ' ],
@@ -221,4 +238,48 @@ public function testCustomLayoutMeta(): void
221
238
sort ($ list );
222
239
$ this ->assertEquals ($ expectedList , $ list );
223
240
}
241
+
242
+ /**
243
+ * Check if existing category page layout will remain unaffected by category page layout default value setting
244
+ *
245
+ * @return void
246
+ */
247
+ public function testExistingCategoryLayoutUnaffectedByDefaults (): void
248
+ {
249
+ /** @var Category $category */
250
+ $ category = $ this ->categoryFactory ->create ();
251
+ $ category ->load (2 );
252
+
253
+ $ this ->registry ->register ('category ' , $ category );
254
+ $ meta = $ this ->dataProvider ->getMeta ();
255
+ $ categoryPageLayout = $ meta ["design " ]["children " ]["page_layout " ]["arguments " ]["data " ]["config " ]["default " ];
256
+ $ this ->registry ->unregister ('category ' );
257
+
258
+ $ this ->assertNull ($ categoryPageLayout );
259
+ }
260
+
261
+ /**
262
+ * Check if category page layout default value setting will apply to the new category during it's creation
263
+ *
264
+ * @throws NoSuchEntityException
265
+ */
266
+ public function testNewCategoryLayoutMatchesDefault (): void
267
+ {
268
+ $ categoryDefaultPageLayout = $ this ->scopeConfig ->getValue (
269
+ 'web/default_layouts/default_category_layout ' ,
270
+ ScopeInterface::SCOPE_STORE ,
271
+ $ this ->storeManager ->getStore ()->getId ()
272
+ );
273
+
274
+ /** @var Category $category */
275
+ $ category = $ this ->categoryFactory ->create ();
276
+ $ category ->setName ('Net Test Category ' );
277
+
278
+ $ this ->registry ->register ('category ' , $ category );
279
+ $ meta = $ this ->dataProvider ->getMeta ();
280
+ $ categoryPageLayout = $ meta ["design " ]["children " ]["page_layout " ]["arguments " ]["data " ]["config " ]["default " ];
281
+ $ this ->registry ->unregister ('category ' );
282
+
283
+ $ this ->assertEquals ($ categoryDefaultPageLayout , $ categoryPageLayout );
284
+ }
224
285
}
0 commit comments