Unverified Commit 5226fc8a authored by Alex Pott's avatar Alex Pott
Browse files

fix: #3564735 Container / service exceptions while installed from existing config

By: kazuko.murata
By: phenaproxima
(cherry picked from commit 24b60a5c)
parent 66e0d15c
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -927,6 +927,9 @@ protected function processExtension(string $type, string $op, string|array $name
        $this->processedSystemTheme = TRUE;
      }
      \Drupal::service('theme_installer')->$op($names);
      // Installing a theme can also cause a kernel boot, so re-inject services
      // as is done with modules.
      $this->reInjectMe();
    }
    $this->setProcessedExtension($type, $op, $names);
  }
+25 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
use Drupal\Core\Config\ConfigEvents;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\ConfigImporterException;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\KernelTests\KernelTestBase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
@@ -948,6 +949,30 @@ public function testUninstallThemeIncrementsCount(): void {
    $this->assertEquals(0, $this->config($cronName)->get('logging'));
  }

  /**
   * Tests that installing a theme will reload all service dependencies.
   */
  public function testThemeInstallReloadsServices(): void {
    $this->assertFalse(\Drupal::service(ThemeHandlerInterface::class)->themeExists('test_base_theme'));

    $sync = $this->container->get('config.storage.sync');
    // Ensure that the config import will install the theme.
    $extensions = $sync->read('core.extension');
    $extensions['theme']['test_base_theme'] = 0;
    $sync->write('core.extension', $extensions);

    $importer = $this->configImporter();
    $property = new \ReflectionProperty($importer, 'themeHandler');
    $old_theme_handler = $property->getValue($importer);
    $this->assertIsObject($old_theme_handler);

    $importer->import();
    $this->assertTrue(\Drupal::service(ThemeHandlerInterface::class)->themeExists('test_base_theme'));
    $new_theme_handler = $property->getValue($importer);
    $this->assertIsObject($new_theme_handler);
    $this->assertNotSame($old_theme_handler, $new_theme_handler);
  }

  /**
   * Tests config events during config import.
   */