public void Can_Delete_Container_Containing_Media_Types()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                EntityContainerRepository containerRepository = CreateContainerRepository(provider);
                MediaTypeRepository       repository          = CreateRepository(provider);

                var container = new EntityContainer(Constants.ObjectTypes.MediaType)
                {
                    Name = "blah"
                };
                containerRepository.Save(container);

                IMediaType contentType =
                    MediaTypeBuilder.CreateSimpleMediaType("test", "Test", propertyGroupAlias: "testGroup", propertyGroupName: "testGroup");
                contentType.ParentId = container.Id;
                repository.Save(contentType);

                // Act
                containerRepository.Delete(container);

                EntityContainer found = containerRepository.Get(container.Id);
                Assert.IsNull(found);

                contentType = repository.Get(contentType.Id);
                Assert.IsNotNull(contentType);
                Assert.AreEqual(-1, contentType.ParentId);
            }
        }
    public void Empty_Description_Is_Always_Null_After_Saving_Media_Type()
    {
        var mediaType = MediaTypeBuilder.CreateSimpleMediaType("mediaType", "Media Type");

        mediaType.Description = null;
        MediaTypeService.Save(mediaType);

        var mediaType2 = MediaTypeBuilder.CreateSimpleMediaType("mediaType2", "Media Type 2");

        mediaType2.Description = string.Empty;
        MediaTypeService.Save(mediaType2);

        Assert.IsNull(mediaType.Description);
        Assert.IsNull(mediaType2.Description);
    }
Exemple #3
0
        public void Automatically_Track_Relations()
        {
            var mt = MediaTypeBuilder.CreateSimpleMediaType("testMediaType", "Test Media Type");

            MediaTypeService.Save(mt);
            var m1 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1);
            var m2 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1);

            MediaService.Save(m1);
            MediaService.Save(m2);

            var template = TemplateBuilder.CreateTextPageTemplate();

            FileService.SaveTemplate(template);

            var ct = ContentTypeBuilder.CreateTextPageContentType("richTextTest", defaultTemplateId: template.Id);

            ct.AllowedTemplates = Enumerable.Empty <ITemplate>();

            ContentTypeService.Save(ct);

            var c1 = ContentBuilder.CreateTextpageContent(ct, "my content 1", -1);

            ContentService.Save(c1);

            var c2 = ContentBuilder.CreateTextpageContent(ct, "my content 2", -1);

            // 'bodyText' is a property with a RTE property editor which we knows tracks relations
            c2.Properties["bodyText"].SetValue(@"<p>
        <img src='/media/12312.jpg' data-udi='umb://media/" + m1.Key.ToString("N") + @"' />
</p><p><img src='/media/234234.jpg' data-udi=""umb://media/" + m2.Key.ToString("N") + @""" />
</p>
<p>
    <a href=""{locallink:umb://document/" + c1.Key.ToString("N") + @"}"">hello</a>
</p>");

            ContentService.Save(c2);

            var relations = RelationService.GetByParentId(c2.Id).ToList();

            Assert.AreEqual(3, relations.Count);
            Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[0].RelationType.Alias);
            Assert.AreEqual(m1.Id, relations[0].ChildId);
            Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[1].RelationType.Alias);
            Assert.AreEqual(m2.Id, relations[1].ChildId);
            Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedDocumentAlias, relations[2].RelationType.Alias);
            Assert.AreEqual(c1.Id, relations[2].ChildId);
        }
