Merge remote-tracking branch 'origin/v9/dev' into v10/dev

# Conflicts:
#	src/Umbraco.Core/Telemetry/TelemetryService.cs
#	src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs
#	src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs
#	src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs
#	src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs
#	src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs
#	src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
#	src/Umbraco.Web.BackOffice/Controllers/DashboardController.cs
#	tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/ScheduledPublishingTests.cs
This commit is contained in:
Bjarke Berg
2022-03-10 14:32:45 +01:00
277 changed files with 6647 additions and 3154 deletions

View File

@@ -25,6 +25,8 @@ context('Relation Types', () => {
cy.get('select[name="relationType-parent"]').select('Document');
cy.get('select[name="relationType-child"]').select('Media');
cy.get('[name="relationType-isdependency"]').last().click({force: true})
cy.get(".btn-primary").click();
});

View File

@@ -1,35 +0,0 @@
context('User Groups', () => {
beforeEach(() => {
cy.umbracoLogin(Cypress.env('username'), Cypress.env('password'));
});
it('Create user group', () => {
const name = "Test Group";
cy.umbracoEnsureUserGroupNameNotExists(name);
cy.umbracoSection('users');
cy.get('[data-element="sub-view-userGroups"]').click();
cy.umbracoButtonByLabelKey("actions_createGroup").click();
//Type name
cy.umbracoEditorHeaderName(name);
// Assign sections
cy.get('.umb-box:nth-child(1) .umb-property:nth-child(1) localize').click();
cy.get('.umb-tree-item__inner').click({multiple:true, timeout: 10000});
cy.get('.btn-success').last().click();
// Save
cy.get('.btn-success').click();
//Assert
cy.umbracoSuccessNotification().should('be.visible');
//Clean up
cy.umbracoEnsureUserGroupNameNotExists(name);
});
});

View File

@@ -0,0 +1,85 @@
/// <reference types="Cypress" />
import { UserGroupBuilder } from 'umbraco-cypress-testhelpers';
context('User Groups', () => {
function navigateToUserGroups() {
cy.umbracoSection('users');
cy.get('[data-element="sub-view-userGroups"]').click();
}
beforeEach(() => {
cy.umbracoLogin(Cypress.env('username'), Cypress.env('password'));
});
it('Create user group', () => {
const name = "Test Group";
cy.umbracoEnsureUserGroupNameNotExists(name);
navigateToUserGroups();
cy.umbracoButtonByLabelKey("actions_createGroup").click();
//Type name
cy.umbracoEditorHeaderName(name);
// Assign sections
cy.get('.umb-box:nth-child(1) .umb-property:nth-child(1) localize').click();
cy.get('.umb-tree-item__inner').click({multiple:true, timeout: 10000});
cy.get('.btn-success').last().click();
// Save
cy.get('.btn-success').click();
//Assert
cy.umbracoSuccessNotification().should('be.visible');
//Clean up
cy.umbracoEnsureUserGroupNameNotExists(name);
});
it('Can delete user group', () => {
// Create user group
const groupName = "Delete user group test"
cy.umbracoEnsureUserGroupNameNotExists(groupName);
const userGroup = new UserGroupBuilder()
.withName(groupName)
.build();
cy.saveUserGroup(userGroup);
navigateToUserGroups();
// Delete the user group
cy.get('.umb-table-body > :nth-child(2)').click();
cy.umbracoButtonByLabelKey("general_delete").click();
cy.get('umb-button[alias="overlaySubmit"]').click();
cy.umbracoSuccessNotification().should('be.visible');
cy.get('.umb-table-body').contains(groupName).should('not.exist');
cy.umbracoEnsureUserGroupNameNotExists(groupName);
});
it('Cannot delete required groups', () => {
navigateToUserGroups();
// There's not really a good way to be 100% sure we'll get the admin group, it should be first, but who knows
// so double check that we actually got the correct one
const administrators = cy.get('.umb-table-body > :nth-child(1)');
administrators.should('contain', 'Administrators');
administrators.click({force: true});
const sensitive = cy.get('.umb-table-body > :nth-child(3)');
sensitive.should('contain', 'Sensitive data');
sensitive.click({force: true});
const translators = cy.get('.umb-table-body > :nth-child(4)');
translators.should('contain', 'Translators');
translators.click({force: true});
// Now that we've clicked all that we shouldn't be able to delete, ensure that the delete button does not show up
cy.get('.umb-editor-sub-header').should('not.contain', 'Delete');
});
});

View File

