mirror of https://github.com/Squidex/squidex.git
35 changed files with 402 additions and 185 deletions
@ -0,0 +1,15 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.ExtractReferenceIds |
||||
|
{ |
||||
|
public enum Ids |
||||
|
{ |
||||
|
All, |
||||
|
ContentOnly |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Domain.Apps.Core.Apps; |
||||
|
using Squidex.Domain.Apps.Core.Contents; |
||||
|
using Squidex.Domain.Apps.Core.ExtractReferenceIds; |
||||
|
using Squidex.Domain.Apps.Core.Schemas; |
||||
|
using Squidex.Infrastructure; |
||||
|
using Squidex.Infrastructure.Json.Objects; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Operations.ExtractReferenceIds |
||||
|
{ |
||||
|
public class ReferenceFormattingTests |
||||
|
{ |
||||
|
private readonly LanguagesConfig languages = LanguagesConfig.English.Set(Language.DE); |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_format_data_with_reference_fields() |
||||
|
{ |
||||
|
var data = CreateData(); |
||||
|
|
||||
|
var schema = |
||||
|
new Schema("my-schema") |
||||
|
.AddString(1, "ref1", Partitioning.Invariant, |
||||
|
new StringFieldProperties { IsReferenceField = true }) |
||||
|
.AddString(2, "ref2", Partitioning.Invariant, |
||||
|
new StringFieldProperties { IsReferenceField = true }) |
||||
|
.AddString(3, "non-ref", Partitioning.Invariant); |
||||
|
|
||||
|
var formatted = data.FormatReferences(schema, languages); |
||||
|
|
||||
|
var expected = |
||||
|
JsonValue.Object() |
||||
|
.Add("en", "EN, 12") |
||||
|
.Add("de", "DE, 12"); |
||||
|
|
||||
|
Assert.Equal(expected, formatted); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_format_data_with_first_field_if_no_reference_field_defined() |
||||
|
{ |
||||
|
var data = CreateData(); |
||||
|
|
||||
|
var schema = |
||||
|
new Schema("my-schema") |
||||
|
.AddString(1, "ref1", Partitioning.Invariant) |
||||
|
.AddString(2, "ref2", Partitioning.Invariant) |
||||
|
.AddString(3, "non-ref", Partitioning.Invariant); |
||||
|
|
||||
|
var formatted = data.FormatReferences(schema, languages); |
||||
|
|
||||
|
var expected = |
||||
|
JsonValue.Object() |
||||
|
.Add("en", "EN") |
||||
|
.Add("de", "DE"); |
||||
|
|
||||
|
Assert.Equal(expected, formatted); |
||||
|
} |
||||
|
|
||||
|
private static NamedContentData CreateData() |
||||
|
{ |
||||
|
return new NamedContentData() |
||||
|
.AddField("ref1", |
||||
|
new ContentFieldData() |
||||
|
.AddValue("en", "EN") |
||||
|
.AddValue("de", "DE")) |
||||
|
.AddField("ref2", |
||||
|
new ContentFieldData() |
||||
|
.AddValue("iv", 12)) |
||||
|
.AddField("non-ref", |
||||
|
new ContentFieldData() |
||||
|
.AddValue("iv", "Ignored")); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue