|
| 1 | +from cs_dynamicpages.testing import CS_DYNAMICPAGES_FUNCTIONAL_TESTING |
| 2 | +from plone import api |
| 3 | +from plone.app.testing import setRoles |
| 4 | +from plone.app.testing import SITE_OWNER_NAME |
| 5 | +from plone.app.testing import SITE_OWNER_PASSWORD |
| 6 | +from plone.app.testing import TEST_USER_ID |
| 7 | +from plone.testing.zope import Browser |
| 8 | + |
| 9 | +import transaction |
| 10 | +import unittest |
| 11 | + |
| 12 | + |
| 13 | +class RelatedImageFunctionalTest(unittest.TestCase): |
| 14 | + layer = CS_DYNAMICPAGES_FUNCTIONAL_TESTING |
| 15 | + |
| 16 | + def setUp(self): |
| 17 | + self.portal = self.layer["portal"] |
| 18 | + self.request = self.layer["request"] |
| 19 | + setRoles(self.portal, TEST_USER_ID, ["Manager"]) |
| 20 | + |
| 21 | + # Create a document and apply the behavior to be able to test the form |
| 22 | + self.portal.invokeFactory("Document", "doc1", title="Doc 1") |
| 23 | + self.doc1 = self.portal["doc1"] |
| 24 | + |
| 25 | + # Apply the behavior to Document type |
| 26 | + fti = api.portal.get_tool("portal_types").getTypeInfo("Document") |
| 27 | + behaviors = list(fti.behaviors) |
| 28 | + behaviors.append("cs_dynamicpages.related_image") |
| 29 | + fti.behaviors = tuple(behaviors) |
| 30 | + |
| 31 | + transaction.commit() |
| 32 | + |
| 33 | + self.browser = Browser(self.layer["app"]) |
| 34 | + self.browser.handleErrors = False |
| 35 | + self.browser.addHeader( |
| 36 | + "Authorization", f"Basic {SITE_OWNER_NAME}:{SITE_OWNER_PASSWORD}" |
| 37 | + ) |
| 38 | + |
| 39 | + def test_related_image_pattern_options_in_browser(self): |
| 40 | + # We set the registry record |
| 41 | + api.portal.set_registry_record("plone.image_objects", ["Image", "CustomImage"]) |
| 42 | + transaction.commit() |
| 43 | + |
| 44 | + # Open the edit form of the document |
| 45 | + self.browser.open(self.doc1.absolute_url() + "/edit") |
| 46 | + |
| 47 | + # The pattern options should be rendered in the HTML for the related_image field |
| 48 | + try: |
| 49 | + self.assertIn("data-pat-contentbrowser", self.browser.contents) |
| 50 | + except AssertionError: |
| 51 | + self.assertIn("data-pat-relateditems", self.browser.contents) |
| 52 | + |
| 53 | + self.assertIn( |
| 54 | + ""selectableTypes": ["Image", "CustomImage"]", |
| 55 | + self.browser.contents, |
| 56 | + ) |
| 57 | + |
| 58 | + # We change the registry record |
| 59 | + api.portal.set_registry_record("plone.image_objects", ["Image"]) |
| 60 | + transaction.commit() |
| 61 | + |
| 62 | + # Open the edit form again |
| 63 | + self.browser.open(self.doc1.absolute_url() + "/edit") |
| 64 | + |
| 65 | + # The pattern options should be updated |
| 66 | + self.assertIn( |
| 67 | + ""selectableTypes": ["Image"]", self.browser.contents |
| 68 | + ) |
0 commit comments