Esempio n. 1
0
        private IEnumerable<FieldConverter> GenerateConverters(QueryContext context, bool checkType)
        {
            if (!context.IsFrontendClient)
            {
                yield return FieldConverters.ExcludeHidden();
            }

            if (checkType)
            {
                yield return FieldConverters.ExcludeChangedTypes();
            }

            yield return FieldConverters.ResolveInvariant(context.App.LanguagesConfig);
            yield return FieldConverters.ResolveLanguages(context.App.LanguagesConfig);

            if (!context.IsFrontendClient)
            {
                yield return FieldConverters.ResolveFallbackLanguages(context.App.LanguagesConfig);

                if (context.Languages?.Any() == true)
                {
                    yield return FieldConverters.FilterLanguages(context.App.LanguagesConfig, context.Languages);
                }
            }
        }
        public void Should_resolve_from_fallback_language_if_found(IJsonValue?value)
        {
            var field = Fields.String(1, "string", Partitioning.Language);

            var config =
                LanguagesConfig.English
                .Set(Language.DE)
                .Set(Language.IT)
                .Set(Language.ES, false, Language.IT);

            var source =
                new ContentFieldData()
                .AddLocalized("en", "EN")
                .AddLocalized("it", "IT");

            if (value != JsonValue.False)
            {
                source["de"] = value !;
            }

            var expected =
                new ContentFieldData()
                .AddLocalized("en", "EN")
                .AddLocalized("it", "IT")
                .AddLocalized("es", "IT")
                .AddLocalized("de", "EN");

            var result = FieldConverters.ResolveFallbackLanguages(config)(source, field);

            Assert.Equal(expected, result);
        }
Esempio n. 3
0
        private IEnumerable <FieldConverter> GenerateConverters(QueryContext context)
        {
            if (!context.IsFrontendClient)
            {
                yield return(FieldConverters.ExcludeHidden());

                yield return(FieldConverters.ForNestedName2Name(ValueConverters.ExcludeHidden()));
            }

            yield return(FieldConverters.ExcludeChangedTypes());

            yield return(FieldConverters.ForNestedName2Name(ValueConverters.ExcludeChangedTypes()));

            yield return(FieldConverters.ResolveInvariant(context.App.LanguagesConfig));

            yield return(FieldConverters.ResolveLanguages(context.App.LanguagesConfig));

            if (!context.IsFrontendClient)
            {
                yield return(FieldConverters.ResolveFallbackLanguages(context.App.LanguagesConfig));

                if (context.Languages?.Any() == true)
                {
                    yield return(FieldConverters.FilterLanguages(context.App.LanguagesConfig, context.Languages));
                }

                if (context.AssetUrlsToResolve?.Any() == true)
                {
                    yield return(FieldConverters.ResolveAssetUrls(context.AssetUrlsToResolve, assetUrlGenerator));
                }
            }
        }
Esempio n. 4
0
        public void Should_return_same_values_if_resolving_fallback_languages_from_invariant_field()
        {
            var source = new ContentFieldData();

            var result = FieldConverters.ResolveFallbackLanguages(languagesConfig)(source, stringInvariantField);

            Assert.Same(source, result);
        }
Esempio n. 5
0
        private IEnumerable <FieldConverter> GenerateConverters(Context context, ValueConverter?cleanReferences)
        {
            if (!context.IsFrontendClient)
            {
                yield return(excludedHiddenField);

                yield return(excludedHiddenValue);
            }

            yield return(excludedChangedField);

            yield return(excludedChangedValue);

            if (cleanReferences != null)
            {
                yield return(FieldConverters.ForValues(cleanReferences));

                yield return(FieldConverters.ForValues(ValueConverters.ForNested(cleanReferences)));
            }

            yield return(FieldConverters.ResolveInvariant(context.App.Languages));

            yield return(FieldConverters.ResolveLanguages(context.App.Languages));

            if (!context.IsFrontendClient)
            {
                if (context.ShouldResolveLanguages())
                {
                    yield return(FieldConverters.ResolveFallbackLanguages(context.App.Languages));
                }

                var languages = context.Languages();

                if (languages.Any())
                {
                    yield return(FieldConverters.FilterLanguages(context.App.Languages, languages));
                }

                var assetUrls = context.AssetUrls().ToList();

                if (assetUrls.Count > 0)
                {
                    var appId = context.App.NamedId();

                    var resolveAssetUrls = ValueConverters.ResolveAssetUrls(appId, assetUrls, urlGenerator);

                    yield return(FieldConverters.ForValues(resolveAssetUrls));

                    yield return(FieldConverters.ForValues(ValueConverters.ForNested(resolveAssetUrls)));
                }
            }
        }
Esempio n. 6
0
        public void Should_not_return_value_if_master_is_missing()
        {
            var source =
                new ContentFieldData()
                .AddValue("de", "DE");

            var expected =
                new ContentFieldData()
                .AddValue("de", "DE");

            var result = FieldConverters.ResolveFallbackLanguages(languagesConfig)(source, stringLanguageField);

            Assert.Equal(expected, result);
        }
        public void Should_not_return_value_if_master_is_missing()
        {
            var field = Fields.String(1, "string", Partitioning.Language);

            var source =
                new ContentFieldData()
                .AddLocalized("de", "DE");

            var expected =
                new ContentFieldData()
                .AddLocalized("de", "DE");

            var result = FieldConverters.ResolveFallbackLanguages(languagesConfig)(source, field);

            Assert.Equal(expected, result);
        }
Esempio n. 8
0
        private IEnumerable <FieldConverter> GenerateConverters(Context context, ValueConverter?cleanReferences)
        {
            if (!context.IsFrontendClient)
            {
                yield return(FieldConverters.ExcludeHidden());

                yield return(FieldConverters.ForNestedName2Name(ValueConverters.ExcludeHidden()));
            }

            yield return(FieldConverters.ExcludeChangedTypes());

            yield return(FieldConverters.ForNestedName2Name(ValueConverters.ExcludeChangedTypes()));

            if (cleanReferences != null)
            {
                yield return(FieldConverters.ForValues(cleanReferences));

                yield return(FieldConverters.ForNestedName2Name(cleanReferences));
            }

            yield return(FieldConverters.ResolveInvariant(context.App.LanguagesConfig));

            yield return(FieldConverters.ResolveLanguages(context.App.LanguagesConfig));

            if (!context.IsFrontendClient)
            {
                if (context.ShouldResolveLanguages())
                {
                    yield return(FieldConverters.ResolveFallbackLanguages(context.App.LanguagesConfig));
                }

                var languages = context.Languages();

                if (languages.Any())
                {
                    yield return(FieldConverters.FilterLanguages(context.App.LanguagesConfig, languages));
                }

                var assetUrls = context.AssetUrls();

                if (assetUrls.Any())
                {
                    yield return(FieldConverters.ResolveAssetUrls(assetUrls.ToList(), assetUrlGenerator));
                }
            }
        }
Esempio n. 9
0
        public void Should_return_language_from_fallback_if_found()
        {
            var config_1 = languagesConfig.Set(new LanguageConfig(Language.IT));
            var config_2 = config_1.Set(new LanguageConfig(Language.ES, false, Language.IT));

            var source =
                new ContentFieldData()
                .AddValue("en", "EN")
                .AddValue("it", "IT");

            var expected =
                new ContentFieldData()
                .AddValue("en", "EN")
                .AddValue("de", "EN")
                .AddValue("it", "IT")
                .AddValue("es", "IT");

            var result = FieldConverters.ResolveFallbackLanguages(config_2)(source, stringLanguageField);

            Assert.Equal(expected, result);
        }