示例#1
0
		public void Should_Replace_Known_Tokens_When_Logged_In_As_Admin()
		{
			// Arrange
			string menuMarkup = "* %categories%\r\n\r\n%allpages%\r\n%mainpage%\r\n%newpage%\r\n%managefiles%\r\n%sitesettings%\r\n";
			string expectedHtml = "<ul><li><a href=\"/pages/alltags\">Categories</a></li></ul>" +
								  "<a href=\"/pages/allpages\">All pages</a>" +
								  "<a href=\"/\">Main Page</a>" +
								  "<a href=\"/pages/new\">New page</a>" +
								  "<a href=\"/filemanager\">Manage files</a>" +
								  "<a href=\"/settings\">Site settings</a>";

			RepositoryMock repository = new RepositoryMock();
			repository.SiteSettings = new SiteSettings();
			repository.SiteSettings.MarkupType = "Markdown";
			repository.SiteSettings.MenuMarkup = menuMarkup;

			UserContextStub userContext = new UserContextStub();
			userContext.IsAdmin = true;
			userContext.IsLoggedIn = true;

			ApplicationSettings applicationSettings = new ApplicationSettings();
			applicationSettings.Installed = true;
			CacheMock cache = new CacheMock();
			SiteCache siteCache = new SiteCache(applicationSettings, cache);

			MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
			MenuParser parser = new MenuParser(converter, repository, siteCache, userContext);

			// Act
			string actualHtml = parser.GetMenu();

			// Assert
			Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml);
		}
示例#2
0
		public void Setup()
		{
			_pluginFactory = new PluginFactoryMock();

			_pageRepository = new PageRepositoryMock();

			_settingsRepository = new SettingsRepositoryMock();
			_settingsRepository.SiteSettings = new SiteSettings();
			_settingsRepository.SiteSettings.MarkupType = "Markdown";

			_userContext = new UserContextStub();

			_applicationSettings = new ApplicationSettings();
			_applicationSettings.Installed = true;

			_cache = new CacheMock();
			_siteCache = new SiteCache(_cache);

			_converter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory);
			_menuParser = new MenuParser(_converter, _settingsRepository, _siteCache, _userContext);
		}
示例#3
0
        public void Should_Cache_Menu_Html_For_Admin_And_Editor_And_Guest_User()
        {
            // Arrange
            string menuMarkup = "My menu %newpage% %sitesettings%";

            RepositoryMock repository = new RepositoryMock();
            repository.SiteSettings = new SiteSettings();
            repository.SiteSettings.MarkupType = "Markdown";
            repository.SiteSettings.MenuMarkup = menuMarkup;

            UserContextStub userContext = new UserContextStub();
            ApplicationSettings applicationSettings = new ApplicationSettings();
            applicationSettings.Installed = true;

            CacheMock cache = new CacheMock();
            SiteCache siteCache = new SiteCache(applicationSettings, cache);

            MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
            MenuParser parser = new MenuParser(converter, repository, siteCache, userContext);

            // Act
            userContext.IsLoggedIn = false;
            userContext.IsAdmin = false;
            parser.GetMenu();

            userContext.IsLoggedIn = true;
            userContext.IsAdmin = false;
            parser.GetMenu();

            userContext.IsLoggedIn = true;
            userContext.IsAdmin = true;
            parser.GetMenu();

            // Assert
            Assert.That(cache.CacheItems.Count, Is.EqualTo(3));
        }
示例#4
0
        /// <summary>
        /// Retrieves the (usually left) menu containing the new page, settings etc. options
        /// </summary>
        public string GetBootStrapNavMenu(IUserContext userContext)
        {
            MenuParser parser = new MenuParser(_markupConverter, Repository, _siteCache, userContext);

            // TODO: turn this into a theme-based bit of template HTML
            StringBuilder builder = new StringBuilder();

            //builder.AppendLine("<nav id=\"leftmenu\" class=\"navbar navbar-default\" role=\"navigation\">");
            //builder.Append(GetCollapsableMenuHtml());

            //builder.AppendLine(@"<div id=""left-menu-toggle"" class=""collapse navbar-collapse"">");

            // Add bootstrap into the <ul>
            string menuHtml = parser.GetMenu();
            menuHtml = menuHtml.Replace("<ul>", "<ul class =\"nav navbar-nav\">");
            builder.AppendLine(menuHtml);

            //builder.AppendLine("</div>");
            //builder.AppendLine("</nav>");

            return builder.ToString();
        }
示例#5
0
        /// <summary>
        /// Retrieves the (usually left) menu containing the new page, settings etc. options
        /// </summary>
        public string GetMenu(IUserContext userContext)
        {
            MenuParser parser = new MenuParser(_markupConverter, Repository, _siteCache, userContext);

            // TODO: turn this into a theme-based bit of template HTML
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("<div id=\"leftmenu\">");
            builder.AppendLine(parser.GetMenu());
            builder.AppendLine("</div>");

            return builder.ToString();
        }