@@ -1628,9 +1628,9 @@
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q=="
},
"umbraco-cypress-testhelpers": {
"version": "1.0.0-beta-63",
"resolved": "https://registry.npmjs.org/umbraco-cypress-testhelpers/-/umbraco-cypress-testhelpers-1.0.0-beta-63.tgz",
"integrity": "sha512-X+DHWktfB+WBb7YrxvpneVfS1PATx2zPYMdkeZTmtoQEeyGxXA9fW6P712/AUbyGAhRhH+46t4cAINdWJxItug==",
"version": "1.0.0-beta-66",
"resolved": "https://registry.npmjs.org/umbraco-cypress-testhelpers/-/umbraco-cypress-testhelpers-1.0.0-beta-66.tgz",
"integrity": "sha512-/Iq0P7rN9LfODO9snoLNqvbd8b432JIYtCVjYOdYZFceMAUIv0v2/6t7+N55Z7h8OpAQzcTLU3VCxfPzZp8wQw==",
"dev": true,
"requires": {
"camelize": "^1.0.0",

View File

@@ -14,7 +14,7 @@
"del": "^6.0.0",
"ncp": "^2.0.0",
"prompt": "^1.2.0",
"umbraco-cypress-testhelpers": "^1.0.0-beta-63"
"umbraco-cypress-testhelpers": "^1.0.0-beta-65"
},
"dependencies": {
"typescript": "^3.9.2"

View File

@@ -8,7 +8,7 @@ using Umbraco.Cms.Tests.Common.Builders.Interfaces;
namespace Umbraco.Cms.Tests.Common.Builders
{
public class RelationTypeBuilder
: ChildBuilderBase<RelationBuilder, IRelationType>,
: ChildBuilderBase<RelationBuilder, IRelationTypeWithIsDependency>,
IWithIdBuilder,
IWithAliasBuilder,
IWithNameBuilder,
@@ -23,6 +23,7 @@ namespace Umbraco.Cms.Tests.Common.Builders
private DateTime? _deleteDate;
private int? _id;
private bool? _isBidirectional;
private bool? _isDependency;
private Guid? _key;
private string _name;
private Guid? _parentObjectType;
@@ -42,6 +43,12 @@ namespace Umbraco.Cms.Tests.Common.Builders
{
_isBidirectional = isBidirectional;
return this;
}
public RelationTypeBuilder WithIsDependency(bool isDependency)
{
_isDependency = isDependency;
return this;
}
public RelationTypeBuilder WithChildObjectType(Guid childObjectType)
@@ -56,7 +63,7 @@ namespace Umbraco.Cms.Tests.Common.Builders
return this;
}
public override IRelationType Build()
public override IRelationTypeWithIsDependency Build()
{
var alias = _alias ?? Guid.NewGuid().ToString();
var name = _name ?? Guid.NewGuid().ToString();
@@ -65,11 +72,12 @@ namespace Umbraco.Cms.Tests.Common.Builders
var id = _id ?? 0;
Guid key = _key ?? Guid.NewGuid();
var isBidirectional = _isBidirectional ?? false;
var isDependency = _isDependency ?? false;
DateTime createDate = _createDate ?? DateTime.Now;
DateTime updateDate = _updateDate ?? DateTime.Now;
DateTime? deleteDate = _deleteDate ?? null;
return new RelationType(name, alias, isBidirectional, parentObjectType, childObjectType)
return new RelationType(name, alias, isBidirectional, parentObjectType, childObjectType, isDependency)
{
Id = id,
Key = key,

View File

@@ -190,23 +190,23 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
// Get parent entities for child id
var parents = repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 11, out long totalRecords).ToList();
Assert.AreEqual(6, totalRecords);
Assert.AreEqual(6, parents.Count);
Assert.AreEqual(9, totalRecords);
Assert.AreEqual(9, parents.Count);
// add the next page
// Add the next page
parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 1, 11, out totalRecords));
Assert.AreEqual(6, totalRecords);
Assert.AreEqual(6, parents.Count);
Assert.AreEqual(9, totalRecords);
Assert.AreEqual(9, parents.Count);
var contentEntities = parents.OfType<IDocumentEntitySlim>().ToList();
var mediaEntities = parents.OfType<IMediaEntitySlim>().ToList();
var memberEntities = parents.OfType<IMemberEntitySlim>().ToList();
Assert.AreEqual(3, contentEntities.Count);
Assert.AreEqual(0, mediaEntities.Count);
Assert.AreEqual(3, mediaEntities.Count);
Assert.AreEqual(3, memberEntities.Count);
// only of a certain type
// Only of a certain type
parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Document.GetGuid()));
Assert.AreEqual(3, totalRecords);
@@ -214,7 +214,32 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
Assert.AreEqual(3, totalRecords);
parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Media.GetGuid()));
Assert.AreEqual(0, totalRecords);
Assert.AreEqual(3, totalRecords);
// Test relations on content
var contentParents = repository.GetPagedParentEntitiesByChildId(createdContent[0].Id, 0, int.MaxValue, out totalRecords).ToList();
Assert.AreEqual(6, totalRecords);
Assert.AreEqual(6, contentParents.Count);
// Test getting relations of specified relation types
var relatedMediaRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);
var relatedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedDocumentAlias);
parents = repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 11, out totalRecords, new int[] { relatedContentRelType.Id, relatedMediaRelType.Id }).ToList();
Assert.AreEqual(6, totalRecords);
Assert.AreEqual(6, parents.Count);
parents = repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 1, 11, out totalRecords, new int[] { relatedContentRelType.Id, relatedMediaRelType.Id }).ToList();
Assert.AreEqual(6, totalRecords);
Assert.AreEqual(0, parents.Count);
parents = repository.GetPagedParentEntitiesByChildId(createdContent[0].Id, 0, 6, out totalRecords, new int[] { relatedContentRelType.Id, relatedMediaRelType.Id }).ToList();
Assert.AreEqual(3, totalRecords);
Assert.AreEqual(3, parents.Count);
parents = repository.GetPagedParentEntitiesByChildId(createdContent[0].Id, 1, 6, out totalRecords, new int[] { relatedContentRelType.Id, relatedMediaRelType.Id }).ToList();
Assert.AreEqual(3, totalRecords);
Assert.AreEqual(0, parents.Count);
}
}
@@ -256,19 +281,19 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
// Get parent entities for child id
var parents = repository.GetPagedChildEntitiesByParentId(createdContent[0].Id, 0, 6, out long totalRecords).ToList();
Assert.AreEqual(3, totalRecords);
Assert.AreEqual(3, parents.Count);
Assert.AreEqual(6, totalRecords);
Assert.AreEqual(6, parents.Count);
// add the next page
// Add the next page
parents.AddRange(repository.GetPagedChildEntitiesByParentId(createdContent[0].Id, 1, 6, out totalRecords));
Assert.AreEqual(3, totalRecords);
Assert.AreEqual(3, parents.Count);
Assert.AreEqual(6, totalRecords);
Assert.AreEqual(6, parents.Count);
var contentEntities = parents.OfType<IDocumentEntitySlim>().ToList();
var mediaEntities = parents.OfType<IMediaEntitySlim>().ToList();
var memberEntities = parents.OfType<IMemberEntitySlim>().ToList();
Assert.AreEqual(0, contentEntities.Count);
Assert.AreEqual(3, contentEntities.Count);
Assert.AreEqual(3, mediaEntities.Count);
Assert.AreEqual(0, memberEntities.Count);
@@ -281,6 +306,18 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
parents.AddRange(repository.GetPagedChildEntitiesByParentId(createdContent[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Member.GetGuid()));
Assert.AreEqual(0, totalRecords);
// Test getting relations of specified relation types
IRelationType relatedMediaRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);
IRelationType relatedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedDocumentAlias);
parents = repository.GetPagedChildEntitiesByParentId(createdContent[0].Id, 0, 6, out totalRecords, new int[] { relatedContentRelType.Id, relatedMediaRelType.Id }).ToList();
Assert.AreEqual(3, totalRecords);
Assert.AreEqual(3, parents.Count);
parents = repository.GetPagedChildEntitiesByParentId(createdContent[0].Id, 1, 6, out totalRecords, new int[] { relatedContentRelType.Id, relatedMediaRelType.Id }).ToList();
Assert.AreEqual(3, totalRecords);
Assert.AreEqual(0, parents.Count);
}
}
@@ -297,6 +334,15 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
createdContent.Add(c1);
}
// Create related content
var relatedContent = new List<IContent>();
for (int i = 0; i < 3; i++)
{
Content c1 = ContentBuilder.CreateBasicContent(contentType);
ContentService.Save(c1);
relatedContent.Add(c1);
}
// Create media
createdMedia = new List<IMedia>();
MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage");
@@ -314,14 +360,24 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
createdMembers = MemberBuilder.CreateSimpleMembers(memberType, 3).ToList();
GetMemberService().Save(createdMembers);
IRelationType relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);
IRelationType relatedMediaRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);
IRelationType relatedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedDocumentAlias);
// Relate content to media
foreach (IContent content in createdContent)
{
foreach (IMedia media in createdMedia)
{
RelationService.Relate(content.Id, media.Id, relType);
RelationService.Relate(content.Id, media.Id, relatedMediaRelType);
}
}
// Relate content to content
foreach (IContent relContent in relatedContent)
{
foreach (IContent content in createdContent)
{
RelationService.Relate(relContent.Id, content.Id, relatedContentRelType);
}
}
@@ -330,7 +386,67 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
{
foreach (IMedia media in createdMedia)
{
RelationService.Relate(member.Id, media.Id, relType);
RelationService.Relate(member.Id, media.Id, relatedMediaRelType);
}
}
// Create copied content
var copiedContent = new List<IContent>();
for (int i = 0; i < 3; i++)
{
Content c1 = ContentBuilder.CreateBasicContent(contentType);
ContentService.Save(c1);
copiedContent.Add(c1);
}
IRelationType copiedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias);
// Relate content to content (mimics copy)
foreach (IContent content in createdContent)
{
foreach (IContent cpContent in copiedContent)
{
RelationService.Relate(content.Id, cpContent.Id, copiedContentRelType);
}
}
// Create trashed content
var trashedContent = new List<IContent>();
for (int i = 0; i < 3; i++)
{
Content c1 = ContentBuilder.CreateBasicContent(contentType);
ContentService.Save(c1);
trashedContent.Add(c1);
}
IRelationType trashedRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias);
// Relate to trashed content
foreach (IContent trContent in trashedContent)
{
foreach (IContent content in createdContent)
{
RelationService.Relate(trContent.Id, content.Id, trashedRelType);
}
}
// Create trashed media
var trashedMedia = new List<IMedia>();
for (int i = 0; i < 3; i++)
{
Media m1 = MediaBuilder.CreateMediaImage(imageType, -1);
MediaService.Save(m1);
trashedMedia.Add(m1);
}
IRelationType trashedMediaRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias);
// Relate to trashed media
foreach (IMedia trMedia in trashedMedia)
{
foreach (IMedia media in createdMedia)
{
RelationService.Relate(trMedia.Id, media.Id, trashedMediaRelType);
}
}
}
@@ -418,14 +534,16 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
"relateContentOnCopy",
true,
Constants.ObjectTypes.Document,
new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972"));
new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972"),
false);
_relateContentType = new RelationType(
"Relate ContentType on Copy",
"relateContentTypeOnCopy",
true,
Constants.ObjectTypes.DocumentType,
new Guid("A2CB7800-F571-4787-9638-BC48539A0EFB"));
new Guid("A2CB7800-F571-4787-9638-BC48539A0EFB"),
false);
using (IScope scope = ScopeProvider.CreateScope())
{

View File

@@ -37,7 +37,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
RelationTypeRepository repository = CreateRepository(provider);
// Act
var relateMemberToContent = new RelationType("Relate Member to Content", "relateMemberToContent", true, Constants.ObjectTypes.Member, Constants.ObjectTypes.Document);
var relateMemberToContent = new RelationType("Relate Member to Content", "relateMemberToContent", true, Constants.ObjectTypes.Member, Constants.ObjectTypes.Document, true);
repository.Save(relateMemberToContent);
@@ -102,12 +102,13 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
RelationTypeRepository repository = CreateRepository(provider);
// Act
IRelationType relationType = repository.Get(8);
var relationType = repository.Get(8) as IRelationTypeWithIsDependency;
// Assert
Assert.That(relationType, Is.Not.Null);
Assert.That(relationType.HasIdentity, Is.True);
Assert.That(relationType.IsBidirectional, Is.True);
Assert.That(relationType.IsDependency, Is.True);
Assert.That(relationType.Alias, Is.EqualTo("relateContentToMedia"));
Assert.That(relationType.Name, Is.EqualTo("Relate Content to Media"));
Assert.That(relationType.ChildObjectType, Is.EqualTo(Constants.ObjectTypes.Media));
@@ -216,9 +217,9 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
public void CreateTestData()
{
var relateContent = new RelationType("Relate Content on Copy", "relateContentOnCopy", true, Constants.ObjectTypes.Document, Constants.ObjectTypes.Document);
var relateContentType = new RelationType("Relate ContentType on Copy", "relateContentTypeOnCopy", true, Constants.ObjectTypes.DocumentType, Constants.ObjectTypes.DocumentType);
var relateContentMedia = new RelationType("Relate Content to Media", "relateContentToMedia", true, Constants.ObjectTypes.Document, Constants.ObjectTypes.Media);
var relateContent = new RelationType("Relate Content on Copy", "relateContentOnCopy", true, Constants.ObjectTypes.Document, Constants.ObjectTypes.Document, false);
var relateContentType = new RelationType("Relate ContentType on Copy", "relateContentTypeOnCopy", true, Constants.ObjectTypes.DocumentType, Constants.ObjectTypes.DocumentType, false);
var relateContentMedia = new RelationType("Relate Content to Media", "relateContentToMedia", true, Constants.ObjectTypes.Document, Constants.ObjectTypes.Media, true);
IScopeProvider provider = ScopeProvider;
using (IScope scope = provider.CreateScope())

View File

@@ -1977,7 +1977,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services
UserService.Save(admin);
RelationService.Save(new RelationType("test", "test", false, Constants.ObjectTypes.Document,
Constants.ObjectTypes.Document));
Constants.ObjectTypes.Document, false));
Assert.IsNotNull(RelationService.Relate(content1, content2, "test"));
PublicAccessService.Save(new PublicAccessEntry(content1, content2, content2,

View File

@@ -266,4 +266,4 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services
// TODO: Create a relation for entities of the wrong Entity Type (GUID) based on the Relation Type's defined parent/child object types
}
}
}

