2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-08-26 09:55:14 +02:00
|
|
|
using System.Collections.Generic;
|
2020-08-27 11:31:46 +02:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2020-08-26 09:55:14 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-08-27 11:31:46 +02:00
|
|
|
using AutoFixture.NUnit3;
|
2020-08-26 09:55:14 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-08-27 11:31:46 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
2020-09-11 21:13:18 +02:00
|
|
|
using Microsoft.Extensions.Options;
|
2020-08-26 09:55:14 +02:00
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2021-09-10 09:25:56 +02:00
|
|
|
using Umbraco.Cms.Core;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Hosting;
|
2021-09-10 09:25:56 +02:00
|
|
|
using Umbraco.Cms.Core.Services;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Tests.UnitTests.AutoFixture;
|
|
|
|
|
using Umbraco.Cms.Web.BackOffice.Controllers;
|
2021-05-18 19:19:58 +02:00
|
|
|
using Umbraco.Cms.Web.BackOffice.Install;
|
2020-08-26 09:55:14 +02:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common
|
2020-08-26 09:55:14 +02:00
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2020-08-27 11:31:46 +02:00
|
|
|
internal class FileNameTests
|
2020-08-26 09:55:14 +02:00
|
|
|
{
|
2020-08-27 11:31:46 +02:00
|
|
|
private string GetViewName(ViewResult viewResult, string separator = "/")
|
2020-08-26 09:55:14 +02:00
|
|
|
{
|
2020-08-27 11:31:46 +02:00
|
|
|
var sections = viewResult.ViewName.Split(separator);
|
|
|
|
|
return sections[^1];
|
2020-08-26 09:55:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-27 11:31:46 +02:00
|
|
|
private IEnumerable<string> GetUiFiles(IEnumerable<string> pathFromNetCore)
|
2020-08-26 09:55:14 +02:00
|
|
|
{
|
2021-10-18 08:14:04 +01:00
|
|
|
var root = TestContext.CurrentContext.TestDirectory.Split("tests")[0];
|
|
|
|
|
var pathToFiles = Path.Combine(root, "src", "Umbraco.Web.UI");
|
2020-08-27 11:31:46 +02:00
|
|
|
foreach (var pathSection in pathFromNetCore)
|
2020-08-26 09:55:14 +02:00
|
|
|
{
|
|
|
|
|
pathToFiles = Path.Combine(pathToFiles, pathSection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new DirectoryInfo(pathToFiles).GetFiles().Select(f => f.Name).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 11:31:46 +02:00
|
|
|
[Test]
|
|
|
|
|
[AutoMoqData]
|
2020-08-26 09:55:14 +02:00
|
|
|
public async Task InstallViewExists(
|
|
|
|
|
[Frozen] IHostingEnvironment hostingEnvironment,
|
|
|
|
|
InstallController sut)
|
|
|
|
|
{
|
|
|
|
|
Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute(It.IsAny<string>())).Returns("http://localhost/");
|
|
|
|
|
var viewResult = await sut.Index() as ViewResult;
|
2020-08-27 11:31:46 +02:00
|
|
|
var fileName = GetViewName(viewResult, Path.DirectorySeparatorChar.ToString());
|
2020-08-26 09:55:14 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
IEnumerable<string> views = GetUiFiles(new[] { "umbraco", "UmbracoInstall" });
|
2020-08-26 09:55:14 +02:00
|
|
|
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 11:31:46 +02:00
|
|
|
[Test]
|
|
|
|
|
[AutoMoqData]
|
|
|
|
|
public void PreviewViewExists(
|
2020-09-14 14:12:38 +02:00
|
|
|
[Frozen] IOptions<GlobalSettings> globalSettings,
|
2020-08-26 09:55:14 +02:00
|
|
|
PreviewController sut)
|
|
|
|
|
{
|
2020-09-14 14:12:38 +02:00
|
|
|
globalSettings.Value.UmbracoPath = "/";
|
2020-08-26 09:55:14 +02:00
|
|
|
|
|
|
|
|
var viewResult = sut.Index() as ViewResult;
|
2020-08-27 11:31:46 +02:00
|
|
|
var fileName = GetViewName(viewResult);
|
2020-08-26 09:55:14 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
IEnumerable<string> views = GetUiFiles(new[] { "umbraco", "UmbracoBackOffice" });
|
2020-08-26 09:55:14 +02:00
|
|
|
|
|
|
|
|
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 11:31:46 +02:00
|
|
|
[Test]
|
|
|
|
|
[AutoMoqData]
|
2020-08-26 09:55:14 +02:00
|
|
|
public async Task BackOfficeDefaultExists(
|
2020-09-11 21:13:18 +02:00
|
|
|
[Frozen] IOptions<GlobalSettings> globalSettings,
|
2020-08-26 09:55:14 +02:00
|
|
|
[Frozen] IHostingEnvironment hostingEnvironment,
|
|
|
|
|
[Frozen] ITempDataDictionary tempDataDictionary,
|
2021-09-10 09:25:56 +02:00
|
|
|
[Frozen] IRuntimeState runtimeState,
|
2020-08-26 09:55:14 +02:00
|
|
|
BackOfficeController sut)
|
|
|
|
|
{
|
2020-09-11 21:13:18 +02:00
|
|
|
globalSettings.Value.UmbracoPath = "/";
|
2020-08-26 09:55:14 +02:00
|
|
|
Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute("/")).Returns("http://localhost/");
|
|
|
|
|
Mock.Get(hostingEnvironment).SetupGet(x => x.ApplicationVirtualPath).Returns("/");
|
2021-09-10 09:25:56 +02:00
|
|
|
Mock.Get(runtimeState).Setup(x => x.Level).Returns(RuntimeLevel.Run);
|
2020-08-26 09:55:14 +02:00
|
|
|
|
|
|
|
|
sut.TempData = tempDataDictionary;
|
|
|
|
|
|
|
|
|
|
var viewResult = await sut.Default() as ViewResult;
|
2020-08-27 11:31:46 +02:00
|
|
|
var fileName = GetViewName(viewResult);
|
2020-12-20 08:36:11 +01:00
|
|
|
IEnumerable<string> views = GetUiFiles(new[] { "umbraco", "UmbracoBackOffice" });
|
2020-08-26 09:55:14 +02:00
|
|
|
|
|
|
|
|
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void LanguageFilesAreLowercase()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IEnumerable<string> files = GetUiFiles(new[] { "umbraco", "config", "lang" });
|
2020-08-26 09:55:14 +02:00
|
|
|
foreach (var fileName in files)
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
Assert.AreEqual(
|
|
|
|
|
fileName.ToLower(),
|
|
|
|
|
fileName,
|
2020-08-27 11:31:46 +02:00
|
|
|
$"Language files must be all lowercase but {fileName} is not lowercase.");
|
2020-08-26 09:55:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|