From 70ccee302d186542235e537ed1ea611ae22cc694 Mon Sep 17 00:00:00 2001
From: Shannon
Date: Fri, 25 Oct 2019 15:08:56 +1100
Subject: [PATCH] Renames/moves some stuff and adds test to show auto relation
tracking
---
...ntityType.cs => Contants-UdiEntityType.cs} | 0
src/Umbraco.Core/Umbraco.Core.csproj | 2 +-
.../Services/ContentServiceTests.cs | 41 +++++++++++++++++++
...Tests.cs => HtmlImageSourceParserTests.cs} | 2 +-
.../HtmlLocalLinkParserTests.cs | 38 ++++++++++++-----
.../Templates/LocalLinkParserTests.cs | 34 ---------------
src/Umbraco.Tests/Umbraco.Tests.csproj | 5 +--
.../PropertyEditors/RichTextPropertyEditor.cs | 4 ++
.../Templates/HtmlImageSourceParser.cs | 2 +-
9 files changed, 78 insertions(+), 50 deletions(-)
rename src/Umbraco.Core/{UdiEntityType.cs => Contants-UdiEntityType.cs} (100%)
rename src/Umbraco.Tests/Templates/{ImageSourceParserTests.cs => HtmlImageSourceParserTests.cs} (98%)
rename src/Umbraco.Tests/{Web => Templates}/HtmlLocalLinkParserTests.cs (78%)
delete mode 100644 src/Umbraco.Tests/Templates/LocalLinkParserTests.cs
diff --git a/src/Umbraco.Core/UdiEntityType.cs b/src/Umbraco.Core/Contants-UdiEntityType.cs
similarity index 100%
rename from src/Umbraco.Core/UdiEntityType.cs
rename to src/Umbraco.Core/Contants-UdiEntityType.cs
diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj
index ff3f8bf972..2fd2c38bdd 100755
--- a/src/Umbraco.Core/Umbraco.Core.csproj
+++ b/src/Umbraco.Core/Umbraco.Core.csproj
@@ -1522,7 +1522,7 @@
-
+
diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs
index 7d65513cc0..89873b5880 100644
--- a/src/Umbraco.Tests/Services/ContentServiceTests.cs
+++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs
@@ -448,6 +448,47 @@ namespace Umbraco.Tests.Services
Assert.That(content.HasIdentity, Is.False);
}
+ [Test]
+ public void Automatically_Track_Relations()
+ {
+ var mt = MockedContentTypes.CreateSimpleMediaType("testMediaType", "Test Media Type");
+ ServiceContext.MediaTypeService.Save(mt);
+ var m1 = MockedMedia.CreateSimpleMedia(mt, "hello 1", -1);
+ var m2 = MockedMedia.CreateSimpleMedia(mt, "hello 1", -1);
+ ServiceContext.MediaService.Save(m1);
+ ServiceContext.MediaService.Save(m2);
+
+ var ct = MockedContentTypes.CreateTextPageContentType("richTextTest");
+ ct.AllowedTemplates = Enumerable.Empty();
+
+ ServiceContext.ContentTypeService.Save(ct);
+
+ var c1 = MockedContent.CreateTextpageContent(ct, "my content 1", -1);
+ ServiceContext.ContentService.Save(c1);
+
+ var c2 = MockedContent.CreateTextpageContent(ct, "my content 2", -1);
+
+ //'bodyText' is a property with a RTE property editor which we knows tracks relations
+ c2.Properties["bodyText"].SetValue(@"
+
+
+
+
+ hello
+
");
+
+ ServiceContext.ContentService.Save(c2);
+
+ var relations = ServiceContext.RelationService.GetByParentId(c2.Id).ToList();
+ Assert.AreEqual(3, relations.Count);
+ Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[0].RelationType.Alias);
+ Assert.AreEqual(m1.Id, relations[0].ChildId);
+ Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[1].RelationType.Alias);
+ Assert.AreEqual(m2.Id, relations[1].ChildId);
+ Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedDocumentAlias, relations[2].RelationType.Alias);
+ Assert.AreEqual(c1.Id, relations[2].ChildId);
+ }
+
[Test]
public void Can_Create_Content_Without_Explicitly_Set_User()
{
diff --git a/src/Umbraco.Tests/Templates/ImageSourceParserTests.cs b/src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs
similarity index 98%
rename from src/Umbraco.Tests/Templates/ImageSourceParserTests.cs
rename to src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs
index dbe5654117..3bef495507 100644
--- a/src/Umbraco.Tests/Templates/ImageSourceParserTests.cs
+++ b/src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs
@@ -20,7 +20,7 @@ namespace Umbraco.Tests.Templates
[TestFixture]
- public class ImageSourceParserTests
+ public class HtmlImageSourceParserTests
{
[Test]
public void Returns_Udis_From_Data_Udi_Html_Attributes()
diff --git a/src/Umbraco.Tests/Web/HtmlLocalLinkParserTests.cs b/src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs
similarity index 78%
rename from src/Umbraco.Tests/Web/HtmlLocalLinkParserTests.cs
rename to src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs
index e6a0abeb4c..7cd96a32ed 100644
--- a/src/Umbraco.Tests/Web/HtmlLocalLinkParserTests.cs
+++ b/src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs
@@ -1,26 +1,44 @@
-using System;
+using Moq;
+using NUnit.Framework;
+using System;
using System.Linq;
using System.Web;
-using Moq;
-using NUnit.Framework;
-using Umbraco.Core.Configuration.UmbracoSettings;
+using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
-using Umbraco.Core.Services;
-using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing.Objects;
using Umbraco.Tests.Testing.Objects.Accessors;
using Umbraco.Web;
-using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.Templates;
-namespace Umbraco.Tests.Web
+namespace Umbraco.Tests.Templates
{
-
[TestFixture]
public class HtmlLocalLinkParserTests
{
+ [Test]
+ public void Returns_Udis_From_LocalLinks()
+ {
+ var input = @"
+
+
+hello
+
";
+
+ var umbracoContextAccessor = new TestUmbracoContextAccessor();
+ var parser = new HtmlLocalLinkParser(umbracoContextAccessor);
+
+ var result = parser.FindUdisFromLocalLinks(input).ToList();
+
+ Assert.AreEqual(2, result.Count);
+ Assert.AreEqual(Udi.Parse("umb://document/C093961595094900AAF9170DDE6AD442"), result[0]);
+ Assert.AreEqual(Udi.Parse("umb://document-type/2D692FCB070B4CDA92FB6883FDBFD6E2"), result[1]);
+ }
+
[TestCase("", "")]
[TestCase("hello href=\"{localLink:1234}\" world ", "hello href=\"/my-test-url\" world ")]
[TestCase("hello href=\"{localLink:umb://document/9931BDE0-AAC3-4BAB-B838-909A7B47570E}\" world ", "hello href=\"/my-test-url\" world ")]
@@ -40,7 +58,7 @@ namespace Umbraco.Tests.Web
var publishedContent = new Mock();
publishedContent.Setup(x => x.Id).Returns(1234);
publishedContent.Setup(x => x.ContentType).Returns(contentType);
-
+
var mediaType = new PublishedContentType(777, "image", PublishedItemType.Media, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Nothing);
var media = new Mock();
media.Setup(x => x.ContentType).Returns(mediaType);
diff --git a/src/Umbraco.Tests/Templates/LocalLinkParserTests.cs b/src/Umbraco.Tests/Templates/LocalLinkParserTests.cs
deleted file mode 100644
index e09d71196e..0000000000
--- a/src/Umbraco.Tests/Templates/LocalLinkParserTests.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using NUnit.Framework;
-using System.Linq;
-using Umbraco.Core;
-using Umbraco.Tests.Testing.Objects.Accessors;
-using Umbraco.Web.Templates;
-
-namespace Umbraco.Tests.Templates
-{
- [TestFixture]
- public class LocalLinkParserTests
- {
- [Test]
- public void Returns_Udis_From_LocalLinks()
- {
- var input = @"
-
-
-hello
-
";
-
- var umbracoContextAccessor = new TestUmbracoContextAccessor();
- var parser = new HtmlLocalLinkParser(umbracoContextAccessor);
-
- var result = parser.FindUdisFromLocalLinks(input).ToList();
-
- Assert.AreEqual(2, result.Count);
- Assert.AreEqual(Udi.Parse("umb://document/C093961595094900AAF9170DDE6AD442"), result[0]);
- Assert.AreEqual(Udi.Parse("umb://document-type/2D692FCB070B4CDA92FB6883FDBFD6E2"), result[1]);
- }
- }
-}
diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj
index fa654ad4a4..4b035f631e 100644
--- a/src/Umbraco.Tests/Umbraco.Tests.csproj
+++ b/src/Umbraco.Tests/Umbraco.Tests.csproj
@@ -159,7 +159,7 @@
-
+
@@ -255,8 +255,7 @@
-
-
+
diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs
index 77617f7779..1c97a2de7a 100644
--- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs
@@ -140,9 +140,13 @@ namespace Umbraco.Web.PropertyEditors
{
var asString = value == null ? string.Empty : value is string str ? str : value.ToString();
+ //TODO: FindUdisFromDataAttributes will return UDIs of any type found, typically these will always be "media" but
+ // if the text is modified to be another type it will still be returned but we will always be relating these with the RelatedMediaAlias
foreach (var udi in _imageSourceParser.FindUdisFromDataAttributes(asString))
yield return new UmbracoEntityReference(udi, Constants.Conventions.RelationTypes.RelatedMediaAlias);
+ //TODO: FindUdisFromLocalLinks will return UDIs of any type found, typically these will always be "document" but
+ // if the text is modified to be another type it will still be returned but we will always be relating these with the RelatedDocumentAlias
foreach (var udi in _localLinkParser.FindUdisFromLocalLinks(asString))
yield return new UmbracoEntityReference(udi, Constants.Conventions.RelationTypes.RelatedDocumentAlias);
diff --git a/src/Umbraco.Web/Templates/HtmlImageSourceParser.cs b/src/Umbraco.Web/Templates/HtmlImageSourceParser.cs
index 66a1cee5bb..b0d6980ef3 100644
--- a/src/Umbraco.Web/Templates/HtmlImageSourceParser.cs
+++ b/src/Umbraco.Web/Templates/HtmlImageSourceParser.cs
@@ -20,7 +20,7 @@ namespace Umbraco.Web.Templates
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
///
- /// Parses out UDIs from an html string based on 'data-udi' html attributes
+ /// Parses out media UDIs from an html string based on 'data-udi' html attributes
///
///
///