View File

@@ -1,6 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using Microsoft.Extensions.Options;
using NUnit.Framework;
using Umbraco.Cms.Core.Configuration.Models;
@@ -15,7 +16,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Validati
public void Returns_Success_ForValid_Configuration()
{
var validator = new GlobalSettingsValidator();
GlobalSettings options = BuildGlobalSettings();
var options = new GlobalSettings();
ValidateOptionsResult result = validator.Validate("settings", options);
Assert.True(result.Succeeded);
}
@@ -24,18 +25,55 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Validati
public void Returns_Fail_For_Configuration_With_Invalid_SmtpFrom_Field()
{
var validator = new GlobalSettingsValidator();
GlobalSettings options = BuildGlobalSettings(smtpEmail: "invalid");
var options = new GlobalSettings
{
Smtp = new SmtpSettings
{
From = "invalid",
}
};
ValidateOptionsResult result = validator.Validate("settings", options);
Assert.False(result.Succeeded);
}
private static GlobalSettings BuildGlobalSettings(string smtpEmail = "test@test.com") =>
new GlobalSettings
[Test]
public void Returns_Fail_For_Configuration_With_Insufficient_SqlWriteLockTimeOut()
{
var validator = new GlobalSettingsValidator();
var options = new GlobalSettings
{
Smtp = new SmtpSettings
{
From = smtpEmail,
}
SqlWriteLockTimeOut = TimeSpan.Parse("00:00:00.099")
};
ValidateOptionsResult result = validator.Validate("settings", options);
Assert.False(result.Succeeded);
}
[Test]
public void Returns_Fail_For_Configuration_With_Excessive_SqlWriteLockTimeOut()
{
var validator = new GlobalSettingsValidator();
var options = new GlobalSettings
{
SqlWriteLockTimeOut = TimeSpan.Parse("00:00:21")
};
ValidateOptionsResult result = validator.Validate("settings", options);
Assert.False(result.Succeeded);
}
[Test]
public void Returns_Success_For_Configuration_With_Valid_SqlWriteLockTimeOut()
{
var validator = new GlobalSettingsValidator();
var options = new GlobalSettings
{
SqlWriteLockTimeOut = TimeSpan.Parse("00:00:20")
};
ValidateOptionsResult result = validator.Validate("settings", options);
Assert.True(result.Succeeded);
}
}
}

