Esempio n. 1
0
        public void Can_Avoid_Circular_Dependencies_In_Composition()
        {
            ContentType  textPage      = ContentTypeBuilder.CreateTextPageContentType();
            ContentType  parent        = ContentTypeBuilder.CreateSimpleContentType("parent", "Parent", null, randomizeAliases: true);
            ContentType  meta          = ContentTypeBuilder.CreateMetaContentType();
            PropertyType propertyType1 = new PropertyTypeBuilder()
                                         .WithAlias("coauthor")
                                         .WithName("Co-author")
                                         .Build();
            ContentType mixin1 = ContentTypeBuilder.CreateSimpleContentType(
                "mixin1",
                "Mixin1",
                propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> {
                propertyType1
            }));
            PropertyType propertyType2 = new PropertyTypeBuilder()
                                         .WithAlias("author")
                                         .WithName("Author")
                                         .Build();
            ContentType mixin2 = ContentTypeBuilder.CreateSimpleContentType(
                "mixin2",
                "Mixin2",
                propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> {
                propertyType2
            }));

            // Act
            bool addedMetaMixin2 = mixin2.AddContentType(meta);
            bool addedMixin2     = mixin1.AddContentType(mixin2);
            bool addedMeta       = parent.AddContentType(meta);

            bool addedMixin1 = parent.AddContentType(mixin1);

            bool addedMixin1Textpage = textPage.AddContentType(mixin1);
            bool addedTextpageParent = parent.AddContentType(textPage);

            IEnumerable <string>        aliases        = textPage.CompositionAliases();
            IEnumerable <IPropertyType> propertyTypes  = textPage.CompositionPropertyTypes;
            IEnumerable <PropertyGroup> propertyGroups = textPage.CompositionPropertyGroups;

            // Assert
            Assert.That(mixin2.ContentTypeCompositionExists("meta"), Is.True);
            Assert.That(mixin1.ContentTypeCompositionExists("meta"), Is.True);
            Assert.That(parent.ContentTypeCompositionExists("meta"), Is.True);
            Assert.That(textPage.ContentTypeCompositionExists("meta"), Is.True);

            Assert.That(aliases.Count(), Is.EqualTo(3));
            Assert.That(propertyTypes.Count(), Is.EqualTo(8));
            Assert.That(propertyGroups.Count(), Is.EqualTo(2));

            Assert.That(addedMeta, Is.True);
            Assert.That(addedMetaMixin2, Is.True);
            Assert.That(addedMixin2, Is.True);
            Assert.That(addedMixin1, Is.False);
            Assert.That(addedMixin1Textpage, Is.True);
            Assert.That(addedTextpageParent, Is.False);
        }
Esempio n. 2
0
        public void Can_Compose_Nested_Composite_ContentType_Collection()
        {
            // Arrange
            ContentType  metaContentType   = ContentTypeBuilder.CreateMetaContentType();
            ContentType  simpleContentType = ContentTypeBuilder.CreateSimpleContentType();
            PropertyType propertyType      = new PropertyTypeBuilder()
                                             .WithAlias("coauthor")
                                             .WithName("Co-author")
                                             .Build();
            ContentType simple2ContentType = ContentTypeBuilder.CreateSimpleContentType(
                "anotherSimple",
                "Another Simple Page",
                propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> {
                propertyType
            }));

            // Act
            bool addedMeta = simple2ContentType.AddContentType(metaContentType);
            bool added     = simpleContentType.AddContentType(simple2ContentType);
            IEnumerable <PropertyGroup> compositionPropertyGroups = simpleContentType.CompositionPropertyGroups;
            IEnumerable <IPropertyType> compositionPropertyTypes  = simpleContentType.CompositionPropertyTypes;

            // Assert
            Assert.That(addedMeta, Is.True);
            Assert.That(added, Is.True);
            Assert.That(compositionPropertyGroups.Count(), Is.EqualTo(2));
            Assert.That(compositionPropertyTypes.Count(), Is.EqualTo(6));
            Assert.That(simpleContentType.ContentTypeCompositionExists("meta"), Is.True);
        }
