Problem/Motivation

Socializer has no automated tests. The settings form and block are only checked by hand, so regressions land in 2.x.

While updating the module for Drupal 12 (#3638610), "Add new network" on /admin/config/system/socializer returned an Ajax error when socializer.settings already had links:

TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given

HTTP status was 200 on ?ajax_form=1. The failure was in SocializerSettingsForm::buildForm(), which passed a null network label into t() for a row past the saved links. That rebuild also runs on a normal POST of "Add new network", so a BrowserTestBase test catches it. The null handling is fixed on 2.x; nothing locks the behavior in.

The block path is also untested: valid links, skipped empty URLs, skipped unknown network keys, and the socializer.settings cache tag.

Proposed resolution

Add Drupal functional tests (BrowserTestBase, group socializer, theme stark, declare(strict_types=1)). Do not add FunctionalJavascript or a phpunit.xml inside the module; Drupal.org CI discovers tests/src/Functional.

  1. tests/src/Functional/SocializerSettingsFormTest.php
    • Anonymous user gets 403 on /admin/config/system/socializer.
    • User with "administer socializer configuration" gets 200 and sees "Add new network".
    • Regression: seed one saved Facebook link, submit "Add new network", assert HTTP 200, no unexpected error, and two network selects.
    • With links: [] (install default), the form shows one blank row. Submit Add and assert two rows, still HTTP 200.
    • Seed two links, submit Remove (first row), assert one select remains, save, and assert config has one link.
    • Fill network, URL, rel, target, and weight on links[0], save, reload, and assert socializer.settings links matches (weight stored as an integer).
  2. tests/src/Functional/SocializerBlockTest.php
    • Enable block. Place socializer_block. Check the front page as anonymous.
    • Seed a valid Facebook URL (target _blank, rel noopener), an empty URL, and an unknown network key. Assert the Facebook anchor, href, target, rel, and icon class. Assert the empty and unknown rows are absent.
    • Change config to add another valid link and reload; the new link must show up (socializer.settings cache tag).
    • Empty links list renders the wrapper with no anchors.

User interface changes

None. Tests only.

API changes

None.

Data model changes

None.

Comments

peraz created an issue. See original summary.

  • peraz committed 0975b159 on 2.x
    Issue #3638822 by peraz: Add functional tests for the settings form and...
peraz’s picture

Assigned: peraz » Unassigned
Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.