View File

@@ -0,0 +1,105 @@
using System.Linq;
using NUnit.Framework;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Tests.Common.Builders;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models
{
[TestFixture]
public class ContentTypeHistoryCleanupTests
{
[Test]
public void Changing_Keep_all_Makes_ContentType_Dirty()
{
var contentType = ContentTypeBuilder.CreateBasicContentType();
Assert.IsFalse(contentType.IsDirty());
var newValue = 2;
contentType.HistoryCleanup.KeepAllVersionsNewerThanDays = newValue;
Assert.IsTrue(contentType.IsDirty());
Assert.AreEqual(newValue, contentType.HistoryCleanup.KeepAllVersionsNewerThanDays);
}
[Test]
public void Changing_Keep_latest_Makes_ContentType_Dirty()
{
var contentType = ContentTypeBuilder.CreateBasicContentType();
Assert.IsFalse(contentType.IsDirty());
var newValue = 2;
contentType.HistoryCleanup.KeepLatestVersionPerDayForDays = newValue;
Assert.IsTrue(contentType.IsDirty());
Assert.AreEqual(newValue, contentType.HistoryCleanup.KeepLatestVersionPerDayForDays);
}
[Test]
public void Changing_Prevent_Cleanup_Makes_ContentType_Dirty()
{
var contentType = ContentTypeBuilder.CreateBasicContentType();
Assert.IsFalse(contentType.IsDirty());
var newValue = true;
contentType.HistoryCleanup.PreventCleanup = newValue;
Assert.IsTrue(contentType.IsDirty());
Assert.AreEqual(newValue, contentType.HistoryCleanup.PreventCleanup);
}
[Test]
public void Replacing_History_Cleanup_Registers_As_Dirty()
{
var contentType = ContentTypeBuilder.CreateBasicContentType();
Assert.IsFalse(contentType.IsDirty());
contentType.HistoryCleanup = new HistoryCleanup();
Assert.IsTrue(contentType.IsDirty());
Assert.IsTrue(contentType.IsPropertyDirty(nameof(contentType.HistoryCleanup)));
}
[Test]
public void Replacing_History_Cleanup_Removes_Old_Dirty_History_Properties()
{
var contentType = ContentTypeBuilder.CreateBasicContentType();
contentType.Alias = "NewValue";
contentType.HistoryCleanup.KeepAllVersionsNewerThanDays = 2;
contentType.PropertyChanged += (sender, args) =>
{
// Ensure that property changed is only invoked for history cleanup
Assert.AreEqual(nameof(contentType.HistoryCleanup), args.PropertyName);
};
// Since we're replacing the entire HistoryCleanup the changed property is no longer dirty, the entire HistoryCleanup is
contentType.HistoryCleanup = new HistoryCleanup();
Assert.Multiple(() =>
{
Assert.IsTrue(contentType.IsDirty());
Assert.IsFalse(contentType.WasDirty());
Assert.AreEqual(2, contentType.GetDirtyProperties().Count());
Assert.IsTrue(contentType.IsPropertyDirty(nameof(contentType.HistoryCleanup)));
Assert.IsTrue(contentType.IsPropertyDirty(nameof(contentType.Alias)));
});
}
[Test]
public void Old_History_Cleanup_Reference_Doesnt_Make_Content_Type_Dirty()
{
var contentType = ContentTypeBuilder.CreateBasicContentType();
var oldHistoryCleanup = contentType.HistoryCleanup;
contentType.HistoryCleanup = new HistoryCleanup();
contentType.ResetDirtyProperties();
contentType.ResetWereDirtyProperties();
oldHistoryCleanup.KeepAllVersionsNewerThanDays = 2;
Assert.IsFalse(contentType.IsDirty());
Assert.IsFalse(contentType.WasDirty());
}
}
}