Esempio n. 3
0
        public void GetAvailableCompositeContentTypes_Include_Indirect_Composed_Types()
        {
            ContentType ct1 = ContentTypeBuilder.CreateBasicContentType("ct1", "CT1");
            ContentType ct2 = ContentTypeBuilder.CreateBasicContentType("ct2", "CT2");
            ContentType ct3 = ContentTypeBuilder.CreateBasicContentType("ct3", "CT3");
            ContentType ct4 = ContentTypeBuilder.CreateBasicContentType("ct4", "CT4");

            ct1.Id = 1;
            ct2.Id = 2;
            ct3.Id = 3;
            ct4.Id = 4;

            ct1.AddContentType(ct3);    // ct3 is direct to ct1
            ct3.AddContentType(ct4);    // ct4 is indirect to ct1

            var service = new Mock <IContentTypeService>();

            IContentTypeComposition[] availableTypes = service.Object.GetAvailableCompositeContentTypes(
                ct1,
                new[] { ct1, ct2, ct3 })
                                                       .Results.Where(x => x.Allowed).Select(x => x.Composition).ToArray();

            Assert.AreEqual(3, availableTypes.Count());
            Assert.AreEqual(ct2.Id, availableTypes.ElementAt(0).Id);
            Assert.AreEqual(ct3.Id, availableTypes.ElementAt(1).Id);
            Assert.AreEqual(ct4.Id, availableTypes.ElementAt(2).Id);
        }
Esempio n. 4
0
        public static ContentType GetBasePageWithGridBase(string basePageTypeAlias)
        {
            var contentService = ApplicationContext.Current.Services.ContentTypeService;
            var fileService    = ApplicationContext.Current.Services.FileService;

            var basePageWithGrid     = contentService.GetContentType(basePageTypeAlias);
            var basePageWithGridBase = new ContentType(basePageWithGrid.Id);

            basePageWithGridBase.AddContentType(basePageWithGrid);
            basePageWithGridBase.SetDefaultTemplate(fileService.GetTemplate(CoreInstallationConstants.TemplateAliases.GridPageLayoutTemplateAlias));

            return(basePageWithGridBase);
        }
        protected override IContentType CreateItem(string alias, ITreeEntity parent, string itemType)
        {
            var item = new ContentType(-1)
            {
                Alias = alias
            };

            if (parent != null)
            {
                if (parent is IContentType parentContent)
                {
                    item.AddContentType(parentContent);
                }

                item.SetParent(parent);
            }

            return(item);
        }
Esempio n. 6
0
        public void GetAvailableCompositeContentTypes_No_Results_If_Already_A_Composition()
        {
            ContentType ct1 = ContentTypeBuilder.CreateBasicContentType("ct1", "CT1");
            ContentType ct2 = ContentTypeBuilder.CreateBasicContentType("ct2", "CT2");
            ContentType ct3 = ContentTypeBuilder.CreateBasicContentType("ct3", "CT3");

            ct1.Id = 1;
            ct2.Id = 2;
            ct3.Id = 3;

            ct2.AddContentType(ct1);

            var service = new Mock <IContentTypeService>();

            System.Collections.Generic.IEnumerable <ContentTypeAvailableCompositionsResult> availableTypes = service.Object.GetAvailableCompositeContentTypes(
                ct1,
                new[] { ct1, ct2, ct3 }).Results;

            Assert.AreEqual(0, availableTypes.Count());
        }
Esempio n. 7
0
        public void Can_Save_ContentType_Structure_And_Create_Content_Based_On_It()
        {
            // Arrange
            var cs       = ServiceContext.ContentService;
            var cts      = ServiceContext.ContentTypeService;
            var dtdYesNo = ServiceContext.DataTypeService.GetDataTypeDefinitionById(-49);
            var ctBase   = new ContentType(-1)
            {
                Name = "Base", Alias = "Base", Icon = "folder.gif", Thumbnail = "folder.png"
            };

            ctBase.AddPropertyType(new PropertyType(dtdYesNo)
            {
                Name = "Hide From Navigation", Alias = "umbracoNaviHide"
            } /*,"Navigation"*/);
            cts.Save(ctBase);

            var ctHomePage = new ContentType(ctBase)
            {
                Name = "Home Page", Alias = "HomePage", Icon = "settingDomain.gif", Thumbnail = "folder.png", AllowedAsRoot = true
            };
            bool addedContentType = ctHomePage.AddContentType(ctBase);

            ctHomePage.AddPropertyType(new PropertyType(dtdYesNo)
            {
                Name = "Some property", Alias = "someProperty"
            } /*,"Navigation"*/);
            cts.Save(ctHomePage);

            // Act
            var homeDoc = cs.CreateContent("Home Page", -1, "HomePage");

            cs.SaveAndPublish(homeDoc);

            // Assert
            Assert.That(ctBase.HasIdentity, Is.True);
            Assert.That(ctHomePage.HasIdentity, Is.True);
            Assert.That(homeDoc.HasIdentity, Is.True);
            Assert.That(homeDoc.ContentTypeId, Is.EqualTo(ctHomePage.Id));
            Assert.That(addedContentType, Is.True);
        }
