|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Store\Test\Unit\Model\Config\Processor; |
| 9 | + |
| 10 | +use Magento\Framework\App\DeploymentConfig; |
| 11 | +use Magento\Framework\App\ResourceConnection; |
| 12 | +use Magento\Store\App\Config\Type\Scopes; |
| 13 | +use Magento\Store\Model\Config\Processor\Fallback; |
| 14 | +use Magento\Store\Model\ResourceModel\Store; |
| 15 | +use Magento\Store\Model\ResourceModel\Website; |
| 16 | +use PHPUnit\Framework\MockObject\MockObject; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | + |
| 19 | +class FallbackTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var Scopes|Scopes&MockObject|MockObject |
| 23 | + */ |
| 24 | + private Scopes $scopes; |
| 25 | + /** |
| 26 | + * @var ResourceConnection|ResourceConnection&MockObject|MockObject |
| 27 | + */ |
| 28 | + private ResourceConnection $resourceConnection; |
| 29 | + /** |
| 30 | + * @var Store|Store&MockObject|MockObject |
| 31 | + */ |
| 32 | + private Store $storeResource; |
| 33 | + /** |
| 34 | + * @var Website|Website&MockObject|MockObject |
| 35 | + */ |
| 36 | + private Website $websiteResource; |
| 37 | + /** |
| 38 | + * @var DeploymentConfig|DeploymentConfig&MockObject|MockObject |
| 39 | + */ |
| 40 | + private DeploymentConfig $deploymentConfig; |
| 41 | + /** |
| 42 | + * @var Fallback |
| 43 | + */ |
| 44 | + private Fallback $fallback; |
| 45 | + |
| 46 | + /** |
| 47 | + * @return void |
| 48 | + */ |
| 49 | + protected function setUp(): void |
| 50 | + { |
| 51 | + parent::setUp(); |
| 52 | + |
| 53 | + $this->scopes = $this->createMock(Scopes::class); |
| 54 | + $this->resourceConnection = $this->createMock(ResourceConnection::class); |
| 55 | + $this->storeResource = $this->createMock(Store::class); |
| 56 | + $this->websiteResource = $this->createMock(Website::class); |
| 57 | + $this->deploymentConfig = $this->createMock(DeploymentConfig::class); |
| 58 | + $this->fallback = new Fallback( |
| 59 | + $this->scopes, |
| 60 | + $this->resourceConnection, |
| 61 | + $this->storeResource, |
| 62 | + $this->websiteResource, |
| 63 | + $this->deploymentConfig |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @return void |
| 69 | + */ |
| 70 | + public function testProcessWithStoreCodeCapitalLetters() |
| 71 | + { |
| 72 | + $storesData = $this->getStoresData(); |
| 73 | + $websiteData = $this->getWebsitesData(); |
| 74 | + $this->deploymentConfig->expects($this->once())->method('isDbAvailable')->willReturn(true); |
| 75 | + $this->storeResource->expects($this->once())->method('readAllStores')->willReturn($storesData); |
| 76 | + $this->websiteResource->expects($this->once())->method('readAllWebsites')->willReturn($websiteData); |
| 77 | + |
| 78 | + $result = $this->fallback->process( |
| 79 | + [ |
| 80 | + 'stores' => [ |
| 81 | + 'two' => [ |
| 82 | + 'checkout' => [ |
| 83 | + 'options' => ['guest_checkout' => 0] |
| 84 | + ] |
| 85 | + ] |
| 86 | + ], |
| 87 | + 'websites' => [ |
| 88 | + ['admin' => ['web' => ['routers' => ['frontend' => ['disabled' => true]]]]] |
| 89 | + ] |
| 90 | + ] |
| 91 | + ); |
| 92 | + $this->assertTrue(in_array('two', array_keys($result['stores']))); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Sample stores data |
| 97 | + * |
| 98 | + * @return array[] |
| 99 | + */ |
| 100 | + private function getStoresData(): array |
| 101 | + { |
| 102 | + return [ |
| 103 | + [ |
| 104 | + 'store_id' => 0, |
| 105 | + 'code' => 'admin', |
| 106 | + 'website_id' => 0, |
| 107 | + 'group_id' => 0, |
| 108 | + 'name' => 'Admin', |
| 109 | + 'sort_order' => 0, |
| 110 | + 'is_active' => 1 |
| 111 | + ], |
| 112 | + [ |
| 113 | + 'store_id' => 1, |
| 114 | + 'code' => 'default', |
| 115 | + 'website_id' => 1, |
| 116 | + 'group_id' => 1, |
| 117 | + 'name' => 'Default Store View', |
| 118 | + 'sort_order' => 0, |
| 119 | + 'is_active' => 1 |
| 120 | + ], |
| 121 | + [ |
| 122 | + 'store_id' => 2, |
| 123 | + 'code' => 'TWO', |
| 124 | + 'website_id' => 1, |
| 125 | + 'group_id' => 1, |
| 126 | + 'name' => 'TWO', |
| 127 | + 'sort_order' => 0, |
| 128 | + 'is_active' => 1 |
| 129 | + ] |
| 130 | + ]; |
| 131 | + } |
| 132 | + |
| 133 | + private function getWebsitesData(): array |
| 134 | + { |
| 135 | + return [ |
| 136 | + [ |
| 137 | + 'website_id' => 0, |
| 138 | + 'code' => 'admin', |
| 139 | + 'name' => 'Admin', |
| 140 | + 'sort_order' => 0, |
| 141 | + 'default_group_id' => 0, |
| 142 | + 'is_default' => 0 |
| 143 | + ], |
| 144 | + [ |
| 145 | + 'website_id' => 1, |
| 146 | + 'code' => 'base', |
| 147 | + 'name' => 'Main Website', |
| 148 | + 'sort_order' => 0, |
| 149 | + 'default_group_id' => 1, |
| 150 | + 'is_default' => 1 |
| 151 | + ] |
| 152 | + ]; |
| 153 | + } |
| 154 | +} |
0 commit comments