|
| 1 | +""" test string interpolation substitutions for content rules """ |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +import unittest |
| 4 | + |
| 5 | +from plone import api |
| 6 | +from plone.app.testing import TEST_USER_ID, setRoles |
| 7 | +from plone.stringinterp.interfaces import IStringInterpolator |
| 8 | + |
| 9 | +from plone.volto.interpolators.volto_portal_url import ( |
| 10 | + VoltoPortalURLSubstitution, |
| 11 | +) |
| 12 | +from plone.volto.interpolators.volto_absolute_url import ( |
| 13 | + VoltoAbsoluteURLSubstitution, |
| 14 | +) |
| 15 | +from plone.volto.testing import ( |
| 16 | + PLONE_VOLTO_CORE_INTEGRATION_TESTING, |
| 17 | + PLONE_VOLTO_CORE_FUNCTIONAL_TESTING, |
| 18 | +) |
| 19 | + |
| 20 | + |
| 21 | +class TestSubstitutions(unittest.TestCase): |
| 22 | + """ Test case for substitutions""" |
| 23 | + |
| 24 | + layer = PLONE_VOLTO_CORE_INTEGRATION_TESTING |
| 25 | + |
| 26 | + def setUp(self): |
| 27 | + self.portal = self.layer["portal"] |
| 28 | + self.request = self.layer["request"] |
| 29 | + |
| 30 | + def test_volto_portal_url(self): |
| 31 | + """ test for volto_portal_url""" |
| 32 | + volto_url = api.portal.get_registry_record("volto.frontend_domain") |
| 33 | + substitution = VoltoPortalURLSubstitution(self.portal)() |
| 34 | + self.assertEqual(substitution, volto_url) |
| 35 | + |
| 36 | + def test_string_interpolation_volto_portal_url(self): |
| 37 | + """ test interpolating as string """ |
| 38 | + volto_url = api.portal.get_registry_record("volto.frontend_domain") |
| 39 | + string = "${volto_portal_url}" |
| 40 | + value = IStringInterpolator(self.portal)(string) |
| 41 | + self.assertEqual(value, volto_url) |
| 42 | + |
| 43 | + |
| 44 | +class TestSubstitutionsFunctional(unittest.TestCase): |
| 45 | + """ Test case for substitutions""" |
| 46 | + |
| 47 | + layer = PLONE_VOLTO_CORE_FUNCTIONAL_TESTING |
| 48 | + |
| 49 | + def setUp(self): |
| 50 | + """ test setup """ |
| 51 | + self.portal = self.layer["portal"] |
| 52 | + self.request = self.layer["request"] |
| 53 | + setRoles(self.portal, TEST_USER_ID, ["Manager"]) |
| 54 | + |
| 55 | + self.portal.invokeFactory("Document", id="doc", title="My Document") |
| 56 | + self.document = self.portal.get("doc") |
| 57 | + |
| 58 | + def test_volto_absolute_url(self): |
| 59 | + """ test for volto_absolute_url""" |
| 60 | + |
| 61 | + volto_url = api.portal.get_registry_record("volto.frontend_domain") |
| 62 | + portal_url = self.portal.absolute_url() |
| 63 | + context_url = self.document.absolute_url() |
| 64 | + substitution = VoltoAbsoluteURLSubstitution(self.document)() |
| 65 | + self.assertEqual(substitution, context_url.replace(portal_url, volto_url)) |
| 66 | + |
| 67 | + def test_string_interpolation_volto_absolute_url(self): |
| 68 | + """ test as string interpolator""" |
| 69 | + |
| 70 | + volto_url = api.portal.get_registry_record("volto.frontend_domain") |
| 71 | + portal_url = self.portal.absolute_url() |
| 72 | + context_url = self.document.absolute_url() |
| 73 | + |
| 74 | + string = "${volto_absolute_url}" |
| 75 | + value = IStringInterpolator(self.document)(string) |
| 76 | + self.assertEqual(value, context_url.replace(portal_url, volto_url)) |
0 commit comments