public void When_Value_Is_Set_GetRelatedEntities_Return_List_With_Related_Entities() { // arrange var rteValue = @"<p>Hier komt de tekst voor de contact pagina</p> <p>Hier kunnen links in gezet <a data-udi=""umb://document/ca4249ed2b234337b52263cabe5587d1"" href=""/{localLink:umb://document/ca4249ed2b234337b52263cabe5587d1}"" title=""Home"">worden </a></p> <p>En afbeeldingen geplaats</p> <p><img style=""width: 500px; height:333.4375px;"" src=""/media/34371d0892c84015912ebaacd002c5d0/00000006000000000000000000000000/18530280048_459b8b61b2_h.jpg?width=500&height=333.4375"" alt="""" data-udi=""umb://media/34371d0892c84015912ebaacd002c5d0"" /></p> <p> </p> <p>Maar we kunnen ook bestanden <a data-udi=""umb://media/a7e62beab9834049aaf765f5f95f2263"" href=""/media/bxlfm1pv/715010_lr.pdf"" title=""715010 LR"">opladen</a></p>"; var parser = new RichTextEditorParser(); // act var result = parser.GetRelatedEntities(rteValue).ToList(); // assert Assert.IsNotNull(result); Assert.AreEqual(3, result.Count); Assert.AreEqual(1, result.Count(x => x.RelationType == RelationTypes.DocumentToDocument)); Assert.AreEqual(2, result.Count(x => x.RelationType == RelationTypes.DocumentToMedia)); Assert.IsTrue(result.Exists(x => x.RelatedEntityUdi.ToString() == "umb://document/ca4249ed2b234337b52263cabe5587d1" && x.RelationType == RelationTypes.DocumentToDocument)); Assert.IsTrue(result.Exists(x => x.RelatedEntityUdi.ToString() == "umb://media/a7e62beab9834049aaf765f5f95f2263" && x.RelationType == RelationTypes.DocumentToMedia)); Assert.IsTrue(result.Exists(x => x.RelatedEntityUdi.ToString() == "umb://media/34371d0892c84015912ebaacd002c5d0" && x.RelationType == RelationTypes.DocumentToMedia)); }
public void When_EditorAlias_Is_Not_Correct_IsParserFor_Should_Return_False() { // arrange var parser = new RichTextEditorParser(); // act var result = parser.IsParserFor(Constants.PropertyEditors.Aliases.Boolean); // assert Assert.IsFalse(result); }
public void When_EditorAlias_Is_Correct_IsParserFor_Should_Return_True() { // arrange var parser = new RichTextEditorParser(); // act var result = parser.IsParserFor(Constants.PropertyEditors.Aliases.TinyMce); // assert Assert.IsTrue(result); }
public void When_Value_Is_Not_Set_GetRelatedEntities_Return_Empty_List() { // arrange var parser = new RichTextEditorParser(); // act var result = parser.GetRelatedEntities(null); // assert Assert.IsNotNull(result); Assert.AreEqual(0, result.Count()); }
public void TestIsParserForInValidDataType() { // arrange var dataTypeDefinition = new DataTypeDefinition("foo"); var parser = new RichTextEditorParser(); // act var result = parser.IsParserFor(dataTypeDefinition); // verify Assert.IsFalse(result); }
public void TestIsParserForValidDataType() { // arrange var dataTypeDefinition = new DataTypeDefinition(global::Umbraco.Core.Constants.PropertyEditors.TinyMCEAlias); var parser = new RichTextEditorParser(); // act var result = parser.IsParserFor(dataTypeDefinition); // verify Assert.IsTrue(result); }
public void TestGetLinkedEntitiesWithValue() { // arrange var parser = new RichTextEditorParser(); var propertyType = new PropertyType( global::Umbraco.Core.Constants.PropertyEditors.TinyMCEAlias, DataTypeDatabaseType.Ntext, "cp1"); var html = @"<p>This content linking to <a data-id=""1069"" href=""/{localLink:1069}"" title=""Our Umbraco"">Our Umbraco</a> and <a data-id=""1070"" href=""/{localLink:1070}"" title=""Codegarden"">Codegarden</a></p> <p>We can also insert several images</p> <p><img style=""width: 500px; height: 375px;"" src=""/media/1054/pensive-parakeet.jpg?width=500&height=375"" alt="""" rel=""1087"" data-id=""1087"" /></p> <p> </p> <p>And another one :</p> <p><img style=""width: 500px; height: 375px;"" src=""/media/1050/costa-rican-frog.jpg?width=500&height=375"" alt="""" rel=""1086"" data-id=""1086"" /></p> <p> </p> <p>And link to files in the media section</p> <p><a data-id=""1084"" href=""/media/1056/pic04.jpg"" title=""pic04.jpg"">Image linked</a></p> <p><a data-id=""1092"" href=""/media/1057/doc-type-grid-editor-developers-guide-v11.pdf"" title=""Doc-Type-Grid-Editor---Developers-Guide-v1.1.pdf"">Pdf linked</a></p> <p> </p> <p> </p>"; var property = new Property(propertyType, html); // act var result = parser.GetLinkedEntities(property.Value); // verify Assert.IsNotNull(result); var entities = result.ToList(); Assert.AreEqual(6, entities.Count()); Assert.IsTrue(entities.Exists(x => x.LinkedEntityType == LinkedEntityType.Document && x.Id == 1069)); Assert.IsTrue(entities.Exists(x => x.LinkedEntityType == LinkedEntityType.Document && x.Id == 1070)); Assert.IsTrue(entities.Exists(x => x.LinkedEntityType == LinkedEntityType.Media && x.Id == 1086)); Assert.IsTrue(entities.Exists(x => x.LinkedEntityType == LinkedEntityType.Media && x.Id == 1087)); Assert.IsTrue(entities.Exists(x => x.LinkedEntityType == LinkedEntityType.Media && x.Id == 1084)); Assert.IsTrue(entities.Exists(x => x.LinkedEntityType == LinkedEntityType.Media && x.Id == 1092)); }
public void TestGetLinkedEntitiesWithEmptyValue() { // arrange var parser = new RichTextEditorParser(); var propertyType = new PropertyType( global::Umbraco.Core.Constants.PropertyEditors.TinyMCEAlias, DataTypeDatabaseType.Ntext, "cp1"); var property = new Property(propertyType, null); // act var result = parser.GetLinkedEntities(property.Value); // verify Assert.IsNotNull(result); var entities = result.ToList(); Assert.AreEqual(0, entities.Count()); }
public void TestGetLinkedEntitiesWithValueV76() { // arrange var cacheProviderMock = new Mock <ICacheProvider>(); cacheProviderMock.Setup(x => x.GetCacheItem(It.IsAny <string>(), It.IsAny <Func <object> >())) .Returns((string k, Func <object> action) => action()); var contentKey = "9bbbfed045e046bdabf2ea0c9ceef572"; var media1Key = "f6aaf1ee4d2d47ad937a53d59687eace"; var media2Key = "edfc78f2521244c883893063988837c8"; var html = $@"<p>This is rich text </p> <p>This can contain links to <a data-udi=""umb://document/{contentKey}"" href=""/{{localLink:umb://document/{contentKey}}}"" title=""Contact"">content</a></p> <p>Have images inserted </p> <p><img style=""width: 500px; height:375px;"" src=""/media/1054/img_20160817_113309.jpg?width=500&height=375"" alt="""" data-udi=""umb://media/{media1Key}"" /></p> <p> </p> <p>And links to <a data-udi=""umb://media/{media2Key}"" href=""/media/1057/djace.pdf"" title=""Djace.pdf"">files</a></p>"; var contentGuid = Guid.Parse(contentKey); var media1Guid = Guid.Parse(media1Key); var media2Guid = Guid.Parse(media2Key); var contentId = 1500; var media1Id = 1601; var media2Id = 1602; var contentMock = new Mock <IContent>(); contentMock.SetupGet(x => x.Id).Returns(contentId); var contentServiceMock = new Mock <IContentService>(); contentServiceMock.Setup(x => x.GetById(contentGuid)).Returns(contentMock.Object); var mediaService = new Mock <IMediaService>(); var media1Mock = new Mock <IMedia>(); media1Mock.SetupGet(x => x.Id).Returns(media1Id); var media2Mock = new Mock <IMedia>(); media2Mock.SetupGet(x => x.Id).Returns(media2Id); mediaService.Setup(x => x.GetById(media1Guid)).Returns(media1Mock.Object); mediaService.Setup(x => x.GetById(media2Guid)).Returns(media2Mock.Object); var parser = new RichTextEditorParser( contentServiceMock.Object, mediaService.Object, cacheProviderMock.Object); // act var result = parser.GetLinkedEntities(html); // verify Assert.IsNotNull(result); var entities = result.ToList(); Assert.AreEqual(3, entities.Count()); Assert.IsTrue(entities.Exists(x => x.LinkedEntityType == LinkedEntityType.Document && x.Id == contentId)); Assert.IsTrue(entities.Exists(x => x.LinkedEntityType == LinkedEntityType.Media && x.Id == media1Id)); Assert.IsTrue(entities.Exists(x => x.LinkedEntityType == LinkedEntityType.Media && x.Id == media2Id)); }