diff --git a/test/OrchardCore.Tests.Modules/BaseThemeSample/DependentTypes.cs b/test/OrchardCore.Tests.Modules/BaseThemeSample/DependentTypes.cs new file mode 100644 index 00000000000..59ec8278bdb --- /dev/null +++ b/test/OrchardCore.Tests.Modules/BaseThemeSample/DependentTypes.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OrchardCore.Modules; + +namespace BaseThemeSample; + +public class BaseThemeFeatureIndependentStartup : StartupBase +{ +} + +[Feature("BaseThemeSample")] +public class BaseThemeSampleStartup : StartupBase +{ +} diff --git a/test/OrchardCore.Tests.Modules/ModuleSample/DependentTypes.cs b/test/OrchardCore.Tests.Modules/ModuleSample/DependentTypes.cs new file mode 100644 index 00000000000..1baf0e9f14c --- /dev/null +++ b/test/OrchardCore.Tests.Modules/ModuleSample/DependentTypes.cs @@ -0,0 +1,17 @@ +using OrchardCore.Environment.Extensions; +using OrchardCore.Modules; + +namespace ModuleSample; + +public class FeatureIndependentStartup : StartupBase { } + +[Feature("Sample1")] +public class Sample1Startup : StartupBase +{ +} + +[Feature("Sample2")] +[FeatureTypeDiscovery(SkipExtension = true)] +public class SkippedDependentType +{ +} diff --git a/test/OrchardCore.Tests/Extensions/ExtensionManagerTests.cs b/test/OrchardCore.Tests/Extensions/ExtensionManagerTests.cs index 1ae8e2bfd45..edcaa3ee1fc 100644 --- a/test/OrchardCore.Tests/Extensions/ExtensionManagerTests.cs +++ b/test/OrchardCore.Tests/Extensions/ExtensionManagerTests.cs @@ -1,3 +1,5 @@ +using BaseThemeSample; +using ModuleSample; using OrchardCore.DisplayManagement.Events; using OrchardCore.DisplayManagement.Extensions; using OrchardCore.Environment.Extensions; @@ -24,6 +26,8 @@ private static readonly IApplicationContext _applicationContext private readonly ExtensionManager _moduleScopedExtensionManager; private readonly ExtensionManager _themeScopedExtensionManager; private readonly ExtensionManager _moduleThemeScopedExtensionManager; + + private readonly TypeFeatureProvider _moduleScopedTypeFeatureProvider = new TypeFeatureProvider(); public ExtensionManagerTests() { @@ -31,7 +35,7 @@ public ExtensionManagerTests() _applicationContext, new[] { new ExtensionDependencyStrategy() }, new[] { new ExtensionPriorityStrategy() }, - new TypeFeatureProvider(), + _moduleScopedTypeFeatureProvider, _moduleFeatureProvider, new NullLogger() ); @@ -167,7 +171,7 @@ public void GetFeaturesWithAIdShouldNotReturnFeaturesTheHaveADependencyOutsideOf /* Theme Base Theme Dependencies */ [Fact] - public void GetFeaturesShouldReturnCorrectThemeHeirarchy() + public void GetFeaturesShouldReturnCorrectThemeHierarchy() { var features = _themeScopedExtensionManager.GetFeatures(["DerivedThemeSample"]); @@ -222,5 +226,53 @@ public void ShouldReturnNotFoundExtensionInfoWhenNotFound() Assert.False(extension.Exists); } + + /* The extension manager must populate the ITypeFeatureProvider correctly */ + + [Fact] + public void TypeFeatureProviderIsPopulatedWithComponentTypes() + { + var feature = _moduleScopedExtensionManager.GetFeatures(["Sample1"]).First(); + var types = _moduleScopedTypeFeatureProvider.GetTypesForFeature(feature); + + Assert.Equal(2, types.Count()); + Assert.Contains(typeof(Sample1Startup), types); + Assert.Contains(typeof(FeatureIndependentStartup), types); + } + + [Fact] + public void TypeFeatureProviderTypeMustBeMappedToAllFeatures() + { + // Types in modules that have no feature that matches the extension ID must be mapped to all features. + var features = _moduleScopedExtensionManager.GetFeatures(["Sample1", "Sample2", "Sample3", "Sample4"]); + + foreach (var feature in features) + { + var types = _moduleScopedTypeFeatureProvider.GetTypesForFeature(feature); + + Assert.Contains(typeof(FeatureIndependentStartup), types); + } + } + + [Fact] + public void TypeFeatureProviderTypeMustBeMappedToExtensionFeature() + { + // Types in modules that have a feature that matches the extension ID must be mapped to that feature. + var feature = _moduleScopedExtensionManager.GetFeatures(["BaseThemeSample"]).First(); + var types = _moduleScopedTypeFeatureProvider.GetTypesForFeature(feature); + + Assert.Equal(2, types.Count()); + Assert.Contains(typeof(BaseThemeSampleStartup), types); + Assert.Contains(typeof(BaseThemeFeatureIndependentStartup), types); + } + + [Fact] + public void TypeFeatureProviderTypeMustBeSkipped() + { + var feature = _moduleScopedExtensionManager.GetFeatures(["Sample2"]).First(); + var types = _moduleScopedTypeFeatureProvider.GetTypesForFeature(feature); + + Assert.DoesNotContain(typeof(SkippedDependentType), types); + } } }