2025-02-12 12:04:58 +01:00
|
|
|
using NUnit.Framework;
|
2025-10-08 08:27:01 +02:00
|
|
|
using Umbraco.Cms.Core;
|
2025-01-29 13:59:58 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
|
|
|
|
|
2025-03-21 18:02:31 +01:00
|
|
|
internal sealed class PublishedUrlInfoProviderTests : PublishedUrlInfoProviderTestsBase
|
2025-01-29 13:59:58 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Two_items_in_level_1_with_same_name_will_have_conflicting_routes()
|
|
|
|
|
{
|
|
|
|
|
// Create a second root
|
|
|
|
|
var secondRoot = ContentBuilder.CreateSimpleContent(ContentType, "Second Root", null);
|
2025-04-14 14:50:02 +02:00
|
|
|
var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.UtcNow.AddMinutes(-5), null);
|
2025-01-29 13:59:58 +01:00
|
|
|
ContentService.Save(secondRoot, -1, contentSchedule);
|
|
|
|
|
|
|
|
|
|
// Create a child of second root
|
|
|
|
|
var childOfSecondRoot = ContentBuilder.CreateSimpleContent(ContentType, Subpage.Name, secondRoot);
|
|
|
|
|
childOfSecondRoot.Key = new Guid("FF6654FB-BC68-4A65-8C6C-135567F50BD6");
|
|
|
|
|
ContentService.Save(childOfSecondRoot, -1, contentSchedule);
|
|
|
|
|
|
|
|
|
|
// Publish both the main root and the second root with descendants
|
2025-02-12 12:04:58 +01:00
|
|
|
ContentService.PublishBranch(Textpage, PublishBranchFilter.IncludeUnpublished, ["*"]);
|
|
|
|
|
ContentService.PublishBranch(secondRoot, PublishBranchFilter.IncludeUnpublished, ["*"]);
|
2025-01-29 13:59:58 +01:00
|
|
|
|
|
|
|
|
var subPageUrls = await PublishedUrlInfoProvider.GetAllAsync(Subpage);
|
|
|
|
|
var childOfSecondRootUrls = await PublishedUrlInfoProvider.GetAllAsync(childOfSecondRoot);
|
|
|
|
|
|
|
|
|
|
// Assert the url of subpage is correct
|
|
|
|
|
Assert.AreEqual(1, subPageUrls.Count);
|
2025-10-08 08:27:01 +02:00
|
|
|
Assert.IsNotNull(subPageUrls.First().Url);
|
|
|
|
|
Assert.AreEqual("/text-page-1/", subPageUrls.First().Url!.ToString());
|
|
|
|
|
Assert.AreEqual(Constants.UrlProviders.Content, subPageUrls.First().Provider);
|
2025-01-29 13:59:58 +01:00
|
|
|
Assert.AreEqual(Subpage.Key, DocumentUrlService.GetDocumentKeyByRoute("/text-page-1/", "en-US", null, false));
|
|
|
|
|
|
|
|
|
|
// Assert the url of child of second root is not exposed
|
|
|
|
|
Assert.AreEqual(1, childOfSecondRootUrls.Count);
|
2025-10-08 08:27:01 +02:00
|
|
|
Assert.IsNull(childOfSecondRootUrls.First().Url);
|
|
|
|
|
Assert.AreEqual(Constants.UrlProviders.Content, childOfSecondRootUrls.First().Provider);
|
2025-01-29 13:59:58 +01:00
|
|
|
|
|
|
|
|
// Ensure the url without hide top level is not finding the child of second root
|
|
|
|
|
Assert.AreNotEqual(childOfSecondRoot.Key, DocumentUrlService.GetDocumentKeyByRoute("/second-root/text-page-1/", "en-US", null, false));
|
|
|
|
|
}
|
|
|
|
|
}
|