config_preview_deploy-1.0.0-alpha3/tests/src/Kernel/ConfigIgnoreIntegrationTest.php
tests/src/Kernel/ConfigIgnoreIntegrationTest.php
<?php
declare(strict_types=1);
namespace Drupal\Tests\config_preview_deploy\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests integration with config_ignore module.
*
* @group config_preview_deploy
*/
class ConfigIgnoreIntegrationTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'config_preview_deploy',
];
/**
* {@inheritdoc}
*
* We disable strict config schema checking because config_ignore module's
* schema is complex and dynamically loaded, which can cause issues in
* kernel tests where the full module discovery might not be complete.
*/
protected $strictConfigSchema = FALSE;
/**
* The config diff service.
*
* @var \Drupal\config_preview_deploy\ConfigDiff
*/
protected $configDiff;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The event dispatcher.
*
* @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installConfig(['system']);
$this->configDiff = $this->container->get('config_preview_deploy.config_diff');
$this->configFactory = $this->container->get('config.factory');
$this->eventDispatcher = $this->container->get('event_dispatcher');
}
/**
* Tests that generateDiff works without config_ignore module.
*/
public function testGenerateDiffWithoutConfigIgnore(): void {
// Create base checkpoint.
$this->configDiff->createBaseCheckpoint();
// Change site name.
$this->configFactory->getEditable('system.site')
->set('name', 'Changed Site Name')
->save();
// Generate diff with transformations enabled.
$diff = $this->configDiff->generateDiff(TRUE);
// Verify the change is included.
$this->assertStringContainsString('Changed Site Name', $diff);
$this->assertStringContainsString('system.site', $diff);
}
/**
* Tests config_ignore integration when module is enabled.
*/
public function testConfigIgnoreIntegration(): void {
// Check if config_ignore module exists.
$module_list = \Drupal::service('extension.list.module');
if (!$module_list->exists('config_ignore')) {
$this->markTestSkipped('Config ignore module not available in codebase');
}
// Create base checkpoint BEFORE enabling config_ignore.
$this->configDiff->createBaseCheckpoint();
// Enable config_ignore module.
$this->enableModules(['config_ignore']);
// Install the default configuration.
$this->installConfig(['config_ignore']);
// Configure config_ignore to ignore system.site.
$this->configFactory->getEditable('config_ignore.settings')
->set('ignored_config_entities', ['system.site'])
->save();
// Clear caches to ensure event subscribers are registered.
drupal_flush_all_caches();
// Re-fetch services after enabling module.
$this->configDiff = $this->container->get('config_preview_deploy.config_diff');
$this->eventDispatcher = $this->container->get('event_dispatcher');
// Change configs.
$this->configFactory->getEditable('system.site')
->set('name', 'Ignored Site Name')
->save();
$this->configFactory->getEditable('system.performance')
->set('cache.page.max_age', 3600)
->save();
// Verify config_ignore is available.
$this->assertTrue(class_exists('\Drupal\config_ignore\EventSubscriber\ConfigIgnoreEventSubscriber'),
'ConfigIgnoreEventSubscriber class should be available');
// Verify the config filter service recognizes config_ignore is available.
$configFilter = $this->container->get('config_preview_deploy.config_filter');
$this->assertTrue($configFilter->isAvailable(), 'Config filter should recognize config_ignore is available');
// Test diff generation first.
$diffWithTransform = $this->configDiff->generateDiff(TRUE);
$diffWithoutTransform = $this->configDiff->generateDiff(FALSE);
// Check that system.site changes are not in the transformed diff.
// We check for the actual file header to ensure it's not showing as a
// changed file.
$this->assertStringNotContainsString(
'--- a/system.site.yml',
$diffWithTransform,
'Transformed diff should not contain system.site changes'
);
$this->assertStringNotContainsString(
'+++ b/system.site.yml',
$diffWithTransform,
'Transformed diff should not contain system.site changes'
);
// But it should contain system.performance changes.
$this->assertStringContainsString(
'system.performance.yml',
$diffWithTransform,
'Transformed diff should contain system.performance changes'
);
$this->assertStringContainsString(
'3600',
$diffWithTransform,
'Transformed diff should contain the new cache value'
);
// The unfiltered diff should contain both.
$this->assertStringContainsString(
'system.site.yml',
$diffWithoutTransform,
'Unfiltered diff should contain system.site'
);
$this->assertStringContainsString(
'Ignored Site Name',
$diffWithoutTransform,
'Unfiltered diff should contain the ignored value'
);
$this->assertStringContainsString(
'system.performance.yml',
$diffWithoutTransform,
'Unfiltered diff should contain system.performance'
);
// Now test the actual filtering behavior.
$changedWithFilter = $this->configDiff->getChangedConfigs(TRUE);
$changedWithoutFilter = $this->configDiff->getChangedConfigs(FALSE);
// Without filter, both configs should be changed.
$this->assertContains(
'system.site',
$changedWithoutFilter,
'Unfiltered should show system.site as changed'
);
$this->assertContains(
'system.performance',
$changedWithoutFilter,
'Unfiltered should show system.performance as changed'
);
// With filter and config_ignore enabled, system.site should NOT be
// changed.
$this->assertNotContains(
'system.site',
$changedWithFilter,
'Filtered should not show ignored system.site as changed'
);
$this->assertContains(
'system.performance',
$changedWithFilter,
'Filtered should show non-ignored system.performance as changed'
);
// CRITICAL: Verify that active storage is NOT modified by filtering.
// The filtering should only affect the generated diff, not the actual
// active storage.
$activeStorageValue = $this->configFactory->get('system.site')->get('name');
$this->assertEquals(
'Ignored Site Name',
$activeStorageValue,
'Active storage should not be modified by config filtering'
);
}
}
