-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/OrchardCore/OrchardCore.Abstractions/Localization/DataLocalizedString.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace OrchardCore.Localization | ||
{ | ||
public class DataLocalizedString | ||
{ | ||
public DataLocalizedString(string context, string name) | ||
{ | ||
Context = context; | ||
Name = name; | ||
} | ||
|
||
public string Context { get; } | ||
|
||
public string Name { get; } | ||
|
||
public override string ToString() => $"{Context}-{Name}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
test/OrchardCore.Tests/Modules/OrchardCore.Localization/LocalizationDataProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Moq; | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
using OrchardCore.ContentTypes.Services; | ||
using OrchardCore.ContentTypes.ViewModels; | ||
using Xunit; | ||
|
||
namespace OrchardCore.Tests.Modules.OrchardCore.Localization | ||
{ | ||
public class LocalizationDataProviderTests | ||
{ | ||
[Fact] | ||
public void ContentTypeDataLocalizationProvider_GetLocalizedStrings() | ||
{ | ||
var contentDefinitionService = new Mock<IContentDefinitionService>(); | ||
contentDefinitionService.Setup(cds => cds.GetTypes()) | ||
.Returns(() => new List<EditTypeViewModel> { | ||
new EditTypeViewModel { DisplayName = "Article" }, | ||
new EditTypeViewModel { DisplayName = "BlogPost" }, | ||
new EditTypeViewModel { DisplayName = "News" } | ||
}); | ||
var localizationDataProvider = new ContentTypeDataLocalizationProvider(contentDefinitionService.Object); | ||
var localizedStrings = localizationDataProvider.GetAllStrings(); | ||
|
||
Assert.Equal(3, localizedStrings.Count()); | ||
Assert.True(localizedStrings.All(s => s.Context == "Content Types")); | ||
} | ||
|
||
[Fact] | ||
public void ContentFieldDataLocalizationProvider_GetLocalizedStrings() | ||
{ | ||
var contentDefinitionService = new Mock<IContentDefinitionService>(); | ||
contentDefinitionService.Setup(cds => cds.GetTypes()) | ||
.Returns(() => new List<EditTypeViewModel> | ||
{ | ||
new EditTypeViewModel { DisplayName = "BlogPost", TypeDefinition = CreateContentTypeDefinition("BlogPost", "Blog Post", new [] { "Title", "Body", "Author" }) }, | ||
new EditTypeViewModel { DisplayName = "Person", TypeDefinition = CreateContentTypeDefinition("Person", "Person", new [] { "FirstName", "LastName" }) }, | ||
}); | ||
var localizationDataProvider = new ContentFieldDataLocalizationProvider(contentDefinitionService.Object); | ||
var localizedStrings = localizationDataProvider.GetAllStrings(); | ||
|
||
Assert.Equal(5, localizedStrings.Count()); | ||
Assert.True(localizedStrings.All(s => s.Context == "Content Fields")); | ||
} | ||
|
||
private ContentTypeDefinition CreateContentTypeDefinition(string name, string displayName, string[] fields) | ||
{ | ||
var contentPartFieldDefinitions = new List<ContentPartFieldDefinition>(); | ||
|
||
foreach (var field in fields) | ||
{ | ||
contentPartFieldDefinitions.Add(new ContentPartFieldDefinition(new ContentFieldDefinition("TextField"), field, null)); | ||
} | ||
|
||
return new ContentTypeDefinition( | ||
name, | ||
displayName, | ||
new List<ContentTypePartDefinition> { new ContentTypePartDefinition("Part", new ContentPartDefinition("Part", contentPartFieldDefinitions, null), null) }, | ||
null); | ||
} | ||
} | ||
} |