Files
Umbraco-CMS/tests/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs
Paul Johnson 00133e880d Move test projects from src/ to tests/ (#11357)
* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
2021-10-18 08:14:04 +01:00

105 lines
4.0 KiB
C#

using System.Collections.Generic;
using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Extensions;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.PublishedContent
{
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
public class PublishedContentExtensionTests : PublishedContentTestBase
{
private IUmbracoContext _ctx;
private string _xmlContent = "";
private bool _createContentTypes = true;
private Dictionary<string, PublishedContentType> _contentTypes;
protected override string GetXmlContent(int templateId)
{
return _xmlContent;
}
[Test]
public void IsDocumentType_NonRecursive_ActualType_ReturnsTrue()
{
InitializeInheritedContentTypes();
var publishedContent = _ctx.Content.GetById(1100);
Assert.That(publishedContent.IsDocumentType("inherited", false));
}
[Test]
public void IsDocumentType_NonRecursive_BaseType_ReturnsFalse()
{
InitializeInheritedContentTypes();
var publishedContent = _ctx.Content.GetById(1100);
Assert.That(publishedContent.IsDocumentType("base", false), Is.False);
}
[Test]
public void IsDocumentType_Recursive_ActualType_ReturnsTrue()
{
InitializeInheritedContentTypes();
var publishedContent = _ctx.Content.GetById(1100);
Assert.That(publishedContent.IsDocumentType("inherited", true));
}
[Test]
public void IsDocumentType_Recursive_BaseType_ReturnsTrue()
{
InitializeInheritedContentTypes();
ContentTypesCache.GetPublishedContentTypeByAlias = null;
var publishedContent = _ctx.Content.GetById(1100);
Assert.That(publishedContent.IsDocumentType("base", true));
}
[Test]
public void IsDocumentType_Recursive_InvalidBaseType_ReturnsFalse()
{
InitializeInheritedContentTypes();
var publishedContent = _ctx.Content.GetById(1100);
Assert.That(publishedContent.IsDocumentType("invalidbase", true), Is.False);
}
private void InitializeInheritedContentTypes()
{
_ctx = GetUmbracoContext("/", 1, null, true);
if (_createContentTypes)
{
var contentTypeService = ServiceContext.ContentTypeService;
var baseType = new ContentType(ShortStringHelper, -1) { Alias = "base", Name = "Base" };
const string contentTypeAlias = "inherited";
var inheritedType = new ContentType(ShortStringHelper, baseType, contentTypeAlias) { Alias = contentTypeAlias, Name = "Inherited" };
contentTypeService.Save(baseType);
contentTypeService.Save(inheritedType);
_contentTypes = new Dictionary<string, PublishedContentType>
{
{ baseType.Alias, new PublishedContentType(baseType, null) },
{ inheritedType.Alias, new PublishedContentType(inheritedType, null) }
};
ContentTypesCache.GetPublishedContentTypeByAlias = alias => _contentTypes[alias];
_createContentTypes = false;
}
ContentTypesCache.GetPublishedContentTypeByAlias = alias => _contentTypes[alias];
_xmlContent = @"<?xml version=""1.0"" encoding=""utf-8""?>
<!DOCTYPE root[
<!ELEMENT inherited ANY>
<!ATTLIST inherited id ID #REQUIRED>
]>
<root id=""-1"">
<inherited id=""1100"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1"" sortOrder=""1"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc=""""/>
</root>";
}
}
}