|
| 1 | +from cs_dynamicpages.controlpanels.dynamic_pages_control_panel.controlpanel import ( |
| 2 | + IDynamicPagesControlPanel, |
| 3 | +) |
| 4 | +from cs_dynamicpages.testing import CS_DYNAMICPAGES_INTEGRATION_TESTING |
| 5 | +from plone import api |
| 6 | +from plone.app.testing import setRoles |
| 7 | +from plone.app.testing import TEST_USER_ID |
| 8 | +from plone.registry.interfaces import IRegistry |
| 9 | +from zope.component import getUtility |
| 10 | + |
| 11 | +import unittest |
| 12 | + |
| 13 | + |
| 14 | +class DynamicPagesControlPanelIntegrationTest(unittest.TestCase): |
| 15 | + """Integration tests for the Dynamic Pages Control Panel.""" |
| 16 | + |
| 17 | + layer = CS_DYNAMICPAGES_INTEGRATION_TESTING |
| 18 | + |
| 19 | + def setUp(self): |
| 20 | + self.portal = self.layer["portal"] |
| 21 | + setRoles(self.portal, TEST_USER_ID, ["Manager"]) |
| 22 | + self.registry = getUtility(IRegistry) |
| 23 | + |
| 24 | + def test_controlpanel_schema_registered(self): |
| 25 | + """Test that the control panel schema is registered in the registry.""" |
| 26 | + records = self.registry.records |
| 27 | + self.assertIn( |
| 28 | + "cs_dynamicpages.dynamic_pages_control_panel.row_type_fields", |
| 29 | + records, |
| 30 | + ) |
| 31 | + |
| 32 | + def test_row_type_fields_record_exists(self): |
| 33 | + """Test that row_type_fields registry record exists.""" |
| 34 | + value = api.portal.get_registry_record( |
| 35 | + "cs_dynamicpages.dynamic_pages_control_panel.row_type_fields" |
| 36 | + ) |
| 37 | + self.assertIsInstance(value, list) |
| 38 | + |
| 39 | + def test_row_widths_record_exists(self): |
| 40 | + """Test that row_widths registry record exists.""" |
| 41 | + value = api.portal.get_registry_record( |
| 42 | + "cs_dynamicpages.dynamic_pages_control_panel.row_widths" |
| 43 | + ) |
| 44 | + self.assertIsInstance(value, list) |
| 45 | + |
| 46 | + def test_spacer_padding_top_record_exists(self): |
| 47 | + """Test that spacer_padding_top registry record exists.""" |
| 48 | + value = api.portal.get_registry_record( |
| 49 | + "cs_dynamicpages.dynamic_pages_control_panel.spacer_padding_top" |
| 50 | + ) |
| 51 | + self.assertIsInstance(value, list) |
| 52 | + |
| 53 | + def test_spacer_padding_bottom_record_exists(self): |
| 54 | + """Test that spacer_padding_bottom registry record exists.""" |
| 55 | + value = api.portal.get_registry_record( |
| 56 | + "cs_dynamicpages.dynamic_pages_control_panel.spacer_padding_bottom" |
| 57 | + ) |
| 58 | + self.assertIsInstance(value, list) |
| 59 | + |
| 60 | + def test_spacer_margin_top_record_exists(self): |
| 61 | + """Test that spacer_margin_top registry record exists.""" |
| 62 | + value = api.portal.get_registry_record( |
| 63 | + "cs_dynamicpages.dynamic_pages_control_panel.spacer_margin_top" |
| 64 | + ) |
| 65 | + self.assertIsInstance(value, list) |
| 66 | + |
| 67 | + def test_spacer_margin_bottom_record_exists(self): |
| 68 | + """Test that spacer_margin_bottom registry record exists.""" |
| 69 | + value = api.portal.get_registry_record( |
| 70 | + "cs_dynamicpages.dynamic_pages_control_panel.spacer_margin_bottom" |
| 71 | + ) |
| 72 | + self.assertIsInstance(value, list) |
| 73 | + |
| 74 | + def test_row_type_fields_has_default_values(self): |
| 75 | + """Test that row_type_fields has default row types configured.""" |
| 76 | + value = api.portal.get_registry_record( |
| 77 | + "cs_dynamicpages.dynamic_pages_control_panel.row_type_fields" |
| 78 | + ) |
| 79 | + row_types = [item["row_type"] for item in value] |
| 80 | + |
| 81 | + # Check for some expected default row types |
| 82 | + self.assertIn("cs_dynamicpages-horizontal-rule-view", row_types) |
| 83 | + self.assertIn("cs_dynamicpages-spacer-view", row_types) |
| 84 | + |
| 85 | + def test_row_widths_has_default_values(self): |
| 86 | + """Test that row_widths has default width options.""" |
| 87 | + value = api.portal.get_registry_record( |
| 88 | + "cs_dynamicpages.dynamic_pages_control_panel.row_widths" |
| 89 | + ) |
| 90 | + self.assertTrue(len(value) > 0) |
| 91 | + |
| 92 | + # Check structure of first item |
| 93 | + first_item = value[0] |
| 94 | + self.assertIn("row_width_label", first_item) |
| 95 | + self.assertIn("row_width_class", first_item) |
| 96 | + |
| 97 | + def test_spacer_values_have_correct_structure(self): |
| 98 | + """Test that spacer values have correct structure.""" |
| 99 | + for record_name in [ |
| 100 | + "spacer_padding_top", |
| 101 | + "spacer_padding_bottom", |
| 102 | + "spacer_margin_top", |
| 103 | + "spacer_margin_bottom", |
| 104 | + ]: |
| 105 | + value = api.portal.get_registry_record( |
| 106 | + f"cs_dynamicpages.dynamic_pages_control_panel.{record_name}" |
| 107 | + ) |
| 108 | + self.assertTrue(len(value) > 0, f"{record_name} should have values") |
| 109 | + |
| 110 | + # Check structure of first item |
| 111 | + first_item = value[0] |
| 112 | + self.assertIn("spacer_label", first_item) |
| 113 | + self.assertIn("spacer_class", first_item) |
| 114 | + |
| 115 | + |
| 116 | +class DynamicPagesControlPanelSchemaTest(unittest.TestCase): |
| 117 | + """Tests for the control panel schema interface.""" |
| 118 | + |
| 119 | + def test_schema_has_row_type_fields(self): |
| 120 | + """Test that schema has row_type_fields field.""" |
| 121 | + self.assertIn("row_type_fields", IDynamicPagesControlPanel.names()) |
| 122 | + |
| 123 | + def test_schema_has_row_widths(self): |
| 124 | + """Test that schema has row_widths field.""" |
| 125 | + self.assertIn("row_widths", IDynamicPagesControlPanel.names()) |
| 126 | + |
| 127 | + def test_schema_has_spacer_fields(self): |
| 128 | + """Test that schema has all spacer fields.""" |
| 129 | + names = IDynamicPagesControlPanel.names() |
| 130 | + self.assertIn("spacer_padding_top", names) |
| 131 | + self.assertIn("spacer_padding_bottom", names) |
| 132 | + self.assertIn("spacer_margin_top", names) |
| 133 | + self.assertIn("spacer_margin_bottom", names) |
0 commit comments