Skip to content

Add first unit tests for language analysis and guid language detection - #73

Open
SNO7E-G wants to merge 1 commit into
OnTheGoSystems:masterfrom
SNO7E-G:test/first-unit-tests
Open

SNO7E-G wants to merge 1 commit into
OnTheGoSystems:masterfrom
SNO7E-G:test/first-unit-tests

Conversation

@SNO7E-G

@SNO7E-G SNO7E-G commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

What

The PHPUnit suite currently contains no tests (CI reports "No tests executed"). This adds the first two test files, covering the two pieces of pure logic in the plugin that need no WordPress mocks:

  • TranslateLanguagesTestgenerateAnalysisLanguages() and languageHasStemmer(): analyzer/snowball resolution for fully-supported languages (de, en), languages without snowball support (ar, th, pt-br), multi-code languages (nn → norwegian), and the english fallback for unknown codes; stemmer availability including the no-stemmer languages.
  • FieldLanguagePatternTestbuildLanguagePattern(): language extraction from post guids for all three URL formats the pattern supports (directory /de/, query parameter ?lang=fr, subdomain de.), plus non-matching guids, asserting the last-captured-group convention that getPostLanguage() relies on.

Notes

  • Test doubles are small named classes (a trait host and a Field\Sync subclass) rather than anonymous classes, because the test framework's include rewriting does not parse anonymous classes.
  • No production code is touched.

Verification

  • PHPUnit under PHP 7.4 (CI version): 13 tests, 19 assertions, OK.
  • PHPStan (level 3): clean.

The PHPUnit suite was empty. Cover the two pure pieces of logic that
need no WordPress mocks:

- TranslateLanguages::generateAnalysisLanguages() and
  languageHasStemmer(): analyzer/snowball/stemmer resolution,
  including languages without snowball or stemmer support and the
  english fallback for unknown codes.
- Field::buildLanguagePattern(): language extraction from guids for
  directory, query parameter and subdomain URL formats.

Test doubles are named classes because the test framework's include
rewriting does not parse anonymous classes.
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