示例#6
0
		public void Should_Replace_Markdown_With_Internal_Link()
		{
			// Arrange
			string menuMarkup = "* [First link](my-page)\r\n";
			string expectedHtml = "<ul><li><a href=\"/wiki/1/my-page\">First link</a></li></ul>";

			RepositoryMock repository = new RepositoryMock();
			repository.AddNewPage(new Page() { Title = "my page", Id = 1 }, "text", "user", DateTime.Now);

			repository.SiteSettings = new SiteSettings();
			repository.SiteSettings.MarkupType = "Markdown";
			repository.SiteSettings.MenuMarkup = menuMarkup;

			UserContextStub userContext = new UserContextStub();
			ApplicationSettings applicationSettings = new ApplicationSettings();
			applicationSettings.Installed = true;

			CacheMock cache = new CacheMock();
			SiteCache siteCache = new SiteCache(applicationSettings, cache);

			MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
			MenuParser parser = new MenuParser(converter, repository, siteCache, userContext);

			// Act
			string actualHtml = parser.GetMenu();

			// Assert
			Assert.That(actualHtml, Is.EqualTo(expectedHtml));
		}
示例#7
0
		public void Should_Replace_Markdown_With_External_Link()
		{
			// Arrange
			string menuMarkup = "* [First link](http://www.google.com)\r\n";
			string expectedHtml = "<ul><li><a href=\"http://www.google.com\" rel=\"nofollow\" class=\"external-link\">First link</a></li></ul>";

			RepositoryMock repository = new RepositoryMock();
			repository.SiteSettings = new SiteSettings();
			repository.SiteSettings.MarkupType = "Markdown";
			repository.SiteSettings.MenuMarkup = menuMarkup;

			UserContextStub userContext = new UserContextStub();
			ApplicationSettings applicationSettings = new ApplicationSettings();
			applicationSettings.Installed = true;

			CacheMock cache = new CacheMock();
			SiteCache siteCache = new SiteCache(applicationSettings, cache);

			MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
			MenuParser parser = new MenuParser(converter, repository, siteCache, userContext);

			// Act
			string actualHtml = parser.GetMenu();

			// Assert
			Assert.That(actualHtml, Is.EqualTo(expectedHtml));
		}
示例#8
0
		public void Should_Return_Different_Menu_Html_For_Admin_And_Editor_And_Guest_User()
		{
			// Arrange
			string menuMarkup = "My menu %newpage% %sitesettings%";

			RepositoryMock repository = new RepositoryMock();
			repository.SiteSettings = new SiteSettings();
			repository.SiteSettings.MarkupType = "Markdown";
			repository.SiteSettings.MenuMarkup = menuMarkup;

			UserContextStub userContext = new UserContextStub();
			ApplicationSettings applicationSettings = new ApplicationSettings();
			applicationSettings.Installed = true;

			CacheMock cache = new CacheMock();
			SiteCache siteCache = new SiteCache(applicationSettings, cache);

			MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
			MenuParser parser = new MenuParser(converter, repository, siteCache, userContext);

			// Act
			userContext.IsLoggedIn = false;
			userContext.IsAdmin = false;
			string guestHtml = parser.GetMenu();

			userContext.IsLoggedIn = true;
			userContext.IsAdmin = false;
			string editorHtml = parser.GetMenu();

			userContext.IsLoggedIn = true;
			userContext.IsAdmin = true;
			string adminHtml = parser.GetMenu();

			// Assert
			Assert.That(guestHtml, Is.EqualTo("My menu"));
			Assert.That(editorHtml, Is.EqualTo("My menu <a href=\"/pages/new\">New page</a>"));
			Assert.That(adminHtml, Is.EqualTo("My menu <a href=\"/pages/new\">New page</a> <a href=\"/settings\">Site settings</a>"));
		}
示例#9
0
		public void Should_Remove_Empty_UL_Tags_For_Logged_In_Tokens_When_Not_Logged_In(string markupType, string expectedHtml)
		{
			// Arrange - \r\n is important so the markdown is valid
			string menuMarkup = "%mainpage%\r\n\r\n* %newpage%\r\n* %managefiles%\r\n* %sitesettings%\r\n";

			RepositoryMock repository = new RepositoryMock();
			repository.SiteSettings = new SiteSettings();
			repository.SiteSettings.MarkupType = markupType;
			repository.SiteSettings.MenuMarkup = menuMarkup;

			UserContextStub userContext = new UserContextStub();
			userContext.IsLoggedIn = false;

			ApplicationSettings applicationSettings = new ApplicationSettings();
			applicationSettings.Installed = true;
			CacheMock cache = new CacheMock();
			SiteCache siteCache = new SiteCache(applicationSettings, cache);

			MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
			MenuParser parser = new MenuParser(converter, repository, siteCache, userContext);

			// Act
			string actualHtml = parser.GetMenu();

			// Assert
			Assert.That(actualHtml, Is.EqualTo(expectedHtml));
		}