View File

@@ -0,0 +1,77 @@
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Telemetry;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Telemetry
{
[TestFixture]
public class SiteIdentifierServiceTests
{
[TestCase("0F1785C5-7BA0-4C52-AB62-863BD2C8F3FE", true)]
[TestCase("This is not a guid", false)]
[TestCase("", false)]
[TestCase("00000000-0000-0000-0000-000000000000", false)] // Don't count empty GUID as valid
public void TryGetOnlyPassesIfValidId(string guidString, bool shouldSucceed)
{
var globalSettings = CreateGlobalSettings(guidString);
var sut = new SiteIdentifierService(
globalSettings,
Mock.Of<IConfigManipulator>(),
Mock.Of<ILogger<SiteIdentifierService>>());
var result = sut.TryGetSiteIdentifier(out var siteIdentifier);
Assert.AreEqual(shouldSucceed, result);
if (shouldSucceed)
{
// When toString is called on a GUID it will to lower, so do the same to our guidString
Assert.AreEqual(guidString.ToLower(), siteIdentifier.ToString());
}
else
{
Assert.AreEqual(Guid.Empty, siteIdentifier);
}
}
[TestCase("0F1785C5-7BA0-4C52-AB62-863BD2C8F3FE", false)]
[TestCase("This is not a guid", true)]
[TestCase("", true)]
[TestCase("00000000-0000-0000-0000-000000000000", true)] // Don't count empty GUID as valid
public void TryGetOrCreateOnlyCreatesNewGuidIfCurrentIsMissingOrInvalid(string guidString, bool shouldCreate)
{
var globalSettings = CreateGlobalSettings(guidString);
var configManipulatorMock = new Mock<IConfigManipulator>();
var sut = new SiteIdentifierService(
globalSettings,
configManipulatorMock.Object,
Mock.Of<ILogger<SiteIdentifierService>>());
var result = sut.TryGetOrCreateSiteIdentifier(out var identifier);
if (shouldCreate)
{
configManipulatorMock.Verify(x => x.SetGlobalId(It.IsAny<string>()), Times.Once);
Assert.AreNotEqual(Guid.Empty, identifier);
Assert.IsTrue(result);
}
else
{
configManipulatorMock.Verify(x => x.SetGlobalId(It.IsAny<string>()), Times.Never());
Assert.AreEqual(guidString.ToLower(), identifier.ToString());
Assert.IsTrue(result);
}
}
private IOptionsMonitor<GlobalSettings> CreateGlobalSettings(string guidString)
{
var globalSettings = new GlobalSettings { Id = guidString };
return Mock.Of<IOptionsMonitor<GlobalSettings>>(x => x.CurrentValue == globalSettings);
}
}
}

