2013-03-19 17:54:41 -01:00
|
|
|
using System;
|
2012-10-04 01:31:08 +05:00
|
|
|
using System.Linq;
|
2012-07-31 00:02:27 +06:00
|
|
|
using System.Xml;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Umbraco.Core;
|
2013-02-21 22:02:56 +06:00
|
|
|
using Umbraco.Core.Configuration;
|
2012-07-31 00:02:27 +06:00
|
|
|
using Umbraco.Tests.TestHelpers;
|
|
|
|
|
using Umbraco.Web;
|
2013-03-19 17:51:55 -01:00
|
|
|
using Umbraco.Web.PublishedCache;
|
2013-03-22 15:02:26 -01:00
|
|
|
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
2012-07-31 00:02:27 +06:00
|
|
|
using Umbraco.Web.Routing;
|
|
|
|
|
using umbraco.BusinessLogic;
|
|
|
|
|
|
2013-02-05 06:31:13 -01:00
|
|
|
namespace Umbraco.Tests.PublishedCache
|
2012-07-31 00:02:27 +06:00
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-03-19 17:54:41 -01:00
|
|
|
public class PublishContentCacheTests
|
2012-07-31 00:02:27 +06:00
|
|
|
{
|
|
|
|
|
private FakeHttpContextFactory _httpContextFactory;
|
|
|
|
|
private UmbracoContext _umbracoContext;
|
2013-03-19 17:51:55 -01:00
|
|
|
private ContextualPublishedContentCache _cache;
|
2012-07-31 00:02:27 +06:00
|
|
|
|
2012-10-04 21:37:11 +05:00
|
|
|
private string GetLegacyXml()
|
2012-07-31 00:02:27 +06:00
|
|
|
{
|
2012-10-04 21:37:11 +05:00
|
|
|
return @"<?xml version=""1.0"" encoding=""utf-8""?><!DOCTYPE root[
|
|
|
|
|
<!ELEMENT node ANY> <!ATTLIST node id ID #REQUIRED> <!ELEMENT data ANY>
|
2012-07-31 02:34:57 +06:00
|
|
|
|
2012-10-04 21:37:11 +05:00
|
|
|
]>
|
|
|
|
|
<root id=""-1"">
|
|
|
|
|
<node id=""1046"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
|
|
|
|
<node id=""1173"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""1"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""sub1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173"" nodeTypeAlias=""Home""><content><![CDATA[]]></content>
|
|
|
|
|
<node id=""1174"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""1"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""sub2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1174"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
|
|
|
|
</node>
|
|
|
|
|
<node id=""1176"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
|
|
|
|
</node>
|
|
|
|
|
</node>
|
|
|
|
|
<node id=""1175"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1175"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
|
|
|
|
</node>
|
|
|
|
|
</node>
|
|
|
|
|
<node id=""1172"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""3"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test"" writerName=""admin"" creatorName=""admin"" path=""-1,1172"" nodeTypeAlias=""Home"" />
|
|
|
|
|
</root>";
|
|
|
|
|
}
|
2012-07-31 00:02:27 +06:00
|
|
|
|
2012-10-04 21:37:11 +05:00
|
|
|
private string GetXml()
|
|
|
|
|
{
|
|
|
|
|
return @"<?xml version=""1.0"" encoding=""utf-8""?><!DOCTYPE root[
|
2012-07-31 00:02:27 +06:00
|
|
|
<!ELEMENT Home ANY>
|
|
|
|
|
<!ATTLIST Home id ID #REQUIRED>
|
|
|
|
|
|
|
|
|
|
]>
|
|
|
|
|
<root id=""-1"">
|
|
|
|
|
<Home id=""1046"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
<Home id=""1173"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""1"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""sub1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
<Home id=""1174"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""1"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""sub2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1174"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
</Home>
|
|
|
|
|
<Home id=""1176"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
</Home>
|
|
|
|
|
</Home>
|
|
|
|
|
<Home id=""1175"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1175"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
</Home>
|
2013-02-19 13:58:16 -01:00
|
|
|
<Home id=""1177"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub'Apostrophe"" urlName=""sub'apostrophe"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1177"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
</Home>
|
2012-07-31 00:02:27 +06:00
|
|
|
</Home>
|
|
|
|
|
<Home id=""1172"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""3"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test"" writerName=""admin"" creatorName=""admin"" path=""-1,1172"" isDoc="""" />
|
2012-10-04 21:37:11 +05:00
|
|
|
</root>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp()
|
|
|
|
|
{
|
|
|
|
|
TestHelper.SetupLog4NetForTests();
|
2013-02-21 22:02:56 +06:00
|
|
|
|
2012-10-04 21:37:11 +05:00
|
|
|
_httpContextFactory = new FakeHttpContextFactory("~/Home");
|
|
|
|
|
//ensure the StateHelper is using our custom context
|
|
|
|
|
StateHelper.HttpContext = _httpContextFactory.HttpContext;
|
2013-03-19 17:54:41 -01:00
|
|
|
|
|
|
|
|
var cache = new PublishedContentCache
|
|
|
|
|
{
|
|
|
|
|
GetXmlDelegate = (user, preview) =>
|
|
|
|
|
{
|
|
|
|
|
var doc = new XmlDocument();
|
|
|
|
|
doc.LoadXml(GetXml());
|
|
|
|
|
return doc;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_umbracoContext = new UmbracoContext(
|
2013-03-19 17:50:36 -01:00
|
|
|
_httpContextFactory.HttpContext,
|
|
|
|
|
new ApplicationContext(),
|
2013-03-19 17:54:41 -01:00
|
|
|
cache,
|
2013-03-19 17:50:36 -01:00
|
|
|
new PublishedMediaCache());
|
2012-10-04 21:37:11 +05:00
|
|
|
|
2013-03-19 17:54:41 -01:00
|
|
|
_cache = _umbracoContext.ContentCache;
|
2012-10-04 21:37:11 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetupForLegacy()
|
|
|
|
|
{
|
|
|
|
|
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = true;
|
2013-03-19 17:54:41 -01:00
|
|
|
|
2013-03-19 17:54:41 -01:00
|
|
|
var cache = _umbracoContext.ContentCache.InnerCache as PublishedContentCache;
|
2013-03-19 17:54:41 -01:00
|
|
|
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported.");
|
|
|
|
|
|
|
|
|
|
cache.GetXmlDelegate = (user, preview) =>
|
|
|
|
|
{
|
2013-03-19 17:54:41 -01:00
|
|
|
var doc = new XmlDocument();
|
|
|
|
|
doc.LoadXml(GetLegacyXml());
|
|
|
|
|
return doc;
|
2012-10-04 21:37:11 +05:00
|
|
|
};
|
2012-07-31 00:02:27 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown()
|
|
|
|
|
{
|
2013-02-26 16:52:44 -01:00
|
|
|
UmbracoSettings.Reset();
|
2012-07-31 00:02:27 +06:00
|
|
|
}
|
|
|
|
|
|
2012-10-04 21:37:11 +05:00
|
|
|
[Test]
|
|
|
|
|
public void Has_Content_LegacySchema()
|
|
|
|
|
{
|
|
|
|
|
SetupForLegacy();
|
|
|
|
|
Has_Content();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Has_Content()
|
|
|
|
|
{
|
2013-03-19 17:54:41 -01:00
|
|
|
Assert.IsTrue(_cache.HasContent());
|
2012-10-04 21:37:11 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Get_Root_Docs_LegacySchema()
|
|
|
|
|
{
|
|
|
|
|
SetupForLegacy();
|
|
|
|
|
Get_Root_Docs();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-04 01:31:08 +05:00
|
|
|
[Test]
|
|
|
|
|
public void Get_Root_Docs()
|
|
|
|
|
{
|
2013-03-19 17:51:55 -01:00
|
|
|
var result = _cache.GetAtRoot();
|
2012-10-04 01:31:08 +05:00
|
|
|
Assert.AreEqual(2, result.Count());
|
|
|
|
|
Assert.AreEqual(1046, result.ElementAt(0).Id);
|
|
|
|
|
Assert.AreEqual(1172, result.ElementAt(1).Id);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-04 21:37:11 +05:00
|
|
|
[TestCase("/", 1046)]
|
|
|
|
|
[TestCase("/home", 1046)]
|
|
|
|
|
[TestCase("/Home", 1046)] //test different cases
|
|
|
|
|
[TestCase("/home/sub1", 1173)]
|
|
|
|
|
[TestCase("/Home/sub1", 1173)]
|
|
|
|
|
[TestCase("/home/Sub1", 1173)] //test different cases
|
|
|
|
|
public void Get_Node_By_Route_LegacySchema(string route, int nodeId)
|
|
|
|
|
{
|
|
|
|
|
SetupForLegacy();
|
|
|
|
|
Get_Node_By_Route(route, nodeId);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 07:41:13 +06:00
|
|
|
[TestCase("/", 1046)]
|
|
|
|
|
[TestCase("/home", 1046)]
|
|
|
|
|
[TestCase("/Home", 1046)] //test different cases
|
|
|
|
|
[TestCase("/home/sub1", 1173)]
|
|
|
|
|
[TestCase("/Home/sub1", 1173)]
|
|
|
|
|
[TestCase("/home/Sub1", 1173)] //test different cases
|
2013-02-19 13:58:16 -01:00
|
|
|
[TestCase("/home/Sub'Apostrophe", 1177)]
|
2012-08-09 07:41:13 +06:00
|
|
|
public void Get_Node_By_Route(string route, int nodeId)
|
|
|
|
|
{
|
2013-03-19 17:51:55 -01:00
|
|
|
var result = _cache.GetByRoute(route, false);
|
2012-08-09 07:41:13 +06:00
|
|
|
Assert.IsNotNull(result);
|
2012-08-10 13:08:47 +06:00
|
|
|
Assert.AreEqual(nodeId, result.Id);
|
2012-08-09 07:41:13 +06:00
|
|
|
}
|
|
|
|
|
|
2012-10-04 21:37:11 +05:00
|
|
|
[TestCase("/", 1046)]
|
|
|
|
|
[TestCase("/sub1", 1173)]
|
|
|
|
|
[TestCase("/Sub1", 1173)]
|
|
|
|
|
public void Get_Node_By_Route_Hiding_Top_Level_Nodes_LegacySchema(string route, int nodeId)
|
|
|
|
|
{
|
|
|
|
|
SetupForLegacy();
|
|
|
|
|
Get_Node_By_Route_Hiding_Top_Level_Nodes(route, nodeId);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 07:41:13 +06:00
|
|
|
[TestCase("/", 1046)]
|
|
|
|
|
[TestCase("/sub1", 1173)]
|
|
|
|
|
[TestCase("/Sub1", 1173)]
|
|
|
|
|
public void Get_Node_By_Route_Hiding_Top_Level_Nodes(string route, int nodeId)
|
2012-07-31 00:02:27 +06:00
|
|
|
{
|
2013-03-19 17:51:55 -01:00
|
|
|
var result = _cache.GetByRoute(route, true);
|
2012-07-31 00:02:27 +06:00
|
|
|
Assert.IsNotNull(result);
|
2012-08-10 13:08:47 +06:00
|
|
|
Assert.AreEqual(nodeId, result.Id);
|
2012-07-31 00:02:27 +06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|