Adding a BaseTheme property to Theme

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-10-05 13:55:29 -07:00
parent 5b53005f14
commit 7b36d725b5
9 changed files with 282 additions and 34 deletions

View File

@@ -59,6 +59,7 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\autofac\Autofac.dll</HintPath>
</Reference>
<Reference Include="Castle.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL" />
<Reference Include="FluentNHibernate, Version=1.0.0.593, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
@@ -127,6 +128,7 @@
<Compile Include="Roles\Controllers\AdminControllerTests.cs" />
<Compile Include="Roles\Services\RoleServiceTests.cs" />
<Compile Include="Settings\Blueprint\ShellDescriptorManagerTests.cs" />
<Compile Include="Themes\Services\ThemeServiceTests.cs" />
<Compile Include="Values.cs" />
<Compile Include="Users\Controllers\AdminControllerTests.cs" />
<Compile Include="Users\Services\MembershipServiceTests.cs" />
@@ -148,6 +150,10 @@
<Project>{C0C45321-B51D-4D8D-9B7B-AA4C2E0B2962}</Project>
<Name>Orchard.CodeGeneration</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Modules\Orchard.Modules.csproj">
<Project>{17F86780-9A1F-4AA1-86F1-875EEC2730C7}</Project>
<Name>Orchard.Modules</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Roles\Orchard.Roles.csproj">
<Project>{D10AD48F-407D-4DB5-A328-173EC7CB010F}</Project>
<Name>Orchard.Roles</Name>
@@ -156,6 +162,10 @@
<Project>{8C7FCBC2-E6E1-405E-BFB5-D8D9E67A09C4}</Project>
<Name>Orchard.Setup</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Themes\Orchard.Themes.csproj">
<Project>{CDE24A24-01D3-403C-84B9-37722E18DFB7}</Project>
<Name>Orchard.Themes</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Users\Orchard.Users.csproj">
<Project>{79AED36E-ABD0-4747-93D3-8722B042454B}</Project>
<Name>Orchard.Users</Name>

View File

