1 config.test public ConfigurationTest::testConfigHtaccess()

Tests that config directories are protected by .htaccess files.


core/modules/config/tests/config.test, line 167
Tests for Configuration module.


Tests reading and writing file contents.


public function testConfigHtaccess() {
  // This test only run if using file-based config storage.
  $active_storage = config_get_config_storage();
  $active_dir = config_get_config_directory();
  if (!is_a($active_storage, 'ConfigFileStorage')) {
    $this->assert(TRUE, 'Config storage is not file-based, so .htaccess test skipped.');

  // Visit the status report to confirm the file is re-created automatically.
  $admin_user = $this->backdropCreateUser(array(
    'access administration pages',
    'access site reports',

  // Remove .htaccess file so we can test that it gets re-created.
  @backdrop_unlink($active_dir . '/.htaccess');
  $this->assertFalse(is_file($active_dir . '/.htaccess'), "Removed the .htaccess file in the 'active' config directory.");

  $this->assertTrue(is_file($active_dir . '/.htaccess'), "Re-created the .htaccess file in the 'active' config directory.");

  // Verify contents of .htaccess file.
  $file = file_get_contents($active_dir . '/.htaccess');
  $this->assertEqual($file, file_htaccess_lines(), 'The .htaccess file contains the proper content.');