Skip to content

WebControls input coverage: captchas, proof of work, form guards, output cache; fixes (#1497) - #1632

Open
belisoful wants to merge 9 commits into
pradosoft:masterfrom
belisoful:1497-wc-input-c
Open

belisoful wants to merge 9 commits into
pradosoft:masterfrom
belisoful:1497-wc-input-c

Conversation

@belisoful

Copy link
Copy Markdown
Member

Part of #1497 (WebControls: input and forms), third of three coverage PRs. Stacked on #1631, which adds TAssetManagerMockTrait; review the last four commits.

Covers TCaptcha, TReCaptcha2, TReCaptcha2Validator, TProofOfWork, TFormGuard, TPasswordStrengthMeter, TUnsavedChangesGuard, TSuggestionList, TOutputCache, TOutputCacheCalculateKeyEventParameter, TOutputCacheCheckDependencyEventParameter, and TOutputCacheTextWriterMulti. TReCaptcha and TReCaptchaValidator are removed in #1629 and are not covered.

Every line and branch of these files is covered. Each missed path in a method with 16 or fewer paths is impossible: it follows an operand that short-circuited, skips the first fetch of a foreach, or needs a single pass of a loop over a fixed-length list. TCaptcha::checkRequirements() returns false only without gd and TrueType support; a test subclass reaches the exception it causes.

TCaptcha::onPreRender() calls static::checkRequirements(), so a subclass can override the check. The random-key fallback of generateRandomKey() is @codeCoverageIgnore, as in #1548: random_bytes() throws only without a system source of randomness. TAssetManagerMockTrait::mockAssetManager() takes the published base, so the captcha_key.php test writes to a temporary folder.

Fixes, one commit each with its regression test:

  • TReCaptcha2Validator throws TConfigurationException (recaptcha2validator_control_invalid) when ControlToValidate names a control that is not a TReCaptcha2. It threw \Exception with inline text. The null check is removed, since getValidationTarget() already throws for a missing control.
  • TReCaptcha2 renders no tabindex on its widget container. TabIndex is the widget's own option (default 0), and since TWebControl renders a tab index of 0, the empty container was a tab stop.
  • TOutputCache reads a cached entry without its cache time, as setCacheTime($data[3] ?? 0) already allowed. The destructuring threw TPhpErrorException.

Checks: the full unit suite passes on PHP 8.2, and these test classes pass on 8.3, 8.4, and 8.5; php-cs-fixer and PHPStan are clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant