Provides utilities for working with blogs
Inheritance: IBlogManager
Ejemplo n.º 1
0
        public void EnableRSS(bool enabled)
        {
            var blogTemplateId = ID.NewID;

            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.ContentRootPath == "/sitecore/content" &&
                x.BlogTemplateIds == new[] { ID.NewID, blogTemplateId, ID.NewID }
            );

            var manager = new BlogManager(settings);

            using (var db = new Db
            {
                new DbItem("blog", ID.NewID, blogTemplateId)
                {
                    { "Enable RSS", enabled ? "1" : string.Empty }
                }
            })
            {
                var item = db.GetItem("/sitecore/content/blog");
                var result = manager.EnableRSS(item);

                if(enabled)
                    Assert.That(result, Is.True);
                else
                {
                    Assert.That(result, Is.False);
                }
            }
        }
Ejemplo n.º 2
0
        public void GetUserBlogs()
        {
            var blogs = new Mod.BlogManager().GetUserBlogs("sitecore\\" + TESTUSERNAME);

            Assert.AreEqual(1, blogs.Length);
            Assert.AreEqual(m_blog1.ID, blogs[0].ID);
        }
Ejemplo n.º 3
0
        public void GetAllBlogs()
        {
            var blogs = new Mod.BlogManager().GetAllBlogs(null).Where(x => m_testContentRoot.Axes.IsAncestorOf(x));

            Assert.That(blogs.Select(x => x.ID), Is.EquivalentTo(new[]
            {
                m_blog1.ID,
                m_blog2.ID
            }));
        }
Ejemplo n.º 4
0
        public void EnableRSS_NullBlog()
        {
            var blogTemplateId = ID.NewID;

            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.ContentRootPath == "/sitecore/content" &&
                x.BlogTemplateIds == new[] { ID.NewID, blogTemplateId, ID.NewID }
            );

            var manager = new BlogManager(settings);
            var result = manager.EnableRSS(null);

            Assert.That(result, Is.False);
        }
Ejemplo n.º 5
0
 public void GetUserBlogs()
 {
     var blogs = new Mod.BlogManager().GetUserBlogs("sitecore\\" + TESTUSERNAME);
     Assert.AreEqual(1, blogs.Length);
     Assert.AreEqual(m_blog1.ID, blogs[0].ID);
 }
Ejemplo n.º 6
0
        public void GetAllBlogs_ExcludeBlogOutsideContentRoot()
        {
            var blogTemplateId = ID.NewID;
            var blog1Id = ID.NewID;
            var blog2Id = ID.NewID;

            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.ContentRootPath == "/sitecore/content/alpha" &&
                x.BlogTemplateIds == new[] { ID.NewID, blogTemplateId, ID.NewID }
            );

            var manager = new BlogManager(settings);

            using (var db = new Db
            {
                new DbItem("alpha")
                {
                    new DbItem("blog 1", blog1Id, blogTemplateId)
                },
                new DbItem("beta")
                {
                    new DbItem("blog 2", blog2Id, blogTemplateId)
                }
            })
            {
                var item = db.GetItem("/sitecore/content/alpha");
                var blogTemplate = item.Database.GetTemplate(blogTemplateId);

                var linkDb = Mock.Of<LinkDatabase>(x =>
                    x.GetReferrers(blogTemplate) == new[]
                    {
                        new ItemLink("master", blog1Id, ID.Null, "master", blogTemplateId, blogTemplateId.ToString()),
                        new ItemLink("master", blog2Id, ID.Null, "master", blogTemplateId, blogTemplateId.ToString())
                    });

                using (new LinkDatabaseSwitcher(linkDb))
                {
                    var blogs = manager.GetAllBlogs(item.Database);
                    var ids = from blog in blogs select blog.ID;

                    Assert.That(ids, Is.EquivalentTo(new[] { blog1Id }));
                }
            }
        }
Ejemplo n.º 7
0
        public void GetUserBlogs_NoBlogs()
        {
            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.ContentRootPath == "/sitecore/content" &&
                x.BlogTemplateIds == new[] { ID.NewID }
            );

            var manager = new BlogManager(settings);

            var membershipProvider = Mock.Of<MembershipProvider>(x =>
                x.GetUser(_validUsername, true) == new FakeMembershipUser()
            );

            using (var db = new Db())
            {
                var item = db.GetItem("/sitecore/content");

                using (new MembershipSwitcher(membershipProvider))
                {
                    var blogs = manager.GetUserBlogs(_validUsername);

                    Assert.That(blogs, Is.Empty);
                }
            }
        }