Exemple #4
0
        public void CacheActiveForIntsAndGuids()
        {
            var realCache = new AppCaches(
                new ObjectCacheAppCache(),
                new DictionaryAppCache(),
                new IsolatedCaches(t => new ObjectCacheAppCache()));

            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository, appCaches: realCache);

                IUmbracoDatabase udb = ScopeAccessor.AmbientScope.Database;

                udb.EnableSqlCount = false;

                MediaType mediaType = MediaTypeBuilder.CreateSimpleMediaType("umbTextpage1", "Textpage");
                mediaTypeRepository.Save(mediaType);

                Media media = MediaBuilder.CreateSimpleMedia(mediaType, "hello", -1);
                repository.Save(media);

                udb.EnableSqlCount = true;

                // go get it, this should already be cached since the default repository key is the INT
                IMedia found = repository.Get(media.Id);
                Assert.AreEqual(0, udb.SqlCount);

                // retrieve again, this should use cache
                found = repository.Get(media.Id);
                Assert.AreEqual(0, udb.SqlCount);

                // reset counter
                udb.EnableSqlCount = false;
                udb.EnableSqlCount = true;

                // now get by GUID, this won't be cached yet because the default repo key is not a GUID
                found = repository.Get(media.Key);
                int sqlCount = udb.SqlCount;
                Assert.Greater(sqlCount, 0);

                // retrieve again, this should use cache now
                found = repository.Get(media.Key);
                Assert.AreEqual(sqlCount, udb.SqlCount);
            }
        }
    public void Can_Copy_MediaType_To_New_Parent_By_Performing_Clone()
    {
        // Arrange
        var parentMediaType1 = MediaTypeBuilder.CreateSimpleMediaType("parent1", "Parent1");

        MediaTypeService.Save(parentMediaType1);
        var parentMediaType2 = MediaTypeBuilder.CreateSimpleMediaType("parent2", "Parent2", null, true);

        MediaTypeService.Save(parentMediaType2);
        var mediaType = MediaTypeBuilder.CreateImageMediaType("Image2") as IMediaType;

        MediaTypeService.Save(mediaType);

        // Act
        var clone = mediaType.DeepCloneWithResetIdentities("newcategory");

        Assert.IsNotNull(clone);
        clone.RemoveContentType("parent1");
        clone.AddContentType(parentMediaType2);
        clone.ParentId = parentMediaType2.Id;
        MediaTypeService.Save(clone);

        // Assert
        Assert.That(clone.HasIdentity, Is.True);

        var clonedMediaType   = MediaTypeService.Get(clone.Id);
        var originalMediaType = MediaTypeService.Get(mediaType.Id);

        Assert.That(clonedMediaType.CompositionAliases().Any(x => x.Equals("parent2")), Is.True);
        Assert.That(clonedMediaType.CompositionAliases().Any(x => x.Equals("parent1")), Is.False);

        Assert.AreEqual(clonedMediaType.Path, "-1," + parentMediaType2.Id + "," + clonedMediaType.Id);
        Assert.AreEqual(clonedMediaType.PropertyTypes.Count(), originalMediaType.PropertyTypes.Count());

        Assert.AreNotEqual(clonedMediaType.ParentId, originalMediaType.ParentId);
        Assert.AreEqual(clonedMediaType.ParentId, parentMediaType2.Id);

        Assert.AreNotEqual(clonedMediaType.Id, originalMediaType.Id);
        Assert.AreNotEqual(clonedMediaType.Key, originalMediaType.Key);
        Assert.AreNotEqual(clonedMediaType.Path, originalMediaType.Path);

        Assert.AreNotEqual(clonedMediaType.PropertyTypes.First(x => x.Alias.StartsWith("umbracoFile")).Id,
                           originalMediaType.PropertyTypes.First(x => x.Alias.StartsWith("umbracoFile")).Id);
        Assert.AreNotEqual(clonedMediaType.PropertyGroups.First(x => x.Name.StartsWith("Media")).Id,
                           originalMediaType.PropertyGroups.First(x => x.Name.StartsWith("Media")).Id);
    }
    public void Deleting_Media_Types_With_Hierarchy_Of_Media_Items_Doesnt_Raise_Trashed_Event_For_Deleted_Items()
    {
        ContentNotificationHandler.MovedMediaToRecycleBin = MovedMediaToRecycleBin;

        try
        {
            IMediaType contentType1 = MediaTypeBuilder.CreateSimpleMediaType("test1", "Test1");
            MediaTypeService.Save(contentType1);
            IMediaType contentType2 = MediaTypeBuilder.CreateSimpleMediaType("test2", "Test2");
            MediaTypeService.Save(contentType2);
            IMediaType contentType3 = MediaTypeBuilder.CreateSimpleMediaType("test3", "Test3");
            MediaTypeService.Save(contentType3);

            IMediaType[] contentTypes = { contentType1, contentType2, contentType3 };
            var          parentId     = -1;

            var ids = new List <int>();

            for (var i = 0; i < 2; i++)
            {
                for (var index = 0; index < contentTypes.Length; index++)
                {
                    var contentType = contentTypes[index];
                    var contentItem =
                        MediaBuilder.CreateSimpleMedia(contentType, "MyName_" + index + "_" + i, parentId);
                    MediaService.Save(contentItem);
                    parentId = contentItem.Id;

                    ids.Add(contentItem.Id);
                }
            }

            foreach (var contentType in contentTypes.Reverse())
            {
                MediaTypeService.Delete(contentType);
            }
        }
        finally
        {
            ContentNotificationHandler.MovedMediaToRecycleBin = null;
        }
    }
    public void Deleting_Media_Type_With_Hierarchy_Of_Media_Items_Moves_Orphaned_Media_To_Recycle_Bin()
    {
        IMediaType contentType1 = MediaTypeBuilder.CreateSimpleMediaType("test1", "Test1");

        MediaTypeService.Save(contentType1);
        IMediaType contentType2 = MediaTypeBuilder.CreateSimpleMediaType("test2", "Test2");

        MediaTypeService.Save(contentType2);
        IMediaType contentType3 = MediaTypeBuilder.CreateSimpleMediaType("test3", "Test3");

        MediaTypeService.Save(contentType3);

        IMediaType[] contentTypes = { contentType1, contentType2, contentType3 };
        var          parentId     = -1;

        var ids = new List <int>();

        for (var i = 0; i < 2; i++)
        {
            for (var index = 0; index < contentTypes.Length; index++)
            {
                var contentType = contentTypes[index];
                var contentItem = MediaBuilder.CreateSimpleMedia(contentType, "MyName_" + index + "_" + i, parentId);
                MediaService.Save(contentItem);
                parentId = contentItem.Id;

                ids.Add(contentItem.Id);
            }
        }

        // delete the first content type, all other content of different content types should be in the recycle bin
        MediaTypeService.Delete(contentTypes[0]);

        var found = MediaService.GetByIds(ids);

        Assert.AreEqual(4, found.Count());
        foreach (var content in found)
        {
            Assert.IsTrue(content.Trashed);
        }
    }
