mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#17860: WidgetsService.GetZones can return duplicate zones
--HG-- branch : 1.x
This commit is contained in:
@@ -31,6 +31,7 @@ namespace Orchard.Tests.Modules.Widgets.Services {
|
||||
|
||||
private const string ThemeZoneName1 = "sidebar";
|
||||
private const string ThemeZoneName2 = "alternative";
|
||||
private const string DuplicateZoneNames = "sidebar,alternative, sidebar , alternative ";
|
||||
|
||||
private const string LayerName1 = "Test layer 1";
|
||||
private const string LayerDescription1 = "Test layer 1";
|
||||
@@ -78,10 +79,12 @@ namespace Orchard.Tests.Modules.Widgets.Services {
|
||||
public override void Register(ContainerBuilder builder) {
|
||||
var mockFeatureManager = new Mock<IFeatureManager>();
|
||||
|
||||
var theme1 = new FeatureDescriptor {Extension = new ExtensionDescriptor {Zones = ThemeZoneName1}};
|
||||
var theme2 = new FeatureDescriptor {Extension = new ExtensionDescriptor {Zones = ThemeZoneName2}};
|
||||
var theme1 = new FeatureDescriptor {Extension = new ExtensionDescriptor { Zones = ThemeZoneName1, ExtensionType = "Theme" }};
|
||||
var theme2 = new FeatureDescriptor { Extension = new ExtensionDescriptor { Zones = ThemeZoneName2, ExtensionType = "Theme" } };
|
||||
var theme3 = new FeatureDescriptor { Extension = new ExtensionDescriptor { Zones = DuplicateZoneNames, ExtensionType = "Theme" } };
|
||||
var module1 = new FeatureDescriptor { Extension = new ExtensionDescriptor { Zones = "DontSeeMeBecauseIAmNotATheme", ExtensionType = "Module" } };
|
||||
mockFeatureManager.Setup(x => x.GetEnabledFeatures())
|
||||
.Returns(new[] { theme1, theme2 });
|
||||
.Returns(new[] { theme1, theme2, theme3, module1 });
|
||||
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
@@ -200,10 +203,10 @@ namespace Orchard.Tests.Modules.Widgets.Services {
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Needs fixing")]
|
||||
//[Ignore("Needs fixing")]
|
||||
public void GetZonesTest() {
|
||||
IEnumerable<string> zones = _widgetService.GetZones();
|
||||
Assert.That(zones.Count(), Is.EqualTo(2), "One zone on the mock list");
|
||||
Assert.That(zones.Count(), Is.EqualTo(2), "Two zones on the mock list");
|
||||
Assert.That(zones.FirstOrDefault(zone => zone == ThemeZoneName1), Is.Not.Null);
|
||||
Assert.That(zones.FirstOrDefault(zone => zone == ThemeZoneName2), Is.Not.Null);
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ namespace Orchard.Widgets.Services {
|
||||
return _featureManager.GetEnabledFeatures()
|
||||
.Select(x => x.Extension)
|
||||
.Where(x => DefaultExtensionTypes.IsTheme(x.ExtensionType) && x.Zones != null)
|
||||
.SelectMany(x => x.Zones.Split(','))
|
||||
.Distinct()
|
||||
.SelectMany(x => x.Zones.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
.Select(x => x.Trim())
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
@@ -80,9 +80,9 @@ namespace Orchard.Widgets.Services {
|
||||
|
||||
// get the zones for this theme
|
||||
if (theme.Zones != null)
|
||||
zones = theme.Zones.Split(',')
|
||||
.Distinct()
|
||||
zones = theme.Zones.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(x => x.Trim())
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
// if this theme has no zones defined then walk the BaseTheme chain until we hit a theme which defines zones
|
||||
@@ -90,9 +90,9 @@ namespace Orchard.Widgets.Services {
|
||||
string baseTheme = theme.BaseTheme;
|
||||
theme = _extensionManager.GetExtension(baseTheme);
|
||||
if (theme != null && theme.Zones != null)
|
||||
zones = theme.Zones.Split(',')
|
||||
.Distinct()
|
||||
zones = theme.Zones.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(x => x.Trim())
|
||||
.Distinct()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user