|
@@ -11,6 +11,7 @@ from wagtail.coreutils import get_dummy_request
|
|
|
from wagtail.models import PAGE_TEMPLATE_VAR, Page, Site
|
|
|
from wagtail.test.testapp.models import BusinessChild, BusinessIndex, SimplePage
|
|
|
from wagtail.test.utils import WagtailTestUtils
|
|
|
+from wagtail.utils.deprecation import RemovedInWagtail70Warning
|
|
|
|
|
|
|
|
|
class TestUserbarTag(WagtailTestUtils, TestCase):
|
|
@@ -184,7 +185,7 @@ class TestAccessibilityCheckerConfig(WagtailTestUtils, TestCase):
|
|
|
return json.loads(self.get_script().string)
|
|
|
|
|
|
def get_hook(self, item_class):
|
|
|
- def customise_accessibility_checker(request, items):
|
|
|
+ def customise_accessibility_checker(request, items, page):
|
|
|
items[:] = [
|
|
|
item_class() if isinstance(item, AccessibilityItem) else item
|
|
|
for item in items
|
|
@@ -455,6 +456,41 @@ class TestUserbarInPageServe(WagtailTestUtils, TestCase):
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
self.assertNotContains(response, '<template id="wagtail-userbar-template">')
|
|
|
|
|
|
+ def test_construct_wagtail_userbar_hook_passes_page(self):
|
|
|
+ kwargs = {}
|
|
|
+
|
|
|
+ def construct_wagtail_userbar(request, items, page):
|
|
|
+ kwargs["page"] = page
|
|
|
+ return items
|
|
|
+
|
|
|
+ with hooks.register_temporarily(
|
|
|
+ "construct_wagtail_userbar",
|
|
|
+ construct_wagtail_userbar,
|
|
|
+ ):
|
|
|
+ response = self.page.serve(self.request)
|
|
|
+ response.render()
|
|
|
+
|
|
|
+ self.assertEqual(kwargs.get("page"), self.page)
|
|
|
+
|
|
|
+ def test_deprecated_construct_wagtail_userbar_hook_without_page(self):
|
|
|
+ kwargs = {}
|
|
|
+
|
|
|
+ def construct_wagtail_userbar(request, items):
|
|
|
+ kwargs["called"] = True
|
|
|
+ return items
|
|
|
+
|
|
|
+ with self.assertWarnsMessage(
|
|
|
+ RemovedInWagtail70Warning,
|
|
|
+ "`construct_wagtail_userbar` hook functions should accept a `page` argument in third position",
|
|
|
+ ), hooks.register_temporarily(
|
|
|
+ "construct_wagtail_userbar",
|
|
|
+ construct_wagtail_userbar,
|
|
|
+ ):
|
|
|
+ response = self.page.serve(self.request)
|
|
|
+ response.render()
|
|
|
+
|
|
|
+ self.assertTrue(kwargs.get("called"))
|
|
|
+
|
|
|
|
|
|
class TestUserbarAddLink(WagtailTestUtils, TestCase):
|
|
|
fixtures = ["test.json"]
|