diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs
new file mode 100644
index 0000000000..249256cc50
--- /dev/null
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using Umbraco.Core.Models;
+using Umbraco.Tests.TestHelpers;
+using Umbraco.Web;
+
+namespace Umbraco.Tests.PublishedContent
+{
+ [TestFixture]
+ public class PublishedContentExtensionTests : PublishedContentTestBase
+ {
+ private UmbracoContext ctx;
+ private string xmlContent = "";
+ private bool createContentTypes = true;
+
+ protected override DatabaseBehavior DatabaseTestBehavior
+ {
+ get { return DatabaseBehavior.NewDbFileAndSchemaPerFixture; }
+ }
+
+ [SetUp]
+ public override void Initialize()
+ {
+ base.Initialize();
+ }
+
+ [TearDown]
+ public override void TearDown()
+ {
+ base.TearDown();
+ }
+
+ protected override string GetXmlContent(int templateId)
+ {
+ return xmlContent;
+ }
+
+ [Test]
+ public void IsDocumentType_NonRecursive_ActualType_ReturnsTrue()
+ {
+ InitializeInheritedContentTypes();
+
+ var publishedContent = ctx.ContentCache.GetById(1100);
+ Assert.That(publishedContent.IsDocumentType("inherited"));
+ }
+
+ [Test]
+ public void IsDocumentType_NonRecursive_BaseType_ReturnsFalse()
+ {
+ InitializeInheritedContentTypes();
+
+ var publishedContent = ctx.ContentCache.GetById(1100);
+ Assert.That(publishedContent.IsDocumentType("base"), Is.False);
+ }
+
+ [Test]
+ public void IsDocumentType_Recursive_ActualType_ReturnsTrue()
+ {
+ InitializeInheritedContentTypes();
+
+ var publishedContent = ctx.ContentCache.GetById(1100);
+ Assert.That(publishedContent.IsDocumentType("inherited", true));
+ }
+
+ [Test]
+ public void IsDocumentType_Recursive_BaseType_ReturnsTrue()
+ {
+ InitializeInheritedContentTypes();
+
+ var publishedContent = ctx.ContentCache.GetById(1100);
+ Assert.That(publishedContent.IsDocumentType("base", true));
+ }
+
+ [Test]
+ public void IsDocumentType_Recursive_InvalidBaseType_ReturnsFalse()
+ {
+ InitializeInheritedContentTypes();
+
+ var publishedContent = ctx.ContentCache.GetById(1100);
+ Assert.That(publishedContent.IsDocumentType("invalidbase", true), Is.False);
+ }
+
+ private void InitializeInheritedContentTypes()
+ {
+ ctx = GetUmbracoContext("/", 1, null, true);
+ if (createContentTypes)
+ {
+ var contentTypeService = ctx.Application.Services.ContentTypeService;
+ var baseType = new ContentType(-1) {Alias = "base", Name = "Base"};
+ var inheritedType = new ContentType(baseType) {Alias = "inherited", Name = "Inherited"};
+ contentTypeService.Save(baseType);
+ contentTypeService.Save(inheritedType);
+ createContentTypes = false;
+ }
+ #region setup xml content
+ xmlContent = @"
+
+
+]>
+
+
+";
+ #endregion
+ }
+ }
+}
diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj
index 34c578d136..9a483e7974 100644
--- a/src/Umbraco.Tests/Umbraco.Tests.csproj
+++ b/src/Umbraco.Tests/Umbraco.Tests.csproj
@@ -196,6 +196,7 @@
+
diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs
index 29d7e1f22c..086cf1ad5a 100644
--- a/src/Umbraco.Web/PublishedContentExtensions.cs
+++ b/src/Umbraco.Web/PublishedContentExtensions.cs
@@ -537,9 +537,27 @@ namespace Umbraco.Web
#region Is Helpers
- public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias)
+ public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias, bool recursive = false)
{
- return content.DocumentTypeAlias == docTypeAlias;
+ if (content.DocumentTypeAlias == docTypeAlias)
+ return true;
+
+ if (recursive)
+ return IsDocumentTypeRecursive(content, docTypeAlias);
+ return false;
+ }
+
+ private static bool IsDocumentTypeRecursive(IPublishedContent content, string docTypeAlias)
+ {
+ var contentTypeService = UmbracoContext.Current.Application.Services.ContentTypeService;
+ var type = contentTypeService.GetContentType(content.DocumentTypeAlias);
+ while (type.ParentId > 0)
+ {
+ type = contentTypeService.GetContentType(type.ParentId);
+ if (type.Alias == docTypeAlias)
+ return true;
+ }
+ return false;
}
public static bool IsNull(this IPublishedContent content, string alias, bool recursive)