From 6f76ee384ccb20b90bc6fcd5eee9c5ddf721da87 Mon Sep 17 00:00:00 2001 From: Jeavon Leopold Date: Thu, 20 Aug 2015 09:31:20 +0100 Subject: [PATCH] Added some extra GetCropUrl tests as you can never have too many --- .../PropertyEditors/ImageCropperTest.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs index 0cbf09f782..4a398082ce 100644 --- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs @@ -21,6 +21,16 @@ namespace Umbraco.Tests.PropertyEditors Assert.AreEqual(mediaPath + "?crop=0.58729977382575338,0.055768992440203169,0,0.32457553600198386&cropmode=percentage&width=100&height=100", urlString); } + /// + /// Test to ensure useCropDimensions is observed + /// + [Test] + public void GetCropUrl_CropAliasIgnoreWidthHeightTest() + { + var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, cropAlias: "Thumb", useCropDimensions: true, width: 50, height: 50); + Assert.AreEqual(mediaPath + "?crop=0.58729977382575338,0.055768992440203169,0,0.32457553600198386&cropmode=percentage&width=100&height=100", urlString); + } + [Test] public void GetCropUrl_WidthHeightTest() { @@ -125,6 +135,9 @@ namespace Umbraco.Tests.PropertyEditors Assert.AreEqual(mediaPath + "?anchor=center&mode=crop&width=300&height=150", urlString); } + /// + /// Test to check if height ratio is returned for a predefined crop without coordinates and focal point in centre when a width parameter is passed + /// [Test] public void GetCropUrl_PreDefinedCropNoCoordinatesWithWidth() { @@ -134,6 +147,9 @@ namespace Umbraco.Tests.PropertyEditors Assert.AreEqual(mediaPath + "?anchor=center&mode=crop&heightratio=0.5962962962962962962962962963&width=200", urlString); } + /// + /// Test to check if height ratio is returned for a predefined crop without coordinates and focal point is custom when a width parameter is passed + /// [Test] public void GetCropUrl_PreDefinedCropNoCoordinatesWithWidthAndFocalPoint() { @@ -143,6 +159,21 @@ namespace Umbraco.Tests.PropertyEditors Assert.AreEqual(mediaPath + "?center=0.41,0.4275&mode=crop&heightratio=0.5962962962962962962962962963&width=200", urlString); } + /// + /// Test to check if crop ratio is ignored if useCropDimensions is true + /// + [Test] + public void GetCropUrl_PreDefinedCropNoCoordinatesWithWidthAndFocalPointIgnore() + { + var cropperJson = "{\"focalPoint\": {\"left\": 0.4275,\"top\": 0.41},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}"; + + var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, cropAlias: "home", width: 200, useCropDimensions: true); + Assert.AreEqual(mediaPath + "?center=0.41,0.4275&mode=crop&width=270&height=161", urlString); + } + + /// + /// Test to check if width ratio is returned for a predefined crop without coordinates and focal point in centre when a height parameter is passed + /// [Test] public void GetCropUrl_PreDefinedCropNoCoordinatesWithHeight() {