Repository: wagtail/wagtail

Issue:
Tests failing on latest `main`
<!--
Found a bug? Please fill out the sections below. 👍
-->

### Issue Summary

Some tests for the ~~legacy~~ moderation feature seems to be failing on latest `main` after #9817. Weirdly, they passed when the CI was run on the PR: https://github.com/wagtail/wagtail/actions/runs/3956994621

Will investigate later today.

<!--
A summary of the issue.
-->

### Steps to Reproduce

1. (for example) Start a new project with `wagtail start myproject`
2. Edit models.py as follows...
3. ...

Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?

-   I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: (yes / no)

### Technical details

-   Python version: Run `python --version`.
-   Django version: Look in your requirements.txt, or run `pip show django | grep Version`.
-   Wagtail version: Look at the bottom of the Settings menu in the Wagtail admin, or run `pip show wagtail | grep Version:`.
-   Browser version: You can use https://www.whatsmybrowser.org/ to find this out.



Discussion:
I think this might just be an issue with the `icon` template tag.
Ah yep, [this line](https://github.com/wagtail/wagtail/blob/main/wagtail/admin/templatetags/wagtailadmin_tags.py#L768) looks suspect - presumably #9817 reintroduced an instance of the old `class_name` attribute, triggering the warning where there wasn't one before. I think we could just make the warning message a static string instead of trying to interpolate the `class_name` value...
(actually, no, it doesn't look suspect - that's just me forgetting how `f`-strings work...)

Resolving patch:
diff --git a/wagtail/admin/templatetags/wagtailadmin_tags.py b/wagtail/admin/templatetags/wagtailadmin_tags.py
--- a/wagtail/admin/templatetags/wagtailadmin_tags.py
+++ b/wagtail/admin/templatetags/wagtailadmin_tags.py
@@ -764,8 +764,8 @@ def icon(name=None, classname=None, title=None, wrapped=False, class_name=None):
 
         warn(
             (
-                "Icon template tag `class_name` has been renamed to `classname`, please adopt the new usage instead.",
-                f'Replace `{{% icon ... class_name="{class_name}" %}}` with `{{% icon ... classname="{class_name}" %}}`',
+                "Icon template tag `class_name` has been renamed to `classname`, please adopt the new usage instead. "
+                f'Replace `{{% icon ... class_name="{class_name}" %}}` with `{{% icon ... classname="{class_name}" %}}`'
             ),
             category=RemovedInWagtail50Warning,
         )


Test patch:
diff --git a/wagtail/admin/tests/test_templatetags.py b/wagtail/admin/tests/test_templatetags.py
--- a/wagtail/admin/tests/test_templatetags.py
+++ b/wagtail/admin/tests/test_templatetags.py
@@ -27,6 +27,7 @@
 from wagtail.models import Locale
 from wagtail.test.utils import WagtailTestUtils
 from wagtail.users.models import UserProfile
+from wagtail.utils.deprecation import RemovedInWagtail50Warning
 
 
 class TestAvatarTemplateTag(TestCase, WagtailTestUtils):
@@ -483,3 +484,62 @@ def test_with_args_with_extra_whitespace(self):
         actual = Template(template).render(context)
 
         self.assertEqual(expected.strip(), actual.strip())
+
+
+class IconTagTest(TestCase):
+    def test_basic(self):
+        template = """
+            {% load wagtailadmin_tags %}
+            {% icon "wagtail" %}
+        """
+
+        expected = """
+            <svg aria-hidden="true" class="icon icon-wagtail icon"><use href="#icon-wagtail"></svg>
+        """
+
+        self.assertHTMLEqual(expected, Template(template).render(Context()))
+
+    def test_with_classes_positional(self):
+        template = """
+            {% load wagtailadmin_tags %}
+            {% icon "cogs" "myclass" %}
+        """
+
+        expected = """
+            <svg aria-hidden="true" class="icon icon-cogs myclass"><use href="#icon-cogs"></svg>
+        """
+
+        self.assertHTMLEqual(expected, Template(template).render(Context()))
+
+    def test_with_classes_keyword(self):
+        template = """
+            {% load wagtailadmin_tags %}
+            {% icon "warning" classname="myclass" %}
+        """
+
+        expected = """
+            <svg aria-hidden="true" class="icon icon-warning myclass"><use href="#icon-warning"></svg>
+        """
+
+        self.assertHTMLEqual(expected, Template(template).render(Context()))
+
+    def test_with_classes_obsolete_keyword(self):
+        template = """
+            {% load wagtailadmin_tags %}
+            {% icon "doc-empty" class_name="myclass" %}
+        """
+
+        expected = """
+            <svg aria-hidden="true" class="icon icon-doc-empty myclass"><use href="#icon-doc-empty"></svg>
+        """
+
+        with self.assertWarnsMessage(
+            RemovedInWagtail50Warning,
+            (
+                "Icon template tag `class_name` has been renamed to `classname`, "
+                "please adopt the new usage instead. Replace "
+                '`{% icon ... class_name="myclass" %}` with '
+                '`{% icon ... classname="myclass" %}`'
+            ),
+        ):
+            self.assertHTMLEqual(expected, Template(template).render(Context()))