* Move core dependencies and MSBuild targets from Umbraco.Cms to Umbraco.Cms.Targets * Re-add appsettings.Tests.json * Include appsettings-schema.json * Use .NET 7.x in CodeQL build * Fix duplicate Directory.Build.props import * Decouple ImageSharp/ImageSharp.Web implementations * Further decouple SqlServer implementation * Add SupportedImageFileTypes to IImageDimensionExtractor * Update descriptions * Update project metadata * Re-enable package validation * Add embedded package icon * Move ContinuousIntegrationBuild to build script * Move shared properties to root Directory.Build.props * Fix GetInstallState throwing exception when default provider isn't configured * Remove redundant PackageRequireLicenseAcceptance and update version to 11.0.0-rc1 * Update build script * Remove LangVersion preview * Disable app-local ICU for MacOS integration test * Disable app-local ICU for all integration tests * Fix RuntimeState_Run test assertion * Update projects and build script to require Node.js 16.17 (latest LTS) * Remove app-local ICU from unit tests * Add missing project reference * Generate XML documentation files * Expose management API in Web.UI project * Update .NET 7 dependencies to RC1 * Update package-lock.json files * Downgrade Cypress version
53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System.Globalization;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using NUnit.Framework;
|
|
using SixLabors.ImageSharp;
|
|
using SixLabors.ImageSharp.Formats.Png;
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
using SixLabors.ImageSharp.Web;
|
|
using SixLabors.ImageSharp.Web.Commands;
|
|
using SixLabors.ImageSharp.Web.Commands.Converters;
|
|
using SixLabors.ImageSharp.Web.Middleware;
|
|
using Umbraco.Cms.Imaging.ImageSharp.ImageProcessors;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.ImageProcessors;
|
|
|
|
[TestFixture]
|
|
public class CropWebProcessorTests
|
|
{
|
|
[Test]
|
|
|
|
// Coordinates are percentages to crop from the left, top, right and bottom sides
|
|
[TestCase("0,0,0,0", 50, 90)]
|
|
[TestCase("0.1,0.0,0.0,0.0", 45, 90)]
|
|
[TestCase("0.0,0.1,0.0,0.0", 50, 81)]
|
|
[TestCase("0.0,0.0,0.1,0.0", 45, 90)]
|
|
[TestCase("0.0,0.0,0.0,0.1", 50, 81)]
|
|
[TestCase("0.1,0.0,0.1,0.0", 40, 90)]
|
|
[TestCase("0.0,0.1,0.0,0.1", 50, 72)]
|
|
[TestCase("0.1,0.1,0.1,0.1", 40, 72)]
|
|
[TestCase("0.25,0.25,0.25,0.25", 25, 45)]
|
|
public void CropWebProcessor_CropsImage(string coordinates, int width, int height)
|
|
{
|
|
using var image = new Image<Rgba32>(50, 90);
|
|
using var formattedImage = new FormattedImage(image, PngFormat.Instance);
|
|
|
|
var logger = new NullLogger<ImageSharpMiddleware>();
|
|
var commands = new CommandCollection { { CropWebProcessor.Coordinates, coordinates } };
|
|
var parser = new CommandParser(new ICommandConverter[]
|
|
{
|
|
new ArrayConverter<float>(),
|
|
new SimpleCommandConverter<float>(),
|
|
});
|
|
var culture = CultureInfo.InvariantCulture;
|
|
|
|
new CropWebProcessor().Process(formattedImage, logger, commands, parser, culture);
|
|
|
|
Assert.AreEqual(width, image.Width);
|
|
Assert.AreEqual(height, image.Height);
|
|
}
|
|
}
|