33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
67namespace Magento \Catalog \Model \Category ;
78
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 ;
817use Magento \TestFramework \Catalog \Model \CategoryLayoutUpdateManager ;
918use Magento \TestFramework \Helper \Bootstrap ;
10- use Magento \Framework \Registry ;
1119use PHPUnit \Framework \TestCase ;
12- use Magento \Catalog \Model \Category ;
13- use Magento \Catalog \Model \CategoryFactory ;
14- use Magento \Catalog \Model \Category \Attribute \Backend \LayoutUpdate ;
1520
1621/**
1722 * @magentoDbIsolation enabled
@@ -40,6 +45,16 @@ class DataProviderTest extends TestCase
4045 */
4146 private $ fakeFiles ;
4247
48+ /**
49+ * @var ScopeConfigInterface
50+ */
51+ private $ scopeConfig ;
52+
53+ /**
54+ * @var StoreManagerInterface
55+ */
56+ private $ storeManager ;
57+
4358 /**
4459 * Create subject instance.
4560 *
@@ -58,7 +73,7 @@ private function createDataProvider(): DataProvider
5873 }
5974
6075 /**
61- * { @inheritDoc}
76+ * @inheritDoc
6277 */
6378 protected function setUp (): void
6479 {
@@ -68,12 +83,14 @@ protected function setUp(): void
6883 $ this ->registry = $ objectManager ->get (Registry::class);
6984 $ this ->categoryFactory = $ objectManager ->get (CategoryFactory::class);
7085 $ this ->fakeFiles = $ objectManager ->get (CategoryLayoutUpdateManager::class);
86+ $ this ->scopeConfig = $ objectManager ->get (ScopeConfigInterface::class);
87+ $ this ->storeManager = $ objectManager ->get (StoreManagerInterface::class);
7188 }
7289
7390 /**
7491 * @return void
7592 */
76- public function testGetMetaRequiredAttributes ()
93+ public function testGetMetaRequiredAttributes (): void
7794 {
7895 $ requiredAttributes = [
7996 'general ' => ['name ' ],
@@ -221,4 +238,48 @@ public function testCustomLayoutMeta(): void
221238 sort ($ list );
222239 $ this ->assertEquals ($ expectedList , $ list );
223240 }
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+ }
224285}
0 commit comments