View File

@@ -15,36 +15,36 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Telemetry
[TestFixture]
public class TelemetryServiceTests
{
[TestCase("0F1785C5-7BA0-4C52-AB62-863BD2C8F3FE", true)]
[TestCase("This is not a guid", false)]
[TestCase("", false)]
public void OnlyParsesIfValidId(string guidString, bool shouldSucceed)
[Test]
public void UsesGetOrCreateSiteId()
{
var globalSettings = CreateGlobalSettings(guidString);
var version = CreateUmbracoVersion(9, 1, 1);
var sut = new TelemetryService(globalSettings, Mock.Of<IManifestParser>(), version);
var version = CreateUmbracoVersion(9, 3, 1);
var siteIdentifierServiceMock = new Mock<ISiteIdentifierService>();
var sut = new TelemetryService(Mock.Of<IManifestParser>(), version, siteIdentifierServiceMock.Object);
Guid guid;
var result = sut.TryGetTelemetryReportData(out var telemetryReportData);
siteIdentifierServiceMock.Verify(x => x.TryGetOrCreateSiteIdentifier(out guid), Times.Once);
}
[Test]
public void SkipsIfCantGetOrCreateId()
{
var version = CreateUmbracoVersion(9, 3, 1);
var sut = new TelemetryService(Mock.Of<IManifestParser>(), version, createSiteIdentifierService(false));
var result = sut.TryGetTelemetryReportData(out var telemetry);
Assert.AreEqual(shouldSucceed, result);
if (shouldSucceed)
{
// When toString is called on a GUID it will to lower, so do the same to our guidString
Assert.AreEqual(guidString.ToLower(), telemetry.Id.ToString());
}
else
{
Assert.IsNull(telemetry);
}
Assert.IsFalse(result);
Assert.IsNull(telemetry);
}
[Test]
public void ReturnsSemanticVersionWithoutBuild()
{
var globalSettings = CreateGlobalSettings();
var version = CreateUmbracoVersion(9, 1, 1, "-rc", "-ad2f4k2d");
var sut = new TelemetryService(globalSettings, Mock.Of<IManifestParser>(), version);
var sut = new TelemetryService(Mock.Of<IManifestParser>(), version, createSiteIdentifierService());
var result = sut.TryGetTelemetryReportData(out var telemetry);
@@ -55,7 +55,6 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Telemetry
[Test]
public void CanGatherPackageTelemetry()
{
var globalSettings = CreateGlobalSettings();
var version = CreateUmbracoVersion(9, 1, 1);
var versionPackageName = "VersionPackage";
var packageVersion = "1.0.0";
@@ -66,7 +65,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Telemetry
new () { PackageName = noVersionPackageName }
};
var manifestParser = CreateManifestParser(manifests);
var sut = new TelemetryService(globalSettings, manifestParser, version);
var sut = new TelemetryService(manifestParser, version, createSiteIdentifierService());
var success = sut.TryGetTelemetryReportData(out var telemetry);
@@ -87,15 +86,14 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Telemetry
[Test]
public void RespectsAllowPackageTelemetry()
{
var globalSettings = CreateGlobalSettings();
var version = CreateUmbracoVersion(9, 1, 1);
PackageManifest[] manifests =
{
new () { PackageName = "DoNotTrack", AllowPackageTelemetry = false },
new () { PackageName = "TrackingAllowed", AllowPackageTelemetry = true }
new () { PackageName = "TrackingAllowed", AllowPackageTelemetry = true },
};
var manifestParser = CreateManifestParser(manifests);
var sut = new TelemetryService(globalSettings, manifestParser, version);
var sut = new TelemetryService(manifestParser, version, createSiteIdentifierService());
var success = sut.TryGetTelemetryReportData(out var telemetry);
@@ -121,15 +119,12 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Telemetry
return Mock.Of<IUmbracoVersion>(x => x.SemanticVersion == version);
}
private IOptionsMonitor<GlobalSettings> CreateGlobalSettings(string guidString = null)
private ISiteIdentifierService createSiteIdentifierService(bool shouldSucceed = true)
{
if (guidString is null)
{
guidString = Guid.NewGuid().ToString();
}
var globalSettings = new GlobalSettings { Id = guidString };
return Mock.Of<IOptionsMonitor<GlobalSettings>>(x => x.CurrentValue == globalSettings);
var mock = new Mock<ISiteIdentifierService>();
var siteIdentifier = shouldSucceed ? Guid.NewGuid() : Guid.Empty;
mock.Setup(x => x.TryGetOrCreateSiteIdentifier(out siteIdentifier)).Returns(shouldSucceed);
return mock.Object;
}
}
}

