diff --git a/phpbb-test-board/feature_checks.py b/phpbb-test-board/feature_checks.py index 6a59f2a..95e234c 100755 --- a/phpbb-test-board/feature_checks.py +++ b/phpbb-test-board/feature_checks.py @@ -424,7 +424,71 @@ def check_sfscompanion(b: Board) -> None: "a member without m_chk_sfs can't open the lookup page") +def check_contactadmin(b: Board) -> None: + def nav_links(html: str) -> tuple: + """Return whether the header and footer navigation bars link to the contact page.""" + header = re.search(r'(?s)id="nav-main".*?id="nav-breadcrumbs"', html) + footer = re.search(r'(?s)id="nav-footer".*', html) + return tuple(bool(m and "app.php/contactadmin" in m.group(0)) for m in (header, footer)) + + # A fresh board can't send email, so deliver by private message; with + # email delivery the contact page shows an error and the ACP won't save. + b.sql("UPDATE phpbb_config SET config_value = '2' WHERE config_name = 'contactadmin_method'") + b.purge_cache() + ok(nav_links(requests.get(f"{b.base}/index.php").text) == (True, True), + "guest sees the contact link in the header and footer navigation") + ok('name="message"' in requests.get(f"{b.base}/app.php/contactadmin").text, "guest contact form loads") + + if not b.sql("SELECT 1 FROM phpbb_config WHERE config_name = 'contactadmin_header_link'"): + print(" [skip] header/footer link settings (not in this version)") + return + admin = requests.Session() + sid = b.login(admin, acp=True) + mid = b.sql("SELECT module_id FROM phpbb_modules WHERE module_basename LIKE '%contactadmin%' " + "AND module_mode = 'configuration'")[0][0] + page_url = f"{b.base}/adm/index.php?i={mid}&sid={sid}" + + def save(header: str, footer: str) -> None: + """Submit the settings page as shown, changing only the two link settings.""" + html = admin.get(page_url).text + form = re.search(r'(?s)
', html).group(0) + action, fields = form_fields(html, "contactadmin") + for tag in re.findall(r']*>', form): + attrs = dict(re.findall(r'(\w+)="([^"]*)"', tag)) + if "name" in attrs and (attrs.get("type") in ("text", "number") + or (attrs.get("type") == "radio" and "checked" in attrs)): + fields[attrs["name"]] = attrs.get("value", "") + fields.update(re.findall(r'(?s)', form)) + for name, options in re.findall(r'(?s)', form): + selected = re.search(r'