@@ -0,0 +1,229 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using Autofac;
using NHibernate;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.MetaData.Services;
using Orchard.ContentManagement.Records;
using Orchard.Core.Settings.Descriptor.Records;
using Orchard.Core.Settings.Handlers;
using Orchard.Core.Settings.Metadata;
using Orchard.Core.Settings.Models;
using Orchard.Core.Settings.Services;
using Orchard.Data;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Implementation;
using Orchard.Environment;
using Orchard.Environment.AutofacUtil.DynamicProxy2;
using Orchard.Environment.Descriptor;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Localization;
using Orchard.Modules;
using Orchard.Modules.Services;
using Orchard.Security;
using Orchard.Security.Permissions;
using Orchard.Settings;
using Orchard.Tests.Stubs;
using Orchard.Themes;
using Orchard.Themes.Handlers;
using Orchard.Themes.Models;
using Orchard.Themes.Services;
using Orchard.UI.Notify;
namespace Orchard.Tests.Modules.Themes.Services {
[TestFixture]
public class ThemeServiceTests {
private IThemeService _themeService;
private IContainer _container;
private ISessionFactory _sessionFactory;
private ISession _session;
[TestFixtureSetUp]
public void InitFixture() {
var databaseFileName = System.IO.Path.GetTempFileName();
_sessionFactory = DataUtility.CreateSessionFactory(databaseFileName,
typeof(ThemeSiteSettingsPartRecord),
typeof(SiteSettingsPartRecord),
typeof(ContentItemVersionRecord),
typeof(ContentItemRecord),
typeof(ContentTypeRecord));
}
[TestFixtureTearDown]
public void TermFixture() { }
[SetUp]
public void Init() {
var context = new DynamicProxyContext();
var builder = new ContainerBuilder();
builder.RegisterModule(new SettingsModule());
builder.RegisterType<ThemeService>().EnableDynamicProxy(context).As<IThemeService>();
builder.RegisterType<SettingsModuleInterceptor>().As<ISettingsModuleInterceptor>();
builder.RegisterType<SiteService>().As<ISiteService>();
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
builder.RegisterType<ShapeHelperFactory>().As<IShapeHelperFactory>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
builder.RegisterType<SiteSettingsPartHandler>().As<IContentHandler>();
builder.RegisterType<ThemeSiteSettingsPartHandler>().As<IContentHandler>();
builder.RegisterType<ModuleService>().As<IModuleService>();
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
builder.RegisterType<StubShellDescriptorManager>().As<IShellDescriptorManager>();
builder.RegisterType<TransactionManager>().As<ITransactionManager>();
builder.RegisterType<Notifier>().As<INotifier>();
builder.RegisterType<StubAuthorizer>().As<IAuthorizer>();
builder.RegisterType(typeof(SettingsFormatter))
.As(typeof(IMapper<XElement, SettingsDictionary>))
.As(typeof(IMapper<SettingsDictionary, XElement>));
_session = _sessionFactory.OpenSession();
builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>();
_container = builder.Build();
_themeService = _container.Resolve<IThemeService>();
}
//todo: test theme feature enablement
[Test]
public void ThemeWithNoBaseThemeCanBeSetAsSiteTheme() {
_themeService.SetSiteTheme("ThemeOne");
var siteTheme = _themeService.GetSiteTheme();
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeOne"));
}
[Test]
public void ThemeWithAvailableBaseThemeCanBeSetAsSiteTheme() {
_themeService.SetSiteTheme("ThemeTwo");
var siteTheme = _themeService.GetSiteTheme();
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeTwo"));
Assert.That(siteTheme.BaseTheme, Is.EqualTo("ThemeOne"));
}
[Test]
public void ThemeWithUnavailableBaseThemeCanBeSetAsSiteTheme() {
_themeService.SetSiteTheme("ThemeOne");
_themeService.SetSiteTheme("ThemeThree");
var siteTheme = _themeService.GetSiteTheme();
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeOne"));
}
#region Stubs
public class TestSessionLocator : ISessionLocator {
private readonly ISession _session;
public TestSessionLocator(ISession session) {
_session = session;
}
public ISession For(Type entityType) {
return _session;
}
}
public class StubAuthorizer : IAuthorizer {
public bool Authorize(Permission permission) {
return true;
}
public bool Authorize(Permission permission, LocalizedString message) {
return true;
}
public bool Authorize(Permission permission, IContent content, LocalizedString message) {
return true;
}
}
public class StubExtensionManager : IExtensionManager {
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
var extensions = new[] {
new ExtensionDescriptor {Name = "ThemeOne", ExtensionType = "Theme"},
new ExtensionDescriptor {Name = "ThemeTwo", BaseTheme = "ThemeOne", ExtensionType = "Theme"},
new ExtensionDescriptor {Name = "ThemeThree", BaseTheme = "TheThemeThatIsntThere", ExtensionType = "Theme"},
};
foreach (var extension in extensions) {
extension.Features = new[] { new FeatureDescriptor { Extension = extension, Name = extension.Name } };
yield return extension;
}
}
public IEnumerable<FeatureDescriptor> AvailableFeatures() {
return AvailableExtensions().SelectMany(ed => ed.Features);
}
public IEnumerable<Feature> LoadFeatures(IEnumerable<FeatureDescriptor> featureDescriptors) {
return featureDescriptors.Select(FrameworkFeature);
}
private static Feature FrameworkFeature(FeatureDescriptor descriptor) {
return new Feature {
Descriptor = descriptor
};
}
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
throw new NotImplementedException();
}
public void UninstallExtension(string extensionType, string extensionName) {
throw new NotImplementedException();
}
public void Monitor(Action<IVolatileToken> monitor) {
throw new NotImplementedException();
}
}
public class StubShellDescriptorManager : IShellDescriptorManager {
private readonly ShellDescriptorRecord _shellDescriptorRecord = new ShellDescriptorRecord();
public ShellDescriptor GetShellDescriptor() {
return GetShellDescriptorFromRecord(_shellDescriptorRecord);
}
public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable<ShellFeature> enabledFeatures, IEnumerable<ShellParameter> parameters) {
_shellDescriptorRecord.Features.Clear();
foreach (var feature in enabledFeatures) {
_shellDescriptorRecord.Features.Add(new ShellFeatureRecord { Name = feature.Name, ShellDescriptorRecord = null });
}
_shellDescriptorRecord.Parameters.Clear();
foreach (var parameter in parameters) {
_shellDescriptorRecord.Parameters.Add(new ShellParameterRecord {
Component = parameter.Component,
Name = parameter.Name,
Value = parameter.Value,
ShellDescriptorRecord = null
});
}
}
private static ShellDescriptor GetShellDescriptorFromRecord(ShellDescriptorRecord shellDescriptorRecord) {
return new ShellDescriptor {
SerialNumber = shellDescriptorRecord.SerialNumber,
Features = shellDescriptorRecord.Features.Select(descriptorFeatureRecord => new ShellFeature {Name = descriptorFeatureRecord.Name}).ToList(),
Parameters = shellDescriptorRecord.Parameters.Select(descriptorParameterRecord => new ShellParameter {
Component = descriptorParameterRecord.Component, Name = descriptorParameterRecord.Name, Value = descriptorParameterRecord.Value
}).ToList()
};
}
}
#endregion
}
}