View File

@@ -113,7 +113,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
var mockScopeProvider = new Mock<IScopeProvider>();
mockScopeProvider
.Setup(x => x.CreateScope(It.IsAny<IsolationLevel>(), It.IsAny<RepositoryCacheMode>(), It.IsAny<IScopedNotificationPublisher>(), It.IsAny<bool?>(), It.IsAny<bool>(), It.IsAny<bool>()))
.Setup(x => x.CreateScope(It.IsAny<IsolationLevel>(), It.IsAny<RepositoryCacheMode>(), It.IsAny<IEventDispatcher>(), It.IsAny<IScopedNotificationPublisher>(), It.IsAny<bool?>(), It.IsAny<bool>(), It.IsAny<bool>()))
.Returns(Mock.Of<IScope>());
return new ScheduledPublishing(

View File

@@ -44,6 +44,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Tests.Common.Builders
.WithAlias(relationTypeAlias)
.WithName(relationTypeName)
.WithIsBidirectional(false)
.WithIsDependency(true)
.WithParentObjectType(parentObjectType)
.WithChildObjectType(childObjectType)
.Done()
@@ -61,6 +62,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Tests.Common.Builders
Assert.AreEqual(relationTypeAlias, relation.RelationType.Alias);
Assert.AreEqual(relationTypeName, relation.RelationType.Name);
Assert.IsFalse(relation.RelationType.IsBidirectional);
Assert.IsTrue((relation.RelationType as IRelationTypeWithIsDependency).IsDependency);
Assert.AreEqual(parentObjectType, relation.RelationType.ParentObjectType);
Assert.AreEqual(childObjectType, relation.RelationType.ChildObjectType);
}

