|
9 | 9 |
|
10 | 10 | use Codeception\Stub\Expected; |
11 | 11 | use Craft; |
| 12 | +use craft\elements\Category; |
12 | 13 | use craft\helpers\StringHelper; |
| 14 | +use craft\models\ProjectConfigData; |
13 | 15 | use craft\models\ReadOnlyProjectConfigData; |
14 | 16 | use craft\mutex\Mutex; |
15 | 17 | use craft\mutex\NullMutex; |
@@ -216,6 +218,69 @@ public function testEventsFiredAndDeltaStored(): void |
216 | 218 | $pc->saveModifiedConfigData(); |
217 | 219 | } |
218 | 220 |
|
| 221 | + public function testApplyingConfigChangesDoesNotExposePartialElementSourcesToSectionHandlers(): void |
| 222 | + { |
| 223 | + $projectConfig = new ProjectConfig(); |
| 224 | + $internalConfig = new ReadOnlyProjectConfigData([], $projectConfig); |
| 225 | + $currentWorkingConfig = new ProjectConfigData([], $projectConfig); |
| 226 | + |
| 227 | + $internalConfigProperty = new \ReflectionProperty(ProjectConfig::class, '_internalConfig'); |
| 228 | + $internalConfigProperty->setValue($projectConfig, $internalConfig); |
| 229 | + |
| 230 | + $currentWorkingConfigProperty = new \ReflectionProperty(ProjectConfig::class, '_currentWorkingConfig'); |
| 231 | + $currentWorkingConfigProperty->setValue($projectConfig, $currentWorkingConfig); |
| 232 | + |
| 233 | + $incomingConfig = [ |
| 234 | + 'elementSources' => [ |
| 235 | + 'craft\\elements\\Category' => [[ |
| 236 | + 'defaultSort' => ['structure', 'asc'], |
| 237 | + 'tableAttributes' => ['link'], |
| 238 | + 'type' => 'native', |
| 239 | + 'key' => 'group:bedad454-861f-4d7f-b0f6-40ce023cffc5', |
| 240 | + 'disabled' => false, |
| 241 | + ]], |
| 242 | + ], |
| 243 | + 'sections' => [ |
| 244 | + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' => [ |
| 245 | + 'siteSettings' => [ |
| 246 | + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb' => [ |
| 247 | + 'hasUrls' => true, |
| 248 | + 'uriFormat' => 'test/{slug}', |
| 249 | + 'template' => 'test/_entry', |
| 250 | + 'enabledByDefault' => true, |
| 251 | + ], |
| 252 | + ], |
| 253 | + 'entryTypes' => ['cccccccc-cccc-cccc-cccc-cccccccccccc'], |
| 254 | + ], |
| 255 | + ], |
| 256 | + ]; |
| 257 | + |
| 258 | + $externalConfig = new ReadOnlyProjectConfigData($incomingConfig, $projectConfig); |
| 259 | + $externalConfigProperty = new \ReflectionProperty(ProjectConfig::class, '_externalConfig'); |
| 260 | + $externalConfigProperty->setValue($projectConfig, $externalConfig); |
| 261 | + |
| 262 | + $originalProjectConfig = Craft::$app->getProjectConfig(); |
| 263 | + $originalElementSources = Craft::$app->getElementSources(); |
| 264 | + $handlerWasCalled = false; |
| 265 | + |
| 266 | + Craft::$app->set('projectConfig', $projectConfig); |
| 267 | + Craft::$app->set('elementSources', new \craft\services\ElementSources()); |
| 268 | + |
| 269 | + $projectConfig->onAdd(ProjectConfig::PATH_SECTIONS . '.{uid}', function() use (&$handlerWasCalled) { |
| 270 | + $handlerWasCalled = true; |
| 271 | + Craft::$app->getElementSources()->getSources(Category::class); |
| 272 | + }); |
| 273 | + |
| 274 | + try { |
| 275 | + $projectConfig->applyConfigChanges($incomingConfig); |
| 276 | + } finally { |
| 277 | + Craft::$app->set('projectConfig', $originalProjectConfig); |
| 278 | + Craft::$app->set('elementSources', $originalElementSources); |
| 279 | + } |
| 280 | + |
| 281 | + self::assertTrue($handlerWasCalled); |
| 282 | + } |
| 283 | + |
219 | 284 | public function getConfigProvider(): array |
220 | 285 | { |
221 | 286 | return [ |
|
0 commit comments