New dashboard config classes all tested

This commit is contained in:
Shannon
2013-10-03 17:50:42 +10:00
parent e2f9b1c7d9
commit b9257fceeb
6 changed files with 136 additions and 14 deletions

View File

@@ -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<IAccessItem> Rules
{
get

View File

@@ -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; }
}
}
}

View File

@@ -9,5 +9,7 @@
string PanelCaption { get; }
string ControlPath { get; }
IAccess AccessRights { get; }
}
}

View File

@@ -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();
}

View File

@@ -6,10 +6,10 @@
<area>settings</area>
</areas>
<tab caption="Get Started">
<control showOnce="true" addPanel="true" panelCaption="">
<control showOnce="true" addPanel="true" panelCaption="hello">
views/dashboard/settings/settingsdashboardintro.html
</control>
<control showOnce="true" addPanel="true" panelCaption="">
<control showOnce="false" addPanel="false" panelCaption="">
views/dashboard/settings/settingsdashboardvideos.html
</control>
</tab>
@@ -60,6 +60,8 @@
<section alias="StartupDashboardSection">
<access>
<deny>translator</deny>
<grant>hello</grant>
<grantBySection>world</grantBySection>
</access>
<areas>
<area>content</area>

View File

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