Esempio n. 8
0
        public void GetAvailableCompositeContentTypes_Do_Not_Include_Other_Composed_Types()
        {
            ContentType ct1 = ContentTypeBuilder.CreateBasicContentType("ct1", "CT1");
            ContentType ct2 = ContentTypeBuilder.CreateBasicContentType("ct2", "CT2");
            ContentType ct3 = ContentTypeBuilder.CreateBasicContentType("ct3", "CT3");

            ct1.Id = 1;
            ct2.Id = 2;
            ct3.Id = 3;

            ct2.AddContentType(ct3);

            var service = new Mock <IContentTypeService>();

            IContentTypeComposition[] availableTypes = service.Object.GetAvailableCompositeContentTypes(
                ct1,
                new[] { ct1, ct2, ct3 })
                                                       .Results.Where(x => x.Allowed).Select(x => x.Composition).ToArray();

            Assert.AreEqual(1, availableTypes.Count());
            Assert.AreEqual(ct3.Id, availableTypes.Single().Id);
        }
Esempio n. 9
0
        protected override Attempt <IContentType> CreateItem(string alias, ITreeEntity parent, string itemType)
        {
            var safeAlias = GetSafeItemAlias(alias);

            var item = new ContentType(shortStringHelper, -1)
            {
                Alias = alias
            };

            if (parent != null)
            {
                if (parent is IContentType parentContent)
                {
                    item.AddContentType(parentContent);
                }

                item.SetParent(parent);
            }

            // adds this alias to the alias cache.
            AddAlias(safeAlias);

            return(Attempt.Succeed((IContentType)item));
        }