Ejemplo n.º 8
0
        public void GetUserBlogs_NoAccess()
        {
            var blogTemplateId = ID.NewID;
            var blog2Id = ID.NewID;
            var blog3Id = ID.NewID;

            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.ContentRootPath == "/sitecore/content" &&
                x.BlogTemplateIds == new[] { ID.NewID, blogTemplateId }
            );

            var manager = new BlogManager(settings);

            var membershipProvider = Mock.Of<MembershipProvider>(x =>
                x.GetUser(_validUsername, true) == new FakeMembershipUser()
            );

            using (var db = new Db
            {
                new DbItem("blog1", ID.NewID, blogTemplateId),
                new DbItem("blog2", blog2Id, blogTemplateId)
                {
                    Access =
                    {
                        CanWrite = true
                    }
                },
                new DbItem("blog3", blog3Id, blogTemplateId)
                {
                    Access =
                    {
                        CanWrite = true
                    }
                }
            })
            {
                var blog1 = db.GetItem("/sitecore/content/blog1");
                var blog2 = db.GetItem("/sitecore/content/blog2");
                var blog3 = db.GetItem("/sitecore/content/blog3");

                using (new MembershipSwitcher(membershipProvider))
                {
                    var user = Sitecore.Security.Accounts.User.FromName(_validUsername, true);

                    var authorizationProvider = Mock.Of<AuthorizationProvider>(x =>
                        x.GetAccess(blog1, user, AccessRight.ItemWrite) == new Sitecore.FakeDb.Security.AccessControl.DenyAccessResult() &&
                        x.GetAccess(blog2, user, AccessRight.ItemWrite) == new Sitecore.FakeDb.Security.AccessControl.DenyAccessResult() &&
                        x.GetAccess(blog3, user, AccessRight.ItemWrite) == new Sitecore.FakeDb.Security.AccessControl.DenyAccessResult()
                    );

                    using (new AuthorizationSwitcher(authorizationProvider))
                    {
                        var blogTemplate = blog1.Database.GetTemplate(blogTemplateId);

                        var linkDb = Mock.Of<LinkDatabase>(x =>
                        x.GetReferrers(blogTemplate) == new[]
                        {
                            new ItemLink("master", blog2Id, ID.Null, "master", blogTemplateId, blogTemplateId.ToString()),
                            new ItemLink("master", blog3Id, ID.Null, "master", blogTemplateId, blogTemplateId.ToString())
                        });

                        using (new LinkDatabaseSwitcher(linkDb))
                        {
                            var blogs = manager.GetUserBlogs(_validUsername);
                            var ids = from blog in blogs select blog.ID;

                            Assert.That(ids, Is.EquivalentTo(new[] { blog2Id, blog3Id }));
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public void GetCurrentBlog_NullItem()
        {
            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.BlogTemplateIds == new[] { ID.NewID }
            );

            var manager = new BlogManager(settings);
            var resultItem = manager.GetCurrentBlog(null);

            Assert.That(resultItem, Is.Null);
        }
Ejemplo n.º 10
0
        public void GetCurrentBlog_CustomTemplates(string startPath, string expectedPath)
        {
            var blogTemplateId = ID.NewID;
            var customBlogtemplateId = ID.NewID;
            var entryTemplateId = ID.NewID;
            var customEntryTemplateId = ID.NewID;

            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.BlogTemplateIds == new[] { ID.NewID, ID.NewID, blogTemplateId, ID.NewID } &&
                x.EntryTemplateIds == new[] { ID.NewID, entryTemplateId, ID.NewID }
            );

            using (var db = new Db
            {
                new DbTemplate(blogTemplateId),
                new DbTemplate(entryTemplateId),
                new DbTemplate(customBlogtemplateId)
                {
                    BaseIDs = new [] { blogTemplateId }
                },
                new DbTemplate(customEntryTemplateId)
                {
                    BaseIDs = new [] { entryTemplateId }
                },
                new DbItem("blog", ID.NewID, customBlogtemplateId)
                {
                    new DbItem("entries")
                    {
                        new DbItem("entry", ID.NewID, customEntryTemplateId)
                    }
                }
            })
            {
                var startItem = db.GetItem(startPath);
                var manager = new BlogManager(settings);
                var resultItem = manager.GetCurrentBlog(startItem);

                Assert.That(resultItem.ID, Is.EqualTo(resultItem.ID));
            };
        }
Ejemplo n.º 11
0
        public void GetCurrentBlog(string startPath, string expectedPath)
        {
            var blogTemplateId = ID.NewID;
            var entryTemplateId = ID.NewID;

            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.BlogTemplateIds == new[] { blogTemplateId } &&
                x.EntryTemplateIds == new[] { entryTemplateId }
            );

            using (var db = new Db
            {
                new DbItem("blog", ID.NewID, blogTemplateId)
                {
                    new DbItem("entries")
                    {
                        new DbItem("entry", ID.NewID, entryTemplateId)
                    }
                }
            })
            {
                var startItem = db.GetItem(startPath);
                var manager = new BlogManager(settings);
                var resultItem = manager.GetCurrentBlog(startItem);

                if(expectedPath == null)
                {
                    Assert.That(resultItem, Is.Null);
                }
                else
                {
                    Assert.That(resultItem.ID, Is.EqualTo(resultItem.ID));
                }
            };
        }
Ejemplo n.º 12
0
        public void GetAllBlogs_None()
        {
            var settings = Mock.Of<IWeBlogSettings>(x =>
                x.ContentRootPath == "/sitecore/content" &&
                x.BlogTemplateIds == new[] { ID.NewID }
            );

            var manager = new BlogManager(settings);

            using (var db = new Db())
            {
                var item = db.GetItem("/sitecore/content");
                var blogs = manager.GetAllBlogs(item.Database);

                Assert.That(blogs, Is.Empty);
            }
        }
Ejemplo n.º 13
0
        public void GetAllBlogs()
        {
          var blogs = new Mod.BlogManager().GetAllBlogs(null).Where(x => m_testContentRoot.Axes.IsAncestorOf(x));

          Assert.That(blogs.Select(x => x.ID), Is.EquivalentTo(new[]
          {
            m_blog1.ID,
            m_blog2.ID
          }));
        }