From 9b4c26bf7e8ab9c93f26167b72f330ac5770fadf Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 12 Nov 2019 13:40:07 +0100 Subject: [PATCH] AB3649 - Fixed tests --- .../Manifest/ManifestDashboard.cs | 6 +-- .../Manifest/DataEditorConverter.cs | 11 ++-- src/Umbraco.Core/Manifest/ManifestParser.cs | 13 +++-- .../PropertyEditors/DataEditor.cs | 2 +- .../PropertyEditors/DataValueEditor.cs | 22 +++----- .../PropertyEditors/LabelPropertyEditor.cs | 10 ++-- .../CoreThings/ObjectExtensionsTests.cs | 6 +-- .../Manifest/ManifestParserTests.cs | 2 +- .../Models/ContentExtensionsTests.cs | 2 +- src/Umbraco.Tests/Models/ContentTests.cs | 4 +- .../Mapping/ContentTypeModelMappingTests.cs | 3 +- .../Mapping/ContentWebModelMappingTests.cs | 2 +- src/Umbraco.Tests/Models/MediaXmlTest.cs | 4 +- src/Umbraco.Tests/Models/VariationTests.cs | 2 +- .../PropertyEditors/ImageCropperTest.cs | 2 +- .../MultiValuePropertyEditorTests.cs | 4 +- .../PropertyEditorValueEditorTests.cs | 50 ++++--------------- .../Published/NestedContentTests.cs | 6 ++- .../PublishedContentTestBase.cs | 8 ++- .../PublishedContent/PublishedContentTests.cs | 5 +- .../PropertyValidationServiceTests.cs | 4 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 16 ++++++ .../CheckBoxListPropertyEditor.cs | 8 ++- .../PropertyEditors/DateValueEditor.cs | 4 +- .../DropDownFlexiblePropertyEditor.cs | 8 ++- .../FileUploadPropertyEditor.cs | 9 +++- .../FileUploadPropertyValueEditor.cs | 7 +-- .../PropertyEditors/GridPropertyEditor.cs | 12 +++-- .../ImageCropperPropertyEditor.cs | 6 ++- .../ImageCropperPropertyValueEditor.cs | 4 +- .../MultiUrlPickerPropertyEditor.cs | 8 ++- .../MultiUrlPickerValueEditor.cs | 2 +- .../MultipleTextStringPropertyEditor.cs | 7 +-- .../PropertyEditors/MultipleValueEditor.cs | 4 +- .../NestedContentPropertyEditor.cs | 12 +++-- .../PropertyEditors/RichTextPropertyEditor.cs | 18 +++++-- .../PropertyEditors/TagsPropertyEditor.cs | 8 +-- .../PropertyEditors/TextAreaPropertyEditor.cs | 13 +++-- .../PropertyEditors/TextOnlyValueEditor.cs | 4 +- .../PropertyEditors/TextboxPropertyEditor.cs | 13 +++-- 40 files changed, 191 insertions(+), 140 deletions(-) diff --git a/src/Umbraco.Abstractions/Manifest/ManifestDashboard.cs b/src/Umbraco.Abstractions/Manifest/ManifestDashboard.cs index 2368f07a0b..2d6f96b5c2 100644 --- a/src/Umbraco.Abstractions/Manifest/ManifestDashboard.cs +++ b/src/Umbraco.Abstractions/Manifest/ManifestDashboard.cs @@ -11,10 +11,8 @@ namespace Umbraco.Core.Manifest [DataMember(Name = "alias", IsRequired = true)] public string Alias { get; set; } - //TODO this needs to be tested manually! - //[JsonProperty("weight", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] - [DefaultValue(100)] // must be equal to DashboardCollectionBuilder.DefaultWeight - public int Weight { get; set; } + [DataMember(Name = "weight")] + public int Weight { get; set; } = 100; [DataMember(Name = "view", IsRequired = true)] public string View { get; set; } diff --git a/src/Umbraco.Core/Manifest/DataEditorConverter.cs b/src/Umbraco.Core/Manifest/DataEditorConverter.cs index 86347d3894..437d1eb159 100644 --- a/src/Umbraco.Core/Manifest/DataEditorConverter.cs +++ b/src/Umbraco.Core/Manifest/DataEditorConverter.cs @@ -6,6 +6,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Serialization; +using Umbraco.Core.Services; namespace Umbraco.Core.Manifest { @@ -16,14 +17,18 @@ namespace Umbraco.Core.Manifest { private readonly ILogger _logger; private readonly IIOHelper _ioHelper; + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; /// /// Initializes a new instance of the class. /// - public DataEditorConverter(ILogger logger, IIOHelper ioHelper) + public DataEditorConverter(ILogger logger, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizationService localizationService) { _logger = logger; _ioHelper = ioHelper; + _dataTypeService = dataTypeService; + _localizationService = localizationService; } /// @@ -78,7 +83,7 @@ namespace Umbraco.Core.Manifest // explicitly assign a value editor of type ValueEditor // (else the deserializer will try to read it before setting it) // (and besides it's an interface) - target.ExplicitValueEditor = new DataValueEditor(); + target.ExplicitValueEditor = new DataValueEditor(_dataTypeService, _localizationService); // in the manifest, validators are a simple dictionary eg // { @@ -150,7 +155,7 @@ namespace Umbraco.Core.Manifest if (jobject.Property("view") != null) { // explicitly assign a value editor of type ParameterValueEditor - target.ExplicitValueEditor = new DataValueEditor(); + target.ExplicitValueEditor = new DataValueEditor(_dataTypeService, _localizationService); // move the 'view' property jobject["editor"] = new JObject { ["view"] = jobject["view"] }; diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index 6b370d2641..75fdde487c 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -10,6 +10,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Serialization; +using Umbraco.Core.Services; namespace Umbraco.Core.Manifest { @@ -24,6 +25,8 @@ namespace Umbraco.Core.Manifest private readonly IAppPolicyCache _cache; private readonly ILogger _logger; private readonly IIOHelper _ioHelper; + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; private readonly ManifestValueValidatorCollection _validators; private readonly ManifestFilterCollection _filters; @@ -32,8 +35,8 @@ namespace Umbraco.Core.Manifest /// /// Initializes a new instance of the class. /// - public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger, IIOHelper ioHelper, IJsonSerializer jsonSerializer) - : this(appCaches, validators, filters, "~/App_Plugins", logger, ioHelper) + public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizationService localizationService, IJsonSerializer jsonSerializer) + : this(appCaches, validators, filters, "~/App_Plugins", logger, ioHelper, dataTypeService, localizationService) { _jsonSerializer = jsonSerializer; } @@ -41,11 +44,13 @@ namespace Umbraco.Core.Manifest /// /// Initializes a new instance of the class. /// - private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger, IIOHelper ioHelper) + private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizationService localizationService) { if (appCaches == null) throw new ArgumentNullException(nameof(appCaches)); _cache = appCaches.RuntimeCache; _ioHelper = ioHelper; + _dataTypeService = dataTypeService; + _localizationService = localizationService; _validators = validators ?? throw new ArgumentNullException(nameof(validators)); _filters = filters ?? throw new ArgumentNullException(nameof(filters)); if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullOrEmptyException(nameof(path)); @@ -167,7 +172,7 @@ namespace Umbraco.Core.Manifest throw new ArgumentNullOrEmptyException(nameof(text)); var manifest = JsonConvert.DeserializeObject(text, - new DataEditorConverter(_logger, _ioHelper), + new DataEditorConverter(_logger, _ioHelper, _dataTypeService, _localizationService), new ValueValidatorConverter(_validators), new DashboardAccessRuleConverter()); diff --git a/src/Umbraco.Core/PropertyEditors/DataEditor.cs b/src/Umbraco.Core/PropertyEditors/DataEditor.cs index dbb2fc467e..047c0f0683 100644 --- a/src/Umbraco.Core/PropertyEditors/DataEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataEditor.cs @@ -165,7 +165,7 @@ namespace Umbraco.Core.PropertyEditors if (Attribute == null) throw new InvalidOperationException("The editor does not specify a view."); - return new DataValueEditor(Attribute); + return new DataValueEditor(Current.Services.DataTypeService, Current.Services.LocalizationService, Attribute); } /// diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index 3dde5a8949..d93ead5838 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -27,31 +27,18 @@ namespace Umbraco.Core.PropertyEditors /// /// Initializes a new instance of the class. /// - public DataValueEditor() // for tests, and manifest + public DataValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService) // for tests, and manifest { ValueType = ValueTypes.String; Validators = new List(); - _dataTypeService = Current.Services.DataTypeService; - _localizationService = Current.Services.LocalizationService; - } - - /// - /// Initializes a new instance of the class. - /// - public DataValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, string view, params IValueValidator[] validators) // not used - : this() - { _dataTypeService = dataTypeService; _localizationService = localizationService; - View = view; - Validators.AddRange(validators); } /// /// Initializes a new instance of the class. /// - public DataValueEditor(DataEditorAttribute attribute) - : this() + public DataValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute) { if (attribute == null) throw new ArgumentNullException(nameof(attribute)); @@ -62,6 +49,9 @@ namespace Umbraco.Core.PropertyEditors View = view; ValueType = attribute.ValueType; HideLabel = attribute.HideLabel; + + _dataTypeService = dataTypeService; + _localizationService = localizationService; } /// @@ -116,7 +106,7 @@ namespace Umbraco.Core.PropertyEditors /// A collection of validators for the pre value editor /// [JsonProperty("validation")] - public List Validators { get; private set; } + public List Validators { get; private set; } = new List(); /// /// Gets the validator used to validate the special property type -level "required". diff --git a/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs index 60b7d55c01..e47d35107a 100644 --- a/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs @@ -1,4 +1,6 @@ -using Umbraco.Core.Logging; +using Umbraco.Core.Composing; +using Umbraco.Core.Logging; +using Umbraco.Core.Services; namespace Umbraco.Core.PropertyEditors { @@ -20,7 +22,7 @@ namespace Umbraco.Core.PropertyEditors { } /// - protected override IDataValueEditor CreateValueEditor() => new LabelPropertyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new LabelPropertyValueEditor(Current.Services.DataTypeService, Current.Services.LocalizationService, Attribute); /// protected override IConfigurationEditor CreateConfigurationEditor() => new LabelConfigurationEditor(); @@ -28,8 +30,8 @@ namespace Umbraco.Core.PropertyEditors // provides the property value editor internal class LabelPropertyValueEditor : DataValueEditor { - public LabelPropertyValueEditor(DataEditorAttribute attribute) - : base(attribute) + public LabelPropertyValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute) + : base(dataTypeService, localizationService, attribute) { } /// diff --git a/src/Umbraco.Tests/CoreThings/ObjectExtensionsTests.cs b/src/Umbraco.Tests/CoreThings/ObjectExtensionsTests.cs index 486d35540c..544c6335e1 100644 --- a/src/Umbraco.Tests/CoreThings/ObjectExtensionsTests.cs +++ b/src/Umbraco.Tests/CoreThings/ObjectExtensionsTests.cs @@ -7,6 +7,7 @@ using System.Web.UI.WebControls; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.PropertyEditors; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.CoreThings { @@ -300,10 +301,7 @@ namespace Umbraco.Tests.CoreThings [Test] public void Value_Editor_Can_Convert_Decimal_To_Decimal_Clr_Type() { - var valueEditor = new DataValueEditor - { - ValueType = ValueTypes.Decimal - }; + var valueEditor = TestHelper.CreateDataValueEditor(ValueTypes.Decimal); var result = valueEditor.TryConvertValueToCrlType(12.34d); Assert.IsTrue(result.Success); diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs index fcc7ccd79b..936138155e 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs @@ -45,7 +45,7 @@ namespace Umbraco.Tests.Manifest new RequiredValidator(Mock.Of()), new RegexValidator(Mock.Of(), null) }; - _parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty()), Mock.Of(), Current.IOHelper, new JsonNetSerializer()); + _parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty()), Mock.Of(), Current.IOHelper, Mock.Of(), Mock.Of(), new JsonNetSerializer()); } [Test] diff --git a/src/Umbraco.Tests/Models/ContentExtensionsTests.cs b/src/Umbraco.Tests/Models/ContentExtensionsTests.cs index 42d7f0e01b..52cf5ddef5 100644 --- a/src/Umbraco.Tests/Models/ContentExtensionsTests.cs +++ b/src/Umbraco.Tests/Models/ContentExtensionsTests.cs @@ -32,7 +32,7 @@ namespace Umbraco.Tests.Models Composition.Register(_ => Mock.Of()); // all this is required so we can validate properties... - var editor = new TextboxPropertyEditor(Mock.Of()) { Alias = "test" }; + var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of()) { Alias = "test" }; Composition.Register(_ => new DataEditorCollection(new[] { editor })); Composition.Register(); var dataType = Mock.Of(); diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs index ffbf462b8e..ee6649dd2b 100644 --- a/src/Umbraco.Tests/Models/ContentTests.cs +++ b/src/Umbraco.Tests/Models/ContentTests.cs @@ -43,7 +43,7 @@ namespace Umbraco.Tests.Models Composition.Register(_ => Mock.Of()); // all this is required so we can validate properties... - var editor = new TextboxPropertyEditor(Mock.Of()) { Alias = "test" }; + var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of()) { Alias = "test" }; Composition.Register(_ => new DataEditorCollection(new [] { editor })); Composition.Register(); var dataType = Mock.Of(); @@ -57,7 +57,7 @@ namespace Umbraco.Tests.Models var mediaTypeService = Mock.Of(); var memberTypeService = Mock.Of(); Composition.Register(_ => ServiceContext.CreatePartial(dataTypeService: dataTypeService, contentTypeBaseServiceProvider: new ContentTypeBaseServiceProvider(_contentTypeService, mediaTypeService, memberTypeService))); - + } [Test] diff --git a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs index 21180ce51b..968e51ab97 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs @@ -24,6 +24,7 @@ namespace Umbraco.Tests.Models.Mapping private readonly Mock _dataTypeService = new Mock(); private readonly Mock _entityService = new Mock(); private readonly Mock _fileService = new Mock(); + private readonly Mock _localizationService = new Mock(); private Mock _editorsMock; protected override void Compose() @@ -31,7 +32,7 @@ namespace Umbraco.Tests.Models.Mapping base.Compose(); // create and register a fake property editor collection to return fake property editors - var editors = new DataEditor[] { new TextboxPropertyEditor(Mock.Of()), }; + var editors = new DataEditor[] { new TextboxPropertyEditor(Mock.Of(), _dataTypeService.Object, _localizationService.Object), }; var dataEditors = new DataEditorCollection(editors); _editorsMock = new Mock(dataEditors); _editorsMock.Setup(x => x[It.IsAny()]).Returns(editors[0]); diff --git a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs index 996f02e16a..9a47ad1b4a 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs @@ -40,7 +40,7 @@ namespace Umbraco.Tests.Models.Mapping Composition.Register(_ => Mock.Of()); // all this is required so we can validate properties... - var editor = new TextboxPropertyEditor(Mock.Of()) { Alias = "test" }; + var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of()) { Alias = "test" }; Composition.Register(_ => new DataEditorCollection(new[] { editor })); Composition.Register(); var dataType = Mock.Of(); diff --git a/src/Umbraco.Tests/Models/MediaXmlTest.cs b/src/Umbraco.Tests/Models/MediaXmlTest.cs index 3ae9414dc1..4b4b333e74 100644 --- a/src/Umbraco.Tests/Models/MediaXmlTest.cs +++ b/src/Umbraco.Tests/Models/MediaXmlTest.cs @@ -33,9 +33,11 @@ namespace Umbraco.Tests.Models var logger = Mock.Of(); var scheme = Mock.Of(); var config = Mock.Of(); + var dataTypeService = Mock.Of(); + var localizationService = Mock.Of(); var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger); - var ignored = new FileUploadPropertyEditor(Mock.Of(), mediaFileSystem, config); + var ignored = new FileUploadPropertyEditor(Mock.Of(), mediaFileSystem, config, dataTypeService, localizationService); var media = MockedMedia.CreateMediaImage(mediaType, -1); media.WriterId = -1; // else it's zero and that's not a user and it breaks the tests diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs index 28663a9dbe..c7ebb9ef71 100644 --- a/src/Umbraco.Tests/Models/VariationTests.cs +++ b/src/Umbraco.Tests/Models/VariationTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.Models var dataEditors = new DataEditorCollection(new IDataEditor[] { - new DataEditor(Mock.Of()) { Alias = "editor", ExplicitValueEditor = new DataValueEditor(dataTypeService, localizationService, "view") } + new DataEditor(Mock.Of()) { Alias = "editor", ExplicitValueEditor = TestHelper.CreateDataValueEditor("view") } }); var propertyEditors = new PropertyEditorCollection(dataEditors); diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs index 5bea491973..885aaeefb9 100644 --- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs @@ -83,7 +83,7 @@ namespace Umbraco.Tests.PropertyEditors var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger); var dataTypeService = new TestObjects.TestDataTypeService( - new DataType(new ImageCropperPropertyEditor(Mock.Of(), mediaFileSystem, Mock.Of(), Mock.Of())) { Id = 1 }); + new DataType(new ImageCropperPropertyEditor(Mock.Of(), mediaFileSystem, Mock.Of(), Mock.Of(), Mock.Of())) { Id = 1 }); var factory = new PublishedContentTypeFactory(Mock.Of(), new PropertyValueConverterCollection(Array.Empty()), dataTypeService); diff --git a/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs index 7f708b6c53..5579395b7e 100644 --- a/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void DropDownMultipleValueEditor_Format_Data_For_Cache() { - var dataType = new DataType(new CheckBoxListPropertyEditor(Mock.Of(), Mock.Of())) + var dataType = new DataType(new CheckBoxListPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of())) { Configuration = new ValueListConfiguration { @@ -59,7 +59,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void DropDownValueEditor_Format_Data_For_Cache() { - var dataType = new DataType(new CheckBoxListPropertyEditor(Mock.Of(), Mock.Of())) + var dataType = new DataType(new CheckBoxListPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of())) { Configuration = new ValueListConfiguration { diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index 06944c14a7..bb1b0e4b10 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -47,10 +47,7 @@ namespace Umbraco.Tests.PropertyEditors var prop = new Property(1, new PropertyType("test", ValueStorageType.Nvarchar)); prop.SetValue(value); - var valueEditor = new DataValueEditor - { - ValueType = ValueTypes.String - }; + var valueEditor = TestHelper.CreateDataValueEditor(ValueTypes.String); var result = valueEditor.ToEditor(prop); Assert.AreEqual(isOk, !(result is string)); @@ -63,10 +60,7 @@ namespace Umbraco.Tests.PropertyEditors [TestCase("DATETIME", "", null)] //test empty string for date public void Value_Editor_Can_Convert_To_Clr_Type(string valueType, string val, object expected) { - var valueEditor = new DataValueEditor - { - ValueType = valueType - }; + var valueEditor = TestHelper.CreateDataValueEditor(valueType); var result = valueEditor.TryConvertValueToCrlType(val); Assert.IsTrue(result.Success); @@ -78,10 +72,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void Value_Editor_Can_Convert_To_Decimal_Clr_Type() { - var valueEditor = new DataValueEditor - { - ValueType = ValueTypes.Decimal - }; + var valueEditor = TestHelper.CreateDataValueEditor(ValueTypes.Decimal); var result = valueEditor.TryConvertValueToCrlType("12.34"); Assert.IsTrue(result.Success); @@ -91,10 +82,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void Value_Editor_Can_Convert_To_Decimal_Clr_Type_With_Other_Separator() { - var valueEditor = new DataValueEditor - { - ValueType = ValueTypes.Decimal - }; + var valueEditor = TestHelper.CreateDataValueEditor(ValueTypes.Decimal); var result = valueEditor.TryConvertValueToCrlType("12,34"); Assert.IsTrue(result.Success); @@ -104,10 +92,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void Value_Editor_Can_Convert_To_Decimal_Clr_Type_With_Empty_String() { - var valueEditor = new DataValueEditor - { - ValueType = ValueTypes.Decimal - }; + var valueEditor = TestHelper.CreateDataValueEditor(ValueTypes.Decimal); var result = valueEditor.TryConvertValueToCrlType(string.Empty); Assert.IsTrue(result.Success); @@ -117,10 +102,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void Value_Editor_Can_Convert_To_Date_Clr_Type() { - var valueEditor = new DataValueEditor - { - ValueType = ValueTypes.Date - }; + var valueEditor = TestHelper.CreateDataValueEditor(ValueTypes.Date); var result = valueEditor.TryConvertValueToCrlType("2010-02-05"); Assert.IsTrue(result.Success); @@ -137,10 +119,7 @@ namespace Umbraco.Tests.PropertyEditors var prop = new Property(1, new PropertyType("test", ValueStorageType.Nvarchar)); prop.SetValue(val); - var valueEditor = new DataValueEditor - { - ValueType = valueType - }; + var valueEditor = TestHelper.CreateDataValueEditor(valueType); var result = valueEditor.ToEditor(prop); Assert.AreEqual(expected, result); @@ -150,10 +129,7 @@ namespace Umbraco.Tests.PropertyEditors public void Value_Editor_Can_Serialize_Decimal_Value() { var value = 12.34M; - var valueEditor = new DataValueEditor - { - ValueType = ValueTypes.Decimal - }; + var valueEditor = TestHelper.CreateDataValueEditor(ValueTypes.Decimal); var prop = new Property(1, new PropertyType("test", ValueStorageType.Decimal)); prop.SetValue(value); @@ -165,10 +141,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void Value_Editor_Can_Serialize_Decimal_Value_With_Empty_String() { - var valueEditor = new DataValueEditor - { - ValueType = ValueTypes.Decimal - }; + var valueEditor = TestHelper.CreateDataValueEditor(ValueTypes.Decimal); var prop = new Property(1, new PropertyType("test", ValueStorageType.Decimal)); prop.SetValue(string.Empty); @@ -181,10 +154,7 @@ namespace Umbraco.Tests.PropertyEditors public void Value_Editor_Can_Serialize_Date_Value() { var now = DateTime.Now; - var valueEditor = new DataValueEditor - { - ValueType = ValueTypes.Date - }; + var valueEditor = TestHelper.CreateDataValueEditor(ValueTypes.Date); var prop = new Property(1, new PropertyType("test", ValueStorageType.Date)); prop.SetValue(now); diff --git a/src/Umbraco.Tests/Published/NestedContentTests.cs b/src/Umbraco.Tests/Published/NestedContentTests.cs index 9385b8955a..4d99aa86d8 100644 --- a/src/Umbraco.Tests/Published/NestedContentTests.cs +++ b/src/Umbraco.Tests/Published/NestedContentTests.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Services; using Umbraco.Tests.PublishedContent; using Umbraco.Tests.TestHelpers; using Umbraco.Web; @@ -31,9 +32,10 @@ namespace Umbraco.Tests.Published var logger = Mock.Of(); var profiler = Mock.Of(); var proflog = new ProfilingLogger(logger, profiler); + var localizationService = Mock.Of(); PropertyEditorCollection editors = null; - var editor = new NestedContentPropertyEditor(logger, new Lazy(() => editors)); + var editor = new NestedContentPropertyEditor(logger, new Lazy(() => editors), Mock.Of(), localizationService); editors = new PropertyEditorCollection(new DataEditorCollection(new DataEditor[] { editor })); var dataType1 = new DataType(editor) @@ -64,7 +66,7 @@ namespace Umbraco.Tests.Published } }; - var dataType3 = new DataType(new TextboxPropertyEditor(logger)) + var dataType3 = new DataType(new TextboxPropertyEditor(logger, Mock.Of(), localizationService)) { Id = 3 }; diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs index f1e2bf20d6..bf55f1783f 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs @@ -40,7 +40,13 @@ namespace Umbraco.Tests.PublishedContent var converters = Factory.GetInstance(); var dataTypeService = new TestObjects.TestDataTypeService( - new DataType(new RichTextPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of())) { Id = 1 }); + new DataType(new RichTextPropertyEditor( + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of())) { Id = 1 }); var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of(), converters, dataTypeService); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index b42dc32b24..7c70e82047 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -47,13 +47,14 @@ namespace Umbraco.Tests.PublishedContent var mediaService = Mock.Of(); var contentTypeBaseServiceProvider = Mock.Of(); var umbracoContextAccessor = Mock.Of(); + var localizationService = Mock.Of(); var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new VoidEditor(logger)) { Id = 1 }, new DataType(new TrueFalsePropertyEditor(logger)) { Id = 1001 }, - new DataType(new RichTextPropertyEditor(logger, mediaService, contentTypeBaseServiceProvider, umbracoContextAccessor)) { Id = 1002 }, + new DataType(new RichTextPropertyEditor(logger, mediaService, contentTypeBaseServiceProvider, umbracoContextAccessor, Mock.Of(), localizationService)) { Id = 1002 }, new DataType(new IntegerPropertyEditor(logger)) { Id = 1003 }, - new DataType(new TextboxPropertyEditor(logger)) { Id = 1004 }, + new DataType(new TextboxPropertyEditor(logger, Mock.Of(), localizationService)) { Id = 1004 }, new DataType(new MediaPickerPropertyEditor(logger)) { Id = 1005 }); Composition.RegisterUnique(f => dataTypeService); } diff --git a/src/Umbraco.Tests/Services/PropertyValidationServiceTests.cs b/src/Umbraco.Tests/Services/PropertyValidationServiceTests.cs index 425c03a9b4..746190d67f 100644 --- a/src/Umbraco.Tests/Services/PropertyValidationServiceTests.cs +++ b/src/Umbraco.Tests/Services/PropertyValidationServiceTests.cs @@ -32,7 +32,7 @@ namespace Umbraco.Tests.Services x => x.Type == EditorType.PropertyValue && x.Alias == Constants.PropertyEditors.Aliases.TextBox); Mock.Get(dataEditor).Setup(x => x.GetValueEditor(It.IsAny())) - .Returns(new CustomTextOnlyValueEditor(new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox, "Test Textbox", "textbox"), textService.Object)); + .Returns(new CustomTextOnlyValueEditor(Mock.Of(), Mock.Of(), new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox, "Test Textbox", "textbox"), textService.Object)); var propEditors = new PropertyEditorCollection(new DataEditorCollection(new[] { dataEditor })); @@ -164,7 +164,7 @@ namespace Umbraco.Tests.Services { private readonly ILocalizedTextService _textService; - public CustomTextOnlyValueEditor(DataEditorAttribute attribute, ILocalizedTextService textService) : base(attribute) + public CustomTextOnlyValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute, ILocalizedTextService textService) : base(dataTypeService, localizationService, attribute) { _textService = textService; } diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index e07dbe1e5a..039a5c9b07 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -17,6 +17,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Services; using File = System.IO.File; namespace Umbraco.Tests.TestHelpers @@ -247,5 +248,20 @@ namespace Umbraco.Tests.TestHelpers } } } + + public static DataValueEditor CreateDataValueEditor(string name) + { + var valueType = (ValueTypes.IsValue(name)) ? name : ValueTypes.String; + + return new DataValueEditor( + Mock.Of(), + Mock.Of(), + new DataEditorAttribute(name, name, name) + { + ValueType = valueType + } + + ); + } } } diff --git a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs index d81b63f2ad..f28acd5e90 100644 --- a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs @@ -17,20 +17,24 @@ namespace Umbraco.Web.PropertyEditors public class CheckBoxListPropertyEditor : DataEditor { private readonly ILocalizedTextService _textService; + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; /// /// The constructor will setup the property editor based on the attribute if one is found /// - public CheckBoxListPropertyEditor(ILogger logger, ILocalizedTextService textService) + public CheckBoxListPropertyEditor(ILogger logger, ILocalizedTextService textService, IDataTypeService dataTypeService, ILocalizationService localizationService) : base(logger) { _textService = textService; + _dataTypeService = dataTypeService; + _localizationService = localizationService; } /// protected override IConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService); /// - protected override IDataValueEditor CreateValueEditor() => new MultipleValueEditor(Logger, Attribute); + protected override IDataValueEditor CreateValueEditor() => new MultipleValueEditor(Logger, _dataTypeService, _localizationService, Attribute); } } diff --git a/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs b/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs index bc1c5dc5f8..b8dada173f 100644 --- a/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs @@ -12,8 +12,8 @@ namespace Umbraco.Web.PropertyEditors /// internal class DateValueEditor : DataValueEditor { - public DateValueEditor(DataEditorAttribute attribute) - : base(attribute) + public DateValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute) + : base(dataTypeService, localizationService, attribute) { Validators.Add(new DateTimeValidator()); } diff --git a/src/Umbraco.Web/PropertyEditors/DropDownFlexiblePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownFlexiblePropertyEditor.cs index 98a19f39ad..0b0a0f6d06 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownFlexiblePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownFlexiblePropertyEditor.cs @@ -14,16 +14,20 @@ namespace Umbraco.Web.PropertyEditors public class DropDownFlexiblePropertyEditor : DataEditor { private readonly ILocalizedTextService _textService; + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; - public DropDownFlexiblePropertyEditor(ILocalizedTextService textService, ILogger logger) + public DropDownFlexiblePropertyEditor(ILocalizedTextService textService, ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService) : base(logger) { _textService = textService; + _dataTypeService = dataTypeService; + _localizationService = localizationService; } protected override IDataValueEditor CreateValueEditor() { - return new MultipleValueEditor(Logger, Attribute); + return new MultipleValueEditor(Logger, _dataTypeService, _localizationService, Attribute); } protected override IConfigurationEditor CreateConfigurationEditor() => new DropDownFlexibleConfigurationEditor(_textService); diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs index 849ad443c8..366f3938a6 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs @@ -8,6 +8,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; +using Umbraco.Core.Services.Implement; using Umbraco.Web.Media; namespace Umbraco.Web.PropertyEditors @@ -23,12 +24,16 @@ namespace Umbraco.Web.PropertyEditors private readonly IMediaFileSystem _mediaFileSystem; private readonly IContentSection _contentSection; private readonly UploadAutoFillProperties _uploadAutoFillProperties; + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; - public FileUploadPropertyEditor(ILogger logger, IMediaFileSystem mediaFileSystem, IContentSection contentSection) + public FileUploadPropertyEditor(ILogger logger, IMediaFileSystem mediaFileSystem, IContentSection contentSection, IDataTypeService dataTypeService, ILocalizationService localizationService) : base(logger) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); _contentSection = contentSection; + _dataTypeService = dataTypeService; + _localizationService = localizationService; _uploadAutoFillProperties = new UploadAutoFillProperties(_mediaFileSystem, logger, contentSection); } @@ -38,7 +43,7 @@ namespace Umbraco.Web.PropertyEditors /// The corresponding property value editor. protected override IDataValueEditor CreateValueEditor() { - var editor = new FileUploadPropertyValueEditor(Attribute, _mediaFileSystem); + var editor = new FileUploadPropertyValueEditor(Attribute, _mediaFileSystem, _dataTypeService, _localizationService); editor.Validators.Add(new UploadFileTypeValidator()); return editor; } diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs index 942f53b561..172d8070af 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs @@ -7,6 +7,7 @@ using Umbraco.Core; using Umbraco.Core.IO; using Umbraco.Core.Models.Editors; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { @@ -17,8 +18,8 @@ namespace Umbraco.Web.PropertyEditors { private readonly IMediaFileSystem _mediaFileSystem; - public FileUploadPropertyValueEditor(DataEditorAttribute attribute, IMediaFileSystem mediaFileSystem) - : base(attribute) + public FileUploadPropertyValueEditor(DataEditorAttribute attribute, IMediaFileSystem mediaFileSystem, IDataTypeService dataTypeService, ILocalizationService localizationService) + : base(dataTypeService, localizationService, attribute) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); } @@ -92,7 +93,7 @@ namespace Umbraco.Web.PropertyEditors if (editorFile == null) return null; return filepath == null ? string.Empty : _mediaFileSystem.GetUrl(filepath); - + } private string ProcessFile(ContentPropertyData editorValue, ContentPropertyFile file, string currentPath, Guid cuid, Guid puid) diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index bae06e09c2..6f6f1d911d 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -28,14 +28,18 @@ namespace Umbraco.Web.PropertyEditors private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; private IUmbracoContextAccessor _umbracoContextAccessor; + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; private ILogger _logger; - public GridPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor) + public GridPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, IDataTypeService dataTypeService, ILocalizationService localizationService) : base(logger) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; _umbracoContextAccessor = umbracoContextAccessor; + _dataTypeService = dataTypeService; + _localizationService = localizationService; _logger = logger; } @@ -45,7 +49,7 @@ namespace Umbraco.Web.PropertyEditors /// Overridden to ensure that the value is validated /// /// - protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor, _logger); + protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor, _logger, _dataTypeService, _localizationService); protected override IConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(); @@ -56,8 +60,8 @@ namespace Umbraco.Web.PropertyEditors private IUmbracoContextAccessor _umbracoContextAccessor; private ILogger _logger; - public GridPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, ILogger logger) - : base(attribute) + public GridPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService) + : base(dataTypeService, localizationService, attribute) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs index d120210411..fe1f026417 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs @@ -32,17 +32,19 @@ namespace Umbraco.Web.PropertyEditors private readonly IMediaFileSystem _mediaFileSystem; private readonly IContentSection _contentSettings; private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; private readonly UploadAutoFillProperties _autoFillProperties; /// /// Initializes a new instance of the class. /// - public ImageCropperPropertyEditor(ILogger logger, IMediaFileSystem mediaFileSystem, IContentSection contentSettings, IDataTypeService dataTypeService) + public ImageCropperPropertyEditor(ILogger logger, IMediaFileSystem mediaFileSystem, IContentSection contentSettings, IDataTypeService dataTypeService, ILocalizationService localizationService) : base(logger) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); _dataTypeService = dataTypeService; + _localizationService = localizationService; // TODO: inject? _autoFillProperties = new UploadAutoFillProperties(_mediaFileSystem, logger, _contentSettings); @@ -52,7 +54,7 @@ namespace Umbraco.Web.PropertyEditors /// Creates the corresponding property value editor. /// /// The corresponding property value editor. - protected override IDataValueEditor CreateValueEditor() => new ImageCropperPropertyValueEditor(Attribute, Logger, _mediaFileSystem); + protected override IDataValueEditor CreateValueEditor() => new ImageCropperPropertyValueEditor(Attribute, Logger, _mediaFileSystem, _dataTypeService, _localizationService); /// /// Creates the corresponding preValue editor. diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs index c9ce5a9d9d..99e2f8c727 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs @@ -21,8 +21,8 @@ namespace Umbraco.Web.PropertyEditors private readonly ILogger _logger; private readonly IMediaFileSystem _mediaFileSystem; - public ImageCropperPropertyValueEditor(DataEditorAttribute attribute, ILogger logger, IMediaFileSystem mediaFileSystem) - : base(attribute) + public ImageCropperPropertyValueEditor(DataEditorAttribute attribute, ILogger logger, IMediaFileSystem mediaFileSystem, IDataTypeService dataTypeService, ILocalizationService localizationService) + : base(dataTypeService, localizationService, attribute) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); diff --git a/src/Umbraco.Web/PropertyEditors/MultiUrlPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiUrlPickerPropertyEditor.cs index 95ac809576..a5da833501 100644 --- a/src/Umbraco.Web/PropertyEditors/MultiUrlPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultiUrlPickerPropertyEditor.cs @@ -19,15 +19,19 @@ namespace Umbraco.Web.PropertyEditors { private readonly IEntityService _entityService; private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor; + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; - public MultiUrlPickerPropertyEditor(ILogger logger, IEntityService entityService, IPublishedSnapshotAccessor publishedSnapshotAccessor) : base(logger, EditorType.PropertyValue) + public MultiUrlPickerPropertyEditor(ILogger logger, IEntityService entityService, IPublishedSnapshotAccessor publishedSnapshotAccessor, IDataTypeService dataTypeService, ILocalizationService localizationService) : base(logger, EditorType.PropertyValue) { _entityService = entityService ?? throw new ArgumentNullException(nameof(entityService)); _publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor)); + _dataTypeService = dataTypeService; + _localizationService = localizationService; } protected override IConfigurationEditor CreateConfigurationEditor() => new MultiUrlPickerConfigurationEditor(); - protected override IDataValueEditor CreateValueEditor() => new MultiUrlPickerValueEditor(_entityService, _publishedSnapshotAccessor, Logger, Attribute); + protected override IDataValueEditor CreateValueEditor() => new MultiUrlPickerValueEditor(_entityService, _publishedSnapshotAccessor, Logger, _dataTypeService, _localizationService, Attribute); } } diff --git a/src/Umbraco.Web/PropertyEditors/MultiUrlPickerValueEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiUrlPickerValueEditor.cs index 36d40cceb8..97d787dbba 100644 --- a/src/Umbraco.Web/PropertyEditors/MultiUrlPickerValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultiUrlPickerValueEditor.cs @@ -21,7 +21,7 @@ namespace Umbraco.Web.PropertyEditors private readonly ILogger _logger; private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor; - public MultiUrlPickerValueEditor(IEntityService entityService, IPublishedSnapshotAccessor publishedSnapshotAccessor, ILogger logger, DataEditorAttribute attribute) : base(attribute) + public MultiUrlPickerValueEditor(IEntityService entityService, IPublishedSnapshotAccessor publishedSnapshotAccessor, ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute) : base(dataTypeService, localizationService, attribute) { _entityService = entityService ?? throw new ArgumentNullException(nameof(entityService)); _publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor)); diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs index 279bc3618a..29ec8530d9 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs @@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.Composing; using Umbraco.Core.Exceptions; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -34,7 +35,7 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override IDataValueEditor CreateValueEditor() => new MultipleTextStringPropertyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new MultipleTextStringPropertyValueEditor(Current.Services.DataTypeService, Current.Services.LocalizationService,Attribute); /// protected override IConfigurationEditor CreateConfigurationEditor() => new MultipleTextStringConfigurationEditor(); @@ -44,8 +45,8 @@ namespace Umbraco.Web.PropertyEditors /// internal class MultipleTextStringPropertyValueEditor : DataValueEditor { - public MultipleTextStringPropertyValueEditor(DataEditorAttribute attribute) - : base(attribute) + public MultipleTextStringPropertyValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute) + : base(dataTypeService, localizationService, attribute) { } /// diff --git a/src/Umbraco.Web/PropertyEditors/MultipleValueEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleValueEditor.cs index b46de6d092..f5ca6c5cfe 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleValueEditor.cs @@ -19,8 +19,8 @@ namespace Umbraco.Web.PropertyEditors { private readonly ILogger _logger; - internal MultipleValueEditor(ILogger logger, DataEditorAttribute attribute) - : base(attribute) + internal MultipleValueEditor(ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute) + : base(dataTypeService, localizationService, attribute) { _logger = logger; } diff --git a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs index 8784a9bb49..3c9dc53de7 100644 --- a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs @@ -28,13 +28,17 @@ namespace Umbraco.Web.PropertyEditors public class NestedContentPropertyEditor : DataEditor { private readonly Lazy _propertyEditors; + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; internal const string ContentTypeAliasPropertyKey = "ncContentTypeAlias"; - public NestedContentPropertyEditor(ILogger logger, Lazy propertyEditors) + public NestedContentPropertyEditor(ILogger logger, Lazy propertyEditors, IDataTypeService dataTypeService, ILocalizationService localizationService) : base (logger) { _propertyEditors = propertyEditors; + _dataTypeService = dataTypeService; + _localizationService = localizationService; } // has to be lazy else circular dep in ctor @@ -48,7 +52,7 @@ namespace Umbraco.Web.PropertyEditors #region Value Editor - protected override IDataValueEditor CreateValueEditor() => new NestedContentPropertyValueEditor(Attribute, PropertyEditors); + protected override IDataValueEditor CreateValueEditor() => new NestedContentPropertyValueEditor(_dataTypeService, _localizationService, Attribute, PropertyEditors); internal class NestedContentPropertyValueEditor : DataValueEditor { @@ -58,8 +62,8 @@ namespace Umbraco.Web.PropertyEditors Current.Services.ContentTypeService.GetAll().ToDictionary(c => c.Alias) ); - public NestedContentPropertyValueEditor(DataEditorAttribute attribute, PropertyEditorCollection propertyEditors) - : base(attribute) + public NestedContentPropertyValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute, PropertyEditorCollection propertyEditors) + : base(dataTypeService, localizationService, attribute) { _propertyEditors = propertyEditors; Validators.Add(new NestedContentValidator(propertyEditors, GetElementType)); diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index 6932504f06..aa6876df39 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -27,16 +27,26 @@ namespace Umbraco.Web.PropertyEditors private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; private IUmbracoContextAccessor _umbracoContextAccessor; + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; private ILogger _logger; /// /// The constructor will setup the property editor based on the attribute if one is found /// - public RichTextPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor) : base(logger) + public RichTextPropertyEditor( + ILogger logger, + IMediaService mediaService, + IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, + IUmbracoContextAccessor umbracoContextAccessor, + IDataTypeService dataTypeService, + ILocalizationService localizationService) : base(logger) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; _umbracoContextAccessor = umbracoContextAccessor; + _dataTypeService = dataTypeService; + _localizationService = localizationService; _logger = logger; } @@ -44,7 +54,7 @@ namespace Umbraco.Web.PropertyEditors /// Create a custom value editor /// /// - protected override IDataValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor, _logger); + protected override IDataValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor, _logger, _dataTypeService, _localizationService); protected override IConfigurationEditor CreateConfigurationEditor() => new RichTextConfigurationEditor(); @@ -60,8 +70,8 @@ namespace Umbraco.Web.PropertyEditors private IUmbracoContextAccessor _umbracoContextAccessor; private ILogger _logger; - public RichTextPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, ILogger logger) - : base(attribute) + public RichTextPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService) + : base(dataTypeService, localizationService, attribute) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; diff --git a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs index fd7e8694a3..74338ba3fa 100644 --- a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs @@ -4,10 +4,12 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.Composing; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Editors; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { @@ -30,14 +32,14 @@ namespace Umbraco.Web.PropertyEditors _validators = validators; } - protected override IDataValueEditor CreateValueEditor() => new TagPropertyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new TagPropertyValueEditor(Current.Services.DataTypeService, Current.Services.LocalizationService, Attribute); protected override IConfigurationEditor CreateConfigurationEditor() => new TagConfigurationEditor(_validators); internal class TagPropertyValueEditor : DataValueEditor { - public TagPropertyValueEditor(DataEditorAttribute attribute) - : base(attribute) + public TagPropertyValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute) + : base(dataTypeService, localizationService, attribute) { } /// diff --git a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs index c7bc2efbda..28698e2c5c 100644 --- a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs @@ -1,6 +1,7 @@ using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { @@ -16,15 +17,21 @@ namespace Umbraco.Web.PropertyEditors Icon = "icon-application-window-alt")] public class TextAreaPropertyEditor : DataEditor { + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; + /// /// Initializes a new instance of the class. /// - public TextAreaPropertyEditor(ILogger logger) + public TextAreaPropertyEditor(ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService) : base(logger) - { } + { + _dataTypeService = dataTypeService; + _localizationService = localizationService; + } /// - protected override IDataValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new TextOnlyValueEditor(_dataTypeService, _localizationService, Attribute); /// protected override IConfigurationEditor CreateConfigurationEditor() => new TextAreaConfigurationEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs index 826051a79b..782e19e42d 100644 --- a/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs @@ -11,8 +11,8 @@ namespace Umbraco.Web.PropertyEditors /// public class TextOnlyValueEditor : DataValueEditor { - public TextOnlyValueEditor(DataEditorAttribute attribute) - : base(attribute) + public TextOnlyValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute) + : base(dataTypeService, localizationService, attribute) { } /// diff --git a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs index 18f8155198..c7c13b4caf 100644 --- a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs @@ -1,6 +1,7 @@ using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { @@ -15,15 +16,21 @@ namespace Umbraco.Web.PropertyEditors Group = Constants.PropertyEditors.Groups.Common)] public class TextboxPropertyEditor : DataEditor { + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; + /// /// Initializes a new instance of the class. /// - public TextboxPropertyEditor(ILogger logger) + public TextboxPropertyEditor(ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService) : base(logger) - { } + { + _dataTypeService = dataTypeService; + _localizationService = localizationService; + } /// - protected override IDataValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new TextOnlyValueEditor(_dataTypeService, _localizationService, Attribute); /// protected override IConfigurationEditor CreateConfigurationEditor() => new TextboxConfigurationEditor();