View File

@@ -26,11 +26,12 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Tests.Common.Builders
var parentObjectType = Guid.NewGuid();
var childObjectType = Guid.NewGuid();
const bool isBidirectional = true;
const bool isDependency = true;
var builder = new RelationTypeBuilder();
// Act
IRelationType relationType = builder
var relationType = builder
.WithId(id)
.WithAlias(alias)
.WithName(name)
@@ -41,6 +42,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Tests.Common.Builders
.WithParentObjectType(parentObjectType)
.WithChildObjectType(childObjectType)
.WithIsBidirectional(isBidirectional)
.WithIsDependency(isDependency)
.Build();
// Assert
@@ -54,6 +56,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Tests.Common.Builders
Assert.AreEqual(parentObjectType, relationType.ParentObjectType);
Assert.AreEqual(childObjectType, relationType.ChildObjectType);
Assert.AreEqual(isBidirectional, relationType.IsBidirectional);
Assert.AreEqual(isDependency, relationType.IsDependency);
}
}
}

View File

@@ -0,0 +1,44 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Microsoft.AspNetCore.Authentication;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Web.BackOffice.Security;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Security
{
[TestFixture]
public class BackOfficeAuthenticationBuilderTests
{
[Test]
public void EnsureBackOfficeScheme_When_Backoffice_Auth_Scheme_Expect_Updated_SignInScheme()
{
var scheme = $"{Constants.Security.BackOfficeExternalAuthenticationTypePrefix}test";
var options = new RemoteAuthenticationOptions
{
SignInScheme = "my_cookie"
};
var sut = new BackOfficeAuthenticationBuilder.EnsureBackOfficeScheme<RemoteAuthenticationOptions>();
sut.PostConfigure(scheme, options);
Assert.AreEqual(options.SignInScheme, Constants.Security.BackOfficeExternalAuthenticationType);
}
[Test]
public void EnsureBackOfficeScheme_When_Not_Backoffice_Auth_Scheme_Expect_No_Change()
{
var scheme = "test";
var options = new RemoteAuthenticationOptions
{
SignInScheme = "my_cookie"
};
var sut = new BackOfficeAuthenticationBuilder.EnsureBackOfficeScheme<RemoteAuthenticationOptions>();
sut.PostConfigure(scheme, options);
Assert.AreNotEqual(options.SignInScheme, Constants.Security.BackOfficeExternalAuthenticationType);
}
}
}