From b9257fceebfb31968278432f7ebed6ef19db799e Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 3 Oct 2013 17:50:42 +1000 Subject: [PATCH] New dashboard config classes all tested --- .../Configuration/Dashboard/AccessElement.cs | 11 +++ .../Configuration/Dashboard/ControlElement.cs | 47 ++++++++--- .../Configuration/Dashboard/IControl.cs | 2 + .../InnerTextConfigurationElement.cs | 4 +- .../DashboardSettings/Dashboard.config | 6 +- .../DashboardSettingsTests.cs | 80 +++++++++++++++++++ 6 files changed, 136 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Core/Configuration/Dashboard/AccessElement.cs b/src/Umbraco.Core/Configuration/Dashboard/AccessElement.cs index e6cffac333..bb798467b9 100644 --- a/src/Umbraco.Core/Configuration/Dashboard/AccessElement.cs +++ b/src/Umbraco.Core/Configuration/Dashboard/AccessElement.cs @@ -1,10 +1,21 @@ using System.Collections.Generic; using System.Linq; +using System.Xml.Linq; namespace Umbraco.Core.Configuration.Dashboard { internal class AccessElement : RawXmlConfigurationElement, IAccess { + public AccessElement() + { + + } + + public AccessElement(XElement rawXml) + :base(rawXml) + { + } + public IEnumerable Rules { get diff --git a/src/Umbraco.Core/Configuration/Dashboard/ControlElement.cs b/src/Umbraco.Core/Configuration/Dashboard/ControlElement.cs index 0a3ef8bc78..6f2584128b 100644 --- a/src/Umbraco.Core/Configuration/Dashboard/ControlElement.cs +++ b/src/Umbraco.Core/Configuration/Dashboard/ControlElement.cs @@ -1,33 +1,54 @@ -using System.Configuration; +using System; +using System.Configuration; using System.Linq; using System.Xml.Linq; namespace Umbraco.Core.Configuration.Dashboard { + internal class ControlElement : RawXmlConfigurationElement, IControl { - [ConfigurationProperty("showOnce", DefaultValue = false)] public bool ShowOnce { - get { return (bool)this["showOnce"]; } + get + { + return RawXml.Attribute("showOnce") == null + ? false + : bool.Parse(RawXml.Attribute("showOnce").Value); + } } - [ConfigurationProperty("addPanel", DefaultValue = true)] public bool AddPanel { - get { return (bool)this["addPanel"]; } + get + { + return RawXml.Attribute("addPanel") == null + ? true + : bool.Parse(RawXml.Attribute("addPanel").Value); + } } - [ConfigurationProperty("panelCaption", DefaultValue = "")] public string PanelCaption { - get { return (string)this["panelCaption"]; } + get + { + return RawXml.Attribute("panelCaption") == null + ? "" + : RawXml.Attribute("panelCaption").Value; + } } - [ConfigurationProperty("access")] public AccessElement Access { - get { return (AccessElement)this["access"]; } + get + { + var access = RawXml.Element("access"); + if (access == null) + { + return new AccessElement(); + } + return new AccessElement(access); + } } public string ControlPath @@ -40,8 +61,14 @@ namespace Umbraco.Core.Configuration.Dashboard { throw new ConfigurationErrorsException("The control element must contain a text node indicating the control path"); } - return txt.Value; + return txt.Value.Trim(); } } + + + IAccess IControl.AccessRights + { + get { return Access; } + } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Configuration/Dashboard/IControl.cs b/src/Umbraco.Core/Configuration/Dashboard/IControl.cs index bfaaf9cbc9..f6a7a46843 100644 --- a/src/Umbraco.Core/Configuration/Dashboard/IControl.cs +++ b/src/Umbraco.Core/Configuration/Dashboard/IControl.cs @@ -9,5 +9,7 @@ string PanelCaption { get; } string ControlPath { get; } + + IAccess AccessRights { get; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Configuration/InnerTextConfigurationElement.cs b/src/Umbraco.Core/Configuration/InnerTextConfigurationElement.cs index 5363893971..0bc94bb157 100644 --- a/src/Umbraco.Core/Configuration/InnerTextConfigurationElement.cs +++ b/src/Umbraco.Core/Configuration/InnerTextConfigurationElement.cs @@ -25,8 +25,8 @@ namespace Umbraco.Core.Configuration //now validate and set the raw value if (RawXml.HasElements) throw new InvalidOperationException("An InnerTextConfigurationElement cannot contain any child elements, only attributes and a value"); - RawValue = RawXml.Value; - + RawValue = RawXml.Value.Trim(); + //RawValue = reader.ReadElementContentAsString(); } diff --git a/src/Umbraco.Tests/Configurations/DashboardSettings/Dashboard.config b/src/Umbraco.Tests/Configurations/DashboardSettings/Dashboard.config index 43cac016c2..fc8750f67b 100644 --- a/src/Umbraco.Tests/Configurations/DashboardSettings/Dashboard.config +++ b/src/Umbraco.Tests/Configurations/DashboardSettings/Dashboard.config @@ -6,10 +6,10 @@ settings - + views/dashboard/settings/settingsdashboardintro.html - + views/dashboard/settings/settingsdashboardvideos.html @@ -60,6 +60,8 @@
translator + hello + world content diff --git a/src/Umbraco.Tests/Configurations/DashboardSettings/DashboardSettingsTests.cs b/src/Umbraco.Tests/Configurations/DashboardSettings/DashboardSettingsTests.cs index e4b31dc1b4..3130ec47ca 100644 --- a/src/Umbraco.Tests/Configurations/DashboardSettings/DashboardSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/DashboardSettings/DashboardSettingsTests.cs @@ -30,6 +30,86 @@ namespace Umbraco.Tests.Configurations.DashboardSettings public void Test_Sections() { Assert.AreEqual(5, SettingsSection.Sections.Count()); + + Assert.AreEqual("StartupSettingsDashboardSection", SettingsSection.Sections.ElementAt(0).Alias); + Assert.AreEqual("StartupDeveloperDashboardSection", SettingsSection.Sections.ElementAt(1).Alias); + Assert.AreEqual("StartupMediaDashboardSection", SettingsSection.Sections.ElementAt(2).Alias); + Assert.AreEqual("StartupDashboardSection", SettingsSection.Sections.ElementAt(3).Alias); + Assert.AreEqual("StartupMemberDashboardSection", SettingsSection.Sections.ElementAt(4).Alias); + } + + [Test] + public void Test_Section_Area() + { + Assert.AreEqual("settings", SettingsSection.Sections.ElementAt(0).Area); + Assert.AreEqual("developer", SettingsSection.Sections.ElementAt(1).Area); + Assert.AreEqual("media", SettingsSection.Sections.ElementAt(2).Area); + Assert.AreEqual("content", SettingsSection.Sections.ElementAt(3).Area); + Assert.AreEqual("member", SettingsSection.Sections.ElementAt(4).Area); + } + + [Test] + public void Test_Section_Access() + { + + Assert.AreEqual(3, SettingsSection.Sections.ElementAt(3).AccessRights.Rules.Count()); + + Assert.AreEqual("translator", SettingsSection.Sections.ElementAt(3).AccessRights.Rules.ElementAt(0).Value); + Assert.AreEqual(AccessType.Deny, SettingsSection.Sections.ElementAt(3).AccessRights.Rules.ElementAt(0).Action); + Assert.AreEqual("hello", SettingsSection.Sections.ElementAt(3).AccessRights.Rules.ElementAt(1).Value); + Assert.AreEqual(AccessType.Grant, SettingsSection.Sections.ElementAt(3).AccessRights.Rules.ElementAt(1).Action); + Assert.AreEqual("world", SettingsSection.Sections.ElementAt(3).AccessRights.Rules.ElementAt(2).Value); + Assert.AreEqual(AccessType.GrantBySection, SettingsSection.Sections.ElementAt(3).AccessRights.Rules.ElementAt(2).Action); + } + + [Test] + public void Test_Section_Tabs() + { + Assert.AreEqual(1, SettingsSection.Sections.ElementAt(0).Tabs.Count()); + Assert.AreEqual(2, SettingsSection.Sections.ElementAt(1).Tabs.Count()); + Assert.AreEqual(3, SettingsSection.Sections.ElementAt(3).Tabs.Count()); + + } + + [Test] + public void Test_Tab() + { + Assert.AreEqual("Get Started", SettingsSection.Sections.ElementAt(0).Tabs.ElementAt(0).Caption); + Assert.AreEqual(2, SettingsSection.Sections.ElementAt(0).Tabs.ElementAt(0).Controls.Count()); + } + + [Test] + public void Test_Tab_Access() + { + Assert.AreEqual(1, SettingsSection.Sections.ElementAt(2).Tabs.ElementAt(1).AccessRights.Rules.Count()); + Assert.AreEqual(AccessType.Grant, SettingsSection.Sections.ElementAt(2).Tabs.ElementAt(1).AccessRights.Rules.ElementAt(0).Action); + Assert.AreEqual("admin", SettingsSection.Sections.ElementAt(2).Tabs.ElementAt(1).AccessRights.Rules.ElementAt(0).Value); + } + + [Test] + public void Test_Control() + { + Assert.AreEqual(true, SettingsSection.Sections.ElementAt(0).Tabs.ElementAt(0).Controls.ElementAt(0).ShowOnce); + Assert.AreEqual(true, SettingsSection.Sections.ElementAt(0).Tabs.ElementAt(0).Controls.ElementAt(0).AddPanel); + Assert.AreEqual("hello", SettingsSection.Sections.ElementAt(0).Tabs.ElementAt(0).Controls.ElementAt(0).PanelCaption); + Assert.AreEqual("views/dashboard/settings/settingsdashboardintro.html", + SettingsSection.Sections.ElementAt(0).Tabs.ElementAt(0).Controls.ElementAt(0).ControlPath); + + Assert.AreEqual(false, SettingsSection.Sections.ElementAt(0).Tabs.ElementAt(0).Controls.ElementAt(1).ShowOnce); + Assert.AreEqual(false, SettingsSection.Sections.ElementAt(0).Tabs.ElementAt(0).Controls.ElementAt(1).AddPanel); + Assert.AreEqual("", SettingsSection.Sections.ElementAt(0).Tabs.ElementAt(0).Controls.ElementAt(1).PanelCaption); + Assert.AreEqual("views/dashboard/settings/settingsdashboardvideos.html", + SettingsSection.Sections.ElementAt(0).Tabs.ElementAt(0).Controls.ElementAt(1).ControlPath); + } + + [Test] + public void Test_Control_Access() + { + Assert.AreEqual(2, SettingsSection.Sections.ElementAt(3).Tabs.ElementAt(0).Controls.ElementAt(1).AccessRights.Rules.Count()); + Assert.AreEqual(AccessType.Deny, SettingsSection.Sections.ElementAt(3).Tabs.ElementAt(0).Controls.ElementAt(1).AccessRights.Rules.ElementAt(0).Action); + Assert.AreEqual("editor", SettingsSection.Sections.ElementAt(3).Tabs.ElementAt(0).Controls.ElementAt(1).AccessRights.Rules.ElementAt(0).Value); + Assert.AreEqual(AccessType.Deny, SettingsSection.Sections.ElementAt(3).Tabs.ElementAt(0).Controls.ElementAt(1).AccessRights.Rules.ElementAt(1).Action); + Assert.AreEqual("writer", SettingsSection.Sections.ElementAt(3).Tabs.ElementAt(0).Controls.ElementAt(1).AccessRights.Rules.ElementAt(1).Value); } } } \ No newline at end of file