Exemple #8
0
    public void Return_List_Of_Content_Items_Where_Media_Item_Referenced()
    {
        var mt = MediaTypeBuilder.CreateSimpleMediaType("testMediaType", "Test Media Type");

        MediaTypeService.Save(mt);
        var m1 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1);

        MediaService.Save(m1);

        var ct = ContentTypeBuilder.CreateTextPageContentType("richTextTest");

        ct.AllowedTemplates = Enumerable.Empty <ITemplate>();
        ContentTypeService.Save(ct);

        void CreateContentWithMediaRefs()
        {
            var content = ContentBuilder.CreateTextpageContent(ct, "my content 2", -1);

            // 'bodyText' is a property with a RTE property editor which we knows automatically tracks relations
            content.Properties["bodyText"].SetValue(@"<p>
        <img src='/media/12312.jpg' data-udi='umb://media/" + m1.Key.ToString("N") + @"' />
</p>");
            ContentService.Save(content);
        }

        for (var i = 0; i < 6; i++)
        {
            CreateContentWithMediaRefs(); // create 6 content items referencing the same media
        }

        var relations = RelationService.GetByChildId(m1.Id, Constants.Conventions.RelationTypes.RelatedMediaAlias)
                        .ToList();

        Assert.AreEqual(6, relations.Count);

        var entities = RelationService.GetParentEntitiesFromRelations(relations).ToList();

        Assert.AreEqual(6, entities.Count);
    }
