Skip to content

Commit

Permalink
Merge branch 'OrchardCMS:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
DotCat1985 authored Jul 4, 2024
2 parents d4ed5c3 + 4aeaaf9 commit bee2158
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
17 changes: 17 additions & 0 deletions test/OrchardCore.Tests.Modules/BaseThemeSample/DependentTypes.cs
Original file line number Diff line number Diff line change
@@ -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
{
}
17 changes: 17 additions & 0 deletions test/OrchardCore.Tests.Modules/ModuleSample/DependentTypes.cs
Original file line number Diff line number Diff line change
@@ -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
{
}
56 changes: 54 additions & 2 deletions test/OrchardCore.Tests/Extensions/ExtensionManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using BaseThemeSample;
using ModuleSample;
using OrchardCore.DisplayManagement.Events;
using OrchardCore.DisplayManagement.Extensions;
using OrchardCore.Environment.Extensions;
Expand All @@ -24,14 +26,16 @@ 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()
{
_moduleScopedExtensionManager = new ExtensionManager(
_applicationContext,
new[] { new ExtensionDependencyStrategy() },
new[] { new ExtensionPriorityStrategy() },
new TypeFeatureProvider(),
_moduleScopedTypeFeatureProvider,
_moduleFeatureProvider,
new NullLogger<ExtensionManager>()
);
Expand Down Expand Up @@ -167,7 +171,7 @@ public void GetFeaturesWithAIdShouldNotReturnFeaturesTheHaveADependencyOutsideOf
/* Theme Base Theme Dependencies */

[Fact]
public void GetFeaturesShouldReturnCorrectThemeHeirarchy()
public void GetFeaturesShouldReturnCorrectThemeHierarchy()
{
var features = _themeScopedExtensionManager.GetFeatures(["DerivedThemeSample"]);

Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit bee2158

Please sign in to comment.