Extension method for easier ResourceManagementOptions registration, Testing time-dependent functionalities with a time shifting clock using the Lombiq UI Testing Toolbox - This week in Orchard (03/01/2025)

In our first post of this year, we will examine a new extension method for easier ResourceManagementOptions registration, test time-dependent functionalities with a time-shifting clock using the Lombiq UI Testing Toolbox, and more! Without further ado, let's dive in!

Orchard Core updates

Cleanup 'has_claim' Liquid Filter

Some code in the has_claim Liquid Filter was added in 2.1 for backward compatibility. It will be removed in v3, changing the behavior of the has_claim Liquid Filter, meaning the Administrator role no longer registers permission-based claims by default during login. This means that directly checking for specific claims in Liquid, such as:

{% assign isAuthorized = User | has_claim: "Permission", "AccessAdminPanel" %}

will return false for administrators, even though they still have full access. Non-admin users, however, may return true if they have the claim. It's important to use the has_permission filter for permission checks in the future:

{% assign isAuthorized = User | has_permission: "AccessAdminPanel" %}

Cleanup has_claim Liquid Filter

Add an extension method for easier ResourceManagementOptions registration

When adding an IConfigureOptions<ResourceManagementOptions> implementation, used to add static resources and commonly named ResourceManagementOptionsConfiguration, you previously had to do the following in the Startup classes:

services.AddTransient<IConfigureOptions<ResourceManagementOptions>, ResourceManagementOptionsConfiguration>();

To simplify this, we introduced a new extension method to do the same in a shorter form:

services.AddResourceConfiguration<ResourceManagementOptionsConfiguration>();

You can utilize this in your codebase by searching the AddTransient<IConfigureOptions<ResourceManagementOptions>, (.+)>\(\) regex pattern and replacing it with AddResourceConfiguration<$1>(). Projects using this have to reference the OrchardCore.ResourceManagement package.

Add extension method for easier ResourceManagementOptions registration

Demos

Testing time-dependent functionalities with a time-shifting clock and headless Orchard Core using the Lombiq UI Testing Toolbox

Maybe you have already heard about the Lombiq UI Testing Toolbox, which is our web UI testing toolbox mostly for Orchard Core applications. Everything you need to do UI testing with Selenium for an Orchard app is here. We wrote about it several times here as well, first when we open-sourced it, when we added some Orchard Core Features tests to it, when we added the automated monkey testing feature, and when we introduced the Visual verification testing. At the end of 2022, we showed you the latest updates about integrating UI testing into Orchard Core and how to use WebApplicationFactory, a fake video capture source, or the interactive mode. At the end of 2023, we showed how you can do security scanning with ZAP using our UI Testing Toolbox. This time, we will check out two new features: the Shift Time feature, which adds a custom IClock implementation where a specified value can shift the clock, and a feature that can be used when using Orchard Core as a headless app! Let's start with the Shift Time feature!

The easiest way to try out our UI Testing Toolbox is to clone Lombiq's Open-Source Orchard Core Extensions solution. This Orchard Core Visual Studio solution contains most of Lombiq's open-source Orchard modules and themes, as well as related utilities and libraries, containing our UI Testing Toolbox for Orchard Core with several samples and documentation.

First, you must navigate to Configuration -> Features and enable the Shift Time - Shortcuts - Lombiq UI Testing Toolbox feature. It replaces Orchard Core's stock ICLock implementation with the custom TimeShiftingClock class. To test this, we created a new Liquid Widget to print the current date using a Liquid expression.

Liquid Widget to print the current date

After we called the ~/Lombiq.Tests.UI.Shortcuts/TimeShift/Set?days=1&seconds=1 action to set the time offset to update the TimeShiftingClock.Shift property for the current tenant, which will trick any service that uses IClock into thinking that you are in the future. This can be used to test features that can expire, such as a limited-time product discount in a web store, without having to wait.

And now, if we navigate to the front end to see the result of our Liquid Widget, you can see that the current date is in the future, 1 day and 1 second ahead of the current date.

Displaying Liquid Widget with the updated date

In the second part of the demo, you can check how you can UI test a headless site using Orchard Core as an API. If you want to see that, don't forget to check out this recording on YouTube!

Orchard Dojo Newsletter

Lombiq's Orchard Dojo Newsletter has 465 subscribers! We have started this newsletter to inform the community around Orchard of the latest news about the platform. By subscribing to this newsletter, you will get an e-mail whenever a new post is published to Orchard Dojo, including This week in Orchard of course.

Do you know of other Orchard enthusiasts who would like to read our weekly articles? Tell them to subscribe here!

If you are interested in more news about Orchard and the details of the topics above, don't forget to check out the recording of this Orchard meeting!