Exemple #9
0
    public void Can_Create_Container_Containing_Media_Types()
    {
        var provider = ScopeProvider;

        using (var scope = provider.CreateScope())
        {
            var containerRepository = CreateContainerRepository(provider);
            var repository          = CreateRepository(provider);

            var container = new EntityContainer(Constants.ObjectTypes.MediaType)
            {
                Name = "blah"
            };
            containerRepository.Save(container);

            var contentType =
                MediaTypeBuilder.CreateSimpleMediaType("test", "Test", propertyGroupAlias: "testGroup", propertyGroupName: "testGroup");
            contentType.ParentId = container.Id;
            repository.Save(contentType);

            Assert.AreEqual(container.Id, contentType.ParentId);
        }
    }
        public void Can_Update_Media_Property_Values()
        {
            IMediaType mediaType = MediaTypeBuilder.CreateSimpleMediaType("test", "Test");

            MediaTypeService.Save(mediaType);
            IMedia media = MediaBuilder.CreateSimpleMedia(mediaType, "hello", -1);

            media.SetValue("title", "title of mine");
            media.SetValue("bodyText", "hello world");
            MediaService.Save(media);

            // re-get
            media = MediaService.GetById(media.Id);
            media.SetValue("title", "another title of mine");          // Change a value
            media.SetValue("bodyText", null);                          // Clear a value
            media.SetValue("author", "new author");                    // Add a value
            MediaService.Save(media);

            // re-get
            media = MediaService.GetById(media.Id);
            Assert.AreEqual("another title of mine", media.GetValue("title"));
            Assert.IsNull(media.GetValue("bodyText"));
            Assert.AreEqual("new author", media.GetValue("author"));
        }
        private static IMedia CreateMedia(int nodeId)
        {
            MediaType mediaType = MediaTypeBuilder.CreateSimpleMediaType("image", "Image");

            return(MediaBuilder.CreateSimpleMedia(mediaType, "Test image", -1, nodeId));
        }
    public void Can_Perform_Update_On_UserRepository()
    {
        var ct = ContentTypeBuilder.CreateBasicContentType("test");
        var mt = MediaTypeBuilder.CreateSimpleMediaType("testmedia", "TestMedia");

        // Arrange
        ICoreScopeProvider provider = ScopeProvider;

        using (var scope = provider.CreateCoreScope(autoComplete: true))
        {
            var userRepository      = CreateRepository(provider);
            var userGroupRepository = CreateUserGroupRepository(provider);

            ContentTypeRepository.Save(ct);
            MediaTypeRepository.Save(mt);

            var content = ContentBuilder.CreateBasicContent(ct);
            var media   = MediaBuilder.CreateSimpleMedia(mt, "asdf", -1);

            DocumentRepository.Save(content);
            MediaRepository.Save(media);

            var user = CreateAndCommitUserWithGroup(userRepository, userGroupRepository);

            // Act
            var resolved = (User)userRepository.Get(user.Id);

            resolved.Name = "New Name";

            // the db column is not used, default permissions are taken from the user type's permissions, this is a getter only
            //// resolved.DefaultPermissions = "ZYX";

            resolved.Language         = "fr";
            resolved.IsApproved       = false;
            resolved.RawPasswordValue = "new";
            resolved.IsLockedOut      = true;
            resolved.StartContentIds  = new[] { content.Id };
            resolved.StartMediaIds    = new[] { media.Id };
            resolved.Email            = "*****@*****.**";
            resolved.Username         = "******";

            userRepository.Save(resolved);

            var updatedItem = (User)userRepository.Get(user.Id);

            // Assert
            Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id));
            Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name));
            Assert.That(updatedItem.Language, Is.EqualTo(resolved.Language));
            Assert.That(updatedItem.IsApproved, Is.EqualTo(resolved.IsApproved));
            Assert.That(updatedItem.RawPasswordValue, Is.EqualTo(resolved.RawPasswordValue));
            Assert.That(updatedItem.IsLockedOut, Is.EqualTo(resolved.IsLockedOut));
            Assert.IsTrue(updatedItem.StartContentIds.UnsortedSequenceEqual(resolved.StartContentIds));
            Assert.IsTrue(updatedItem.StartMediaIds.UnsortedSequenceEqual(resolved.StartMediaIds));
            Assert.That(updatedItem.Email, Is.EqualTo(resolved.Email));
            Assert.That(updatedItem.Username, Is.EqualTo(resolved.Username));
            Assert.That(updatedItem.AllowedSections.Count(), Is.EqualTo(resolved.AllowedSections.Count()));
            foreach (var allowedSection in resolved.AllowedSections)
            {
                Assert.IsTrue(updatedItem.AllowedSections.Contains(allowedSection));
            }
        }
    }
    public void IMediaTypeComposition_To_MediaTypeDisplay()
    {
        // Arrange
        var ctMain = MediaTypeBuilder.CreateSimpleMediaType("parent", "Parent");

        // not assigned to tab
        ctMain.AddPropertyType(
            new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext)
        {
            Alias       = "umbracoUrlName",
            Name        = "Slug",
            Description = string.Empty,
            Mandatory   = false,
            SortOrder   = 1,
            DataTypeId  = -88
        });
        MediaTypeBuilder.EnsureAllIds(ctMain, 8888);
        var ctChild1 = MediaTypeBuilder.CreateSimpleMediaType("child1", "Child 1", ctMain, true);

        ctChild1.AddPropertyType(
            new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext)
        {
            Alias       = "someProperty",
            Name        = "Some Property",
            Description = string.Empty,
            Mandatory   = false,
            SortOrder   = 1,
            DataTypeId  = -88
        },
            "anotherTab",
            "Another tab");
        MediaTypeBuilder.EnsureAllIds(ctChild1, 7777);
        var contentType =
            MediaTypeBuilder.CreateSimpleMediaType("child2", "Child 2", ctChild1, true, "customGroup", "CustomGroup");

        // not assigned to tab
        contentType.AddPropertyType(
            new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext)
        {
            Alias       = "umbracoUrlAlias",
            Name        = "AltUrl",
            Description = string.Empty,
            Mandatory   = false,
            SortOrder   = 1,
            DataTypeId  = -88
        });
        MediaTypeBuilder.EnsureAllIds(contentType, 6666);

        // Act
        var result = _sut.Map <MediaTypeDisplay>(contentType);

        // Assert
        Assert.AreEqual(contentType.Alias, result.Alias);
        Assert.AreEqual(contentType.Description, result.Description);
        Assert.AreEqual(contentType.Icon, result.Icon);
        Assert.AreEqual(contentType.Id, result.Id);
        Assert.AreEqual(contentType.Name, result.Name);
        Assert.AreEqual(contentType.ParentId, result.ParentId);
        Assert.AreEqual(contentType.Path, result.Path);
        Assert.AreEqual(contentType.Thumbnail, result.Thumbnail);
        Assert.AreEqual(contentType.IsContainer, result.IsContainer);
        Assert.AreEqual(contentType.CreateDate, result.CreateDate);
        Assert.AreEqual(contentType.UpdateDate, result.UpdateDate);

        Assert.AreEqual(contentType.CompositionPropertyGroups.Select(x => x.Name).Distinct().Count(), result.Groups.Count(x => x.IsGenericProperties == false));
        Assert.AreEqual(1, result.Groups.Count(x => x.IsGenericProperties));
        Assert.AreEqual(contentType.PropertyGroups.Count(), result.Groups.Count(x => x.Inherited == false && x.IsGenericProperties == false));

        var allPropertiesMapped  = result.Groups.SelectMany(x => x.Properties).ToArray();
        var allPropertyIdsMapped = allPropertiesMapped.Select(x => x.Id).ToArray();
        var allSourcePropertyIds = contentType.CompositionPropertyTypes.Select(x => x.Id).ToArray();

        Assert.AreEqual(contentType.PropertyTypes.Count(), allPropertiesMapped.Count(x => x.Inherited == false));
        Assert.AreEqual(allPropertyIdsMapped.Count(), allSourcePropertyIds.Count());
        Assert.IsTrue(allPropertyIdsMapped.ContainsAll(allSourcePropertyIds));

        Assert.AreEqual(2, result.Groups.Count(x => x.ParentTabContentTypes.Any()));
        Assert.IsTrue(
            result.Groups.SelectMany(x => x.ParentTabContentTypes).ContainsAll(new[] { ctMain.Id, ctChild1.Id }));

        Assert.AreEqual(contentType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count());
        for (var i = 0; i < contentType.AllowedContentTypes.Count(); i++)
        {
            Assert.AreEqual(contentType.AllowedContentTypes.ElementAt(i).Id.Value, result.AllowedContentTypes.ElementAt(i));
        }
    }