Esempio n. 10
0
        public void Change_Variations_ComposedContentType_2()
        {
            // one composing content type, variant, with both variant and invariant properties
            // one composed content type, variant, with both variant and invariant properties
            // one composed content type, invariant
            // can change the composing content type to invariant and back
            // can change the variant composed content type to invariant and back

            var languageEn = new Language("en")
            {
                IsDefault = true
            };

            ServiceContext.LocalizationService.Save(languageEn);
            var languageFr = new Language("fr");

            ServiceContext.LocalizationService.Save(languageFr);

            var composing = new ContentType(-1)
            {
                Alias      = "composing",
                Name       = "composing",
                Variations = ContentVariation.Culture
            };

            var properties1 = new PropertyTypeCollection(true)
            {
                new PropertyType("value11", ValueStorageType.Ntext)
                {
                    Alias      = "value11",
                    DataTypeId = -88,
                    Variations = ContentVariation.Culture
                },
                new PropertyType("value12", ValueStorageType.Ntext)
                {
                    Alias      = "value12",
                    DataTypeId = -88,
                    Variations = ContentVariation.Nothing
                }
            };

            composing.PropertyGroups.Add(new PropertyGroup(properties1)
            {
                Name = "Content"
            });
            ServiceContext.ContentTypeService.Save(composing);

            var composed1 = new ContentType(-1)
            {
                Alias      = "composed1",
                Name       = "composed1",
                Variations = ContentVariation.Culture
            };

            var properties2 = new PropertyTypeCollection(true)
            {
                new PropertyType("value21", ValueStorageType.Ntext)
                {
                    Alias      = "value21",
                    DataTypeId = -88,
                    Variations = ContentVariation.Culture
                },
                new PropertyType("value22", ValueStorageType.Ntext)
                {
                    Alias      = "value22",
                    DataTypeId = -88,
                    Variations = ContentVariation.Nothing
                }
            };

            composed1.PropertyGroups.Add(new PropertyGroup(properties2)
            {
                Name = "Content"
            });
            composed1.AddContentType(composing);
            ServiceContext.ContentTypeService.Save(composed1);

            var composed2 = new ContentType(-1)
            {
                Alias      = "composed2",
                Name       = "composed2",
                Variations = ContentVariation.Nothing
            };

            var properties3 = new PropertyTypeCollection(true)
            {
                new PropertyType("value31", ValueStorageType.Ntext)
                {
                    Alias      = "value31",
                    DataTypeId = -88,
                    Variations = ContentVariation.Nothing
                },
                new PropertyType("value32", ValueStorageType.Ntext)
                {
                    Alias      = "value32",
                    DataTypeId = -88,
                    Variations = ContentVariation.Nothing
                }
            };

            composed2.PropertyGroups.Add(new PropertyGroup(properties3)
            {
                Name = "Content"
            });
            composed2.AddContentType(composing);
            ServiceContext.ContentTypeService.Save(composed2);

            var document1 = (IContent) new Content("document1", -1, composed1);

            document1.SetCultureName("doc1en", "en");
            document1.SetCultureName("doc1fr", "fr");
            document1.SetValue("value11", "v11en", "en");
            document1.SetValue("value11", "v11fr", "fr");
            document1.SetValue("value12", "v12");
            document1.SetValue("value21", "v21en", "en");
            document1.SetValue("value21", "v21fr", "fr");
            document1.SetValue("value22", "v22");
            ServiceContext.ContentService.Save(document1);

            var document2 = (IContent) new Content("document2", -1, composed2);

            document2.Name = "doc2";
            document2.SetValue("value11", "v11");
            document2.SetValue("value12", "v12");
            document2.SetValue("value31", "v31");
            document2.SetValue("value32", "v32");
            ServiceContext.ContentService.Save(document2);

            // both value11 and value21 are variant
            Console.WriteLine(GetJson(document1.Id));
            AssertJsonStartsWith(document1.Id,
                                 "{'properties':{'value11':[{'culture':'en','seg':'','val':'v11en'},{'culture':'fr','seg':'','val':'v11fr'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value21':[{'culture':'en','seg':'','val':'v21en'},{'culture':'fr','seg':'','val':'v21fr'}],'value22':[{'culture':'','seg':'','val':'v22'}]},'cultureData':");

            Console.WriteLine(GetJson(document2.Id));
            AssertJsonStartsWith(document2.Id,
                                 "{'properties':{'value11':[{'culture':'','seg':'','val':'v11'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value31':[{'culture':'','seg':'','val':'v31'}],'value32':[{'culture':'','seg':'','val':'v32'}]},'cultureData':");

            composed1.Variations = ContentVariation.Nothing;
            ServiceContext.ContentTypeService.Save(composed1);

            // both value11 and value21 are invariant
            Console.WriteLine(GetJson(document1.Id));
            AssertJsonStartsWith(document1.Id,
                                 "{'properties':{'value11':[{'culture':'','seg':'','val':'v11en'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value21':[{'culture':'','seg':'','val':'v21en'}],'value22':[{'culture':'','seg':'','val':'v22'}]},'cultureData':");

            Console.WriteLine(GetJson(document2.Id));
            AssertJsonStartsWith(document2.Id,
                                 "{'properties':{'value11':[{'culture':'','seg':'','val':'v11'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value31':[{'culture':'','seg':'','val':'v31'}],'value32':[{'culture':'','seg':'','val':'v32'}]},'cultureData':");

            composed1.Variations = ContentVariation.Culture;
            ServiceContext.ContentTypeService.Save(composed1);

            // value11 is variant again, but value21 is still invariant
            Console.WriteLine(GetJson(document1.Id));
            AssertJsonStartsWith(document1.Id,
                                 "{'properties':{'value11':[{'culture':'en','seg':'','val':'v11en'},{'culture':'fr','seg':'','val':'v11fr'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value21':[{'culture':'','seg':'','val':'v21en'}],'value22':[{'culture':'','seg':'','val':'v22'}]},'cultureData':");

            Console.WriteLine(GetJson(document2.Id));
            AssertJsonStartsWith(document2.Id,
                                 "{'properties':{'value11':[{'culture':'','seg':'','val':'v11'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value31':[{'culture':'','seg':'','val':'v31'}],'value32':[{'culture':'','seg':'','val':'v32'}]},'cultureData':");

            composed1.PropertyTypes.First(x => x.Alias == "value21").Variations = ContentVariation.Culture;
            ServiceContext.ContentTypeService.Save(composed1);

            // we can make it variant again
            Console.WriteLine(GetJson(document1.Id));
            AssertJsonStartsWith(document1.Id,
                                 "{'properties':{'value11':[{'culture':'en','seg':'','val':'v11en'},{'culture':'fr','seg':'','val':'v11fr'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value21':[{'culture':'en','seg':'','val':'v21en'},{'culture':'fr','seg':'','val':'v21fr'}],'value22':[{'culture':'','seg':'','val':'v22'}]},'cultureData':");

            Console.WriteLine(GetJson(document2.Id));
            AssertJsonStartsWith(document2.Id,
                                 "{'properties':{'value11':[{'culture':'','seg':'','val':'v11'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value31':[{'culture':'','seg':'','val':'v31'}],'value32':[{'culture':'','seg':'','val':'v32'}]},'cultureData':");

            composing.Variations = ContentVariation.Nothing;
            ServiceContext.ContentTypeService.Save(composing);

            // value11 is invariant
            Console.WriteLine(GetJson(document1.Id));
            AssertJsonStartsWith(document1.Id,
                                 "{'properties':{'value11':[{'culture':'','seg':'','val':'v11en'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value21':[{'culture':'en','seg':'','val':'v21en'},{'culture':'fr','seg':'','val':'v21fr'}],'value22':[{'culture':'','seg':'','val':'v22'}]},'cultureData':");

            Console.WriteLine(GetJson(document2.Id));
            AssertJsonStartsWith(document2.Id,
                                 "{'properties':{'value11':[{'culture':'','seg':'','val':'v11'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value31':[{'culture':'','seg':'','val':'v31'}],'value32':[{'culture':'','seg':'','val':'v32'}]},'cultureData':");

            composing.Variations = ContentVariation.Culture;
            ServiceContext.ContentTypeService.Save(composing);

            // value11 is still invariant
            Console.WriteLine(GetJson(document1.Id));
            AssertJsonStartsWith(document1.Id,
                                 "{'properties':{'value11':[{'culture':'','seg':'','val':'v11en'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value21':[{'culture':'en','seg':'','val':'v21en'},{'culture':'fr','seg':'','val':'v21fr'}],'value22':[{'culture':'','seg':'','val':'v22'}]},'cultureData':");

            Console.WriteLine(GetJson(document2.Id));
            AssertJsonStartsWith(document2.Id,
                                 "{'properties':{'value11':[{'culture':'','seg':'','val':'v11'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value31':[{'culture':'','seg':'','val':'v31'}],'value32':[{'culture':'','seg':'','val':'v32'}]},'cultureData':");

            composing.PropertyTypes.First(x => x.Alias == "value11").Variations = ContentVariation.Culture;
            ServiceContext.ContentTypeService.Save(composing);

            // we can make it variant again
            Console.WriteLine(GetJson(document1.Id));
            AssertJsonStartsWith(document1.Id,
                                 "{'properties':{'value11':[{'culture':'en','seg':'','val':'v11en'},{'culture':'fr','seg':'','val':'v11fr'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value21':[{'culture':'en','seg':'','val':'v21en'},{'culture':'fr','seg':'','val':'v21fr'}],'value22':[{'culture':'','seg':'','val':'v22'}]},'cultureData':");

            Console.WriteLine(GetJson(document2.Id));
            AssertJsonStartsWith(document2.Id,
                                 "{'properties':{'value11':[{'culture':'','seg':'','val':'v11'}],'value12':[{'culture':'','seg':'','val':'v12'}],'value31':[{'culture':'','seg':'','val':'v31'}],'value32':[{'culture':'','seg':'','val':'v32'}]},'cultureData':");
        }