+
+ = \wp_kses_post($message) ?>
+
+
+ get_template_directory(), '/\\');
+ $lookupFile = \sprintf(self::FILE_PATH_TEMPLATE, $themeRoot);
+
+ if (!\is_readable($lookupFile)) {
+ return [];
+ }
+
+ $configuration = (array)(include $lookupFile);
+
+ return \array_filter(
+ (array)($configuration[self::VERSIONS_KEY] ?? null),
+ static fn (mixed $v) => \is_string($v),
+ );
+ }
+}
diff --git a/src/Service/VersionActivator.php b/src/Service/VersionActivator.php
new file mode 100644
index 0000000..85c6f3b
--- /dev/null
+++ b/src/Service/VersionActivator.php
@@ -0,0 +1,41 @@
+supportedVersions = $supportedVersions;
+ $this->loader = $loader;
+ }
+
+ public function forTheme(\WP_Theme $theme): bool
+ {
+ $supportedVersions = $this->supportedVersions->forTheme($theme);
+ if (!$supportedVersions) {
+ return false;
+ }
+
+ return $this->loader->load(...$supportedVersions);
+ }
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..1aa1018
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,9 @@
+container = new App\Container();
+ }
+
+ /**
+ * @test
+ */
+ public function when_gutenberg_plugin_is_active_show_admin_notices(): void
+ {
+ $serviceIntegration = Provider\ServiceIntegration::new();
+ $this->withGutenbergPluginActive();
+ Actions\expectAdded('admin_notices');
+ $serviceIntegration->boot($this->container);
+ }
+
+ /**
+ * @test
+ */
+ public function when_gutenberg_plugin_is_active_service_do_not_bootstrap(): void
+ {
+ $serviceIntegration = Provider\ServiceIntegration::new();
+ $this->withGutenbergPluginActive();
+ $this->assertEquals(false, $serviceIntegration->boot($this->container));
+ }
+
+ /**
+ * @test
+ */
+ public function custom_gutenberg_version_is_activated(): void
+ {
+ $serviceIntegration = Provider\ServiceIntegration::new();
+ $this->withActiveGutenberg();
+ Actions\expectAdded('admin_notices')->never();
+ $serviceIntegration->boot($this->container);
+ }
+
+ /**
+ * @test
+ */
+ public function add_backoffice_and_frontoffice_body_classes(): void
+ {
+ $serviceIntegration = Provider\ServiceIntegration::new();
+ $this->withActiveGutenberg();
+ Filters\expectAdded('body_class')->once();
+ Filters\expectAdded('admin_body_class')->once();
+ $serviceIntegration->boot($this->container);
+ }
+}
diff --git a/tests/integration/Service/VersionActivatorTest.php b/tests/integration/Service/VersionActivatorTest.php
new file mode 100644
index 0000000..fabe989
--- /dev/null
+++ b/tests/integration/Service/VersionActivatorTest.php
@@ -0,0 +1,78 @@
+theme
+ ->shouldReceive('get_template_directory')
+ ->andReturn($this->themesPath('theme-name'));
+
+ $versionsLoader->shouldReceive('isLoaded')->andReturn(false);
+ $versionsLoader->shouldReceive('loadMatching')->with('13.9.0')->andReturn(true);
+
+ $versionActivator = Service\VersionActivator::new($supportedVersions, $loader);
+
+ $this->assertEquals(true, $versionActivator->forTheme($this->theme));
+ }
+
+ /**
+ * @test
+ */
+ public function does_not_activate_gutenberg_because_no_compatible_versions_found(): void
+ {
+ $versionsLoader = \Mockery::mock('alias:' . GutenbergVersions\Loader::class);
+
+ $supportedVersions = Service\SupportedVersions::new();
+ $loader = Service\Loader::new();
+
+ $this->theme
+ ->shouldReceive('get_template_directory')
+ ->andReturn($this->themesPath('theme-name'));
+
+ $versionsLoader->shouldReceive('isLoaded')->andReturn(false);
+ $versionsLoader->shouldReceive('loadMatching')->andReturn(false);
+
+ $versionActivator = Service\VersionActivator::new($supportedVersions, $loader);
+
+ $this->assertEquals(false, $versionActivator->forTheme($this->theme));
+ }
+
+ /**
+ * @test
+ */
+ public function does_not_activate_gutenberg_because_already_loaded(): void
+ {
+ $versionsLoader = \Mockery::mock('alias:' . GutenbergVersions\Loader::class);
+
+ $supportedVersions = Service\SupportedVersions::new();
+ $loader = Service\Loader::new();
+
+ $this->theme
+ ->shouldReceive('get_template_directory')
+ ->andReturn($this->themesPath('theme-name'));
+
+ $versionsLoader->shouldReceive('isLoaded')->andReturn(true);
+ $versionsLoader->shouldReceive('loadMatching')->never();
+
+ $versionActivator = Service\VersionActivator::new($supportedVersions, $loader);
+
+ $this->assertEquals(true, $versionActivator->forTheme($this->theme));
+ }
+}
diff --git a/tests/src/UnitTestCase.php b/tests/src/UnitTestCase.php
new file mode 100644
index 0000000..e82a7f2
--- /dev/null
+++ b/tests/src/UnitTestCase.php
@@ -0,0 +1,113 @@
+ [
+ 'theme-name' => [
+ 'config' => [
+ 'gutenberg.php' => <<