-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6807 from umbraco/v8/feature/AB2461-media-tracking
Splits up TemplateUtilities into testable parts, creates new GetReferences API
- Loading branch information
Showing
29 changed files
with
860 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Umbraco.Core.PropertyEditors | ||
{ | ||
/// <summary> | ||
/// Resolve references from <see cref="IDataValueEditor"/> values | ||
/// </summary> | ||
public interface IDataValueReference | ||
{ | ||
/// <summary> | ||
/// Returns any references contained in the value | ||
/// </summary> | ||
/// <param name="value"></param> | ||
/// <returns></returns> | ||
IEnumerable<Udi> GetReferences(object value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
|
||
namespace Umbraco.Tests.PropertyEditors | ||
{ | ||
|
||
[TestFixture] | ||
public class ImageCropperTest | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using Umbraco.Core.Logging; | ||
using Moq; | ||
using NUnit.Framework; | ||
using Umbraco.Core.Services; | ||
using Umbraco.Tests.Testing.Objects.Accessors; | ||
using Umbraco.Web.Templates; | ||
using Umbraco.Web; | ||
using Umbraco.Core.Models.PublishedContent; | ||
using Umbraco.Web.Routing; | ||
using Umbraco.Tests.Testing.Objects; | ||
using System.Web; | ||
using System; | ||
using System.Linq; | ||
using Umbraco.Core.Models; | ||
using Umbraco.Core; | ||
|
||
namespace Umbraco.Tests.Templates | ||
{ | ||
|
||
|
||
[TestFixture] | ||
public class ImageSourceParserTests | ||
{ | ||
[Test] | ||
public void Returns_Udis_From_Data_Udi_Html_Attributes() | ||
{ | ||
var input = @"<p> | ||
<div> | ||
<img src='/media/12312.jpg' data-udi='umb://media/D4B18427A1544721B09AC7692F35C264' /> | ||
</div> | ||
</p><p><img src='/media/234234.jpg' data-udi=""umb://media-type/B726D735E4C446D58F703F3FBCFC97A5"" /></p>"; | ||
|
||
var logger = Mock.Of<ILogger>(); | ||
var umbracoContextAccessor = new TestUmbracoContextAccessor(); | ||
var imageSourceParser = new HtmlImageSourceParser(umbracoContextAccessor, logger, Mock.Of<IMediaService>(), Mock.Of<IContentTypeBaseServiceProvider>()); | ||
|
||
var result = imageSourceParser.FindUdisFromDataAttributes(input).ToList(); | ||
Assert.AreEqual(2, result.Count); | ||
Assert.AreEqual(Udi.Parse("umb://media/D4B18427A1544721B09AC7692F35C264"), result[0]); | ||
Assert.AreEqual(Udi.Parse("umb://media-type/B726D735E4C446D58F703F3FBCFC97A5"), result[1]); | ||
} | ||
|
||
[Test] | ||
public void Remove_Image_Sources() | ||
{ | ||
var logger = Mock.Of<ILogger>(); | ||
var umbracoContextAccessor = new TestUmbracoContextAccessor(); | ||
var imageSourceParser = new HtmlImageSourceParser(umbracoContextAccessor, logger, Mock.Of<IMediaService>(), Mock.Of<IContentTypeBaseServiceProvider>()); | ||
|
||
var result = imageSourceParser.RemoveImageSources(@"<p> | ||
<div> | ||
<img src=""/media/12354/test.jpg"" /> | ||
</div></p> | ||
<p> | ||
<div><img src=""/media/987645/test.jpg"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div> | ||
</p>"); | ||
|
||
Assert.AreEqual(@"<p> | ||
<div> | ||
<img src=""/media/12354/test.jpg"" /> | ||
</div></p> | ||
<p> | ||
<div><img src="""" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div> | ||
</p>", result); | ||
} | ||
|
||
[Test] | ||
public void Ensure_Image_Sources() | ||
{ | ||
//setup a mock url provider which we'll use for testing | ||
|
||
var mediaType = new PublishedContentType(777, "image", PublishedItemType.Media, Enumerable.Empty<string>(), Enumerable.Empty<PublishedPropertyType>(), ContentVariation.Nothing); | ||
var media = new Mock<IPublishedContent>(); | ||
media.Setup(x => x.ContentType).Returns(mediaType); | ||
var mediaUrlProvider = new Mock<IMediaUrlProvider>(); | ||
mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny<UmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<string>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>())) | ||
.Returns(UrlInfo.Url("/media/1001/my-image.jpg")); | ||
|
||
var umbracoContextAccessor = new TestUmbracoContextAccessor(); | ||
|
||
var umbracoContextFactory = TestUmbracoContextFactory.Create( | ||
mediaUrlProvider: mediaUrlProvider.Object, | ||
umbracoContextAccessor: umbracoContextAccessor); | ||
|
||
using (var reference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>())) | ||
{ | ||
var mediaCache = Mock.Get(reference.UmbracoContext.Media); | ||
mediaCache.Setup(x => x.GetById(It.IsAny<Guid>())).Returns(media.Object); | ||
|
||
var imageSourceParser = new HtmlImageSourceParser(umbracoContextAccessor, Mock.Of<ILogger>(), Mock.Of<IMediaService>(), Mock.Of<IContentTypeBaseServiceProvider>()); | ||
|
||
var result = imageSourceParser.EnsureImageSources(@"<p> | ||
<div> | ||
<img src="""" /> | ||
</div></p> | ||
<p> | ||
<div><img src="""" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div> | ||
</p> | ||
<p> | ||
<div><img src=""?width=100"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div> | ||
</p>"); | ||
|
||
Assert.AreEqual(@"<p> | ||
<div> | ||
<img src="""" /> | ||
</div></p> | ||
<p> | ||
<div><img src=""/media/1001/my-image.jpg"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div> | ||
</p> | ||
<p> | ||
<div><img src=""/media/1001/my-image.jpg?width=100"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div> | ||
</p>", result); | ||
|
||
} | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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 = @"<p> | ||
<div> | ||
<img src='/media/12312.jpg' data-udi='umb://media/D4B18427A1544721B09AC7692F35C264' /> | ||
<a href=""{locallink:umb://document/C093961595094900AAF9170DDE6AD442}"">hello</a> | ||
</div> | ||
</p><p><img src='/media/234234.jpg' data-udi=""umb://media-type/B726D735E4C446D58F703F3FBCFC97A5"" /> | ||
<a href=""{locallink:umb://document-type/2D692FCB070B4CDA92FB6883FDBFD6E2}"">hello</a> | ||
</p>"; | ||
|
||
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]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Moq; | ||
using Umbraco.Core.Configuration; | ||
using Umbraco.Core.Configuration.UmbracoSettings; | ||
using Umbraco.Core.Services; | ||
using Umbraco.Tests.TestHelpers; | ||
using Umbraco.Tests.Testing.Objects.Accessors; | ||
using Umbraco.Web; | ||
using Umbraco.Web.PublishedCache; | ||
using Umbraco.Web.Routing; | ||
|
||
namespace Umbraco.Tests.Testing.Objects | ||
{ | ||
/// <summary> | ||
/// Simplify creating test UmbracoContext's | ||
/// </summary> | ||
public class TestUmbracoContextFactory | ||
{ | ||
public static IUmbracoContextFactory Create(IGlobalSettings globalSettings = null, IUrlProvider urlProvider = null, | ||
IMediaUrlProvider mediaUrlProvider = null, | ||
IUmbracoContextAccessor umbracoContextAccessor = null) | ||
{ | ||
if (globalSettings == null) globalSettings = SettingsForTests.GenerateMockGlobalSettings(); | ||
if (urlProvider == null) urlProvider = Mock.Of<IUrlProvider>(); | ||
if (mediaUrlProvider == null) mediaUrlProvider = Mock.Of<IMediaUrlProvider>(); | ||
if (umbracoContextAccessor == null) umbracoContextAccessor = new TestUmbracoContextAccessor(); | ||
|
||
var contentCache = new Mock<IPublishedContentCache>(); | ||
var mediaCache = new Mock<IPublishedMediaCache>(); | ||
var snapshot = new Mock<IPublishedSnapshot>(); | ||
snapshot.Setup(x => x.Content).Returns(contentCache.Object); | ||
snapshot.Setup(x => x.Media).Returns(mediaCache.Object); | ||
var snapshotService = new Mock<IPublishedSnapshotService>(); | ||
snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(snapshot.Object); | ||
|
||
var umbracoContextFactory = new UmbracoContextFactory( | ||
umbracoContextAccessor, | ||
snapshotService.Object, | ||
new TestVariationContextAccessor(), | ||
new TestDefaultCultureAccessor(), | ||
Mock.Of<IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of<IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "Auto")), | ||
globalSettings, | ||
new UrlProviderCollection(new[] { urlProvider }), | ||
new MediaUrlProviderCollection(new[] { mediaUrlProvider }), | ||
Mock.Of<IUserService>()); | ||
|
||
return umbracoContextFactory; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.