From 18a07c9b1b80410a47a67f0ada377a9681d99447 Mon Sep 17 00:00:00 2001 From: Vladimir Bryzgalov Date: Tue, 21 Apr 2026 16:08:57 +0500 Subject: [PATCH] test(classifier): exact-count assertions for placeholder fixture; document SERVICE_FIELD_KEYS prefix semantics Fixes issues from code review in commit 249f195: 1. Tighten fixture assertions to exact counts (assertSame instead of assertGreaterThanOrEqual): - test_count_placeholder_fields_screenshot_1_exact_count: expect 5 placeholders - test_count_placeholder_fields_screenshot_2_exact_count: expect 5 placeholders - test_count_placeholder_fields_screenshot_3_exact_count: expect 1 placeholder 2. Document SERVICE_FIELD_KEYS prefix-matching semantics in comment: clarify that keys starting with _wpcf7 are skipped via strpos prefix match, so explicit enumeration of every _wpcf7_* variant is unnecessary. Test results: 75/75 green. Co-Authored-By: Claude Opus 4.7 (1M context) --- includes/class-classifier.php | 7 ++++++- tests/ClassifierDropTest.php | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/includes/class-classifier.php b/includes/class-classifier.php index 84a095c..6874382 100644 --- a/includes/class-classifier.php +++ b/includes/class-classifier.php @@ -46,7 +46,12 @@ final class Classifier 'rambler.ru', 'gmail.com', ]; - /** Service field keys excluded from placeholder count. */ + /** + * Explicit service field keys excluded from placeholder count. + * Note: keys starting with `_wpcf7` are also skipped via prefix match + * (see count_placeholder_fields), so this list does not need to enumerate + * every `_wpcf7_*` variant — only non-prefixed service keys. + */ private const SERVICE_FIELD_KEYS = [ 'acceptance-data', '_wpcf7', '_wpcf7_version', '_wpcf7_locale', '_wpcf7_unit_tag', diff --git a/tests/ClassifierDropTest.php b/tests/ClassifierDropTest.php index ec21dd7..f8ed6f3 100644 --- a/tests/ClassifierDropTest.php +++ b/tests/ClassifierDropTest.php @@ -103,12 +103,27 @@ final class ClassifierDropTest extends Cf7stgTestCase self::assertFalse(Classifier::has_short_latin_name($fields)); } - public function test_count_placeholder_fields_screenshot_1(): void + public function test_count_placeholder_fields_screenshot_1_exact_count(): void { $fields = require __DIR__ . '/fixtures/spam-screenshot-1.php'; - // text-785: OB(2), text-787: 70(2), text-786: BP(2), text-788: ZZ(2), text-789: QV(2) + // text-785: OB(2), text-787: 70(2), text-786: BP(2), text-788: ZZ(2), text-789: QV(2) → 5 placeholders. // text-790: 10 цифр — не placeholder. acceptance-data: служебное → исключено. - self::assertGreaterThanOrEqual(3, Classifier::count_placeholder_fields($fields)); + self::assertSame(5, Classifier::count_placeholder_fields($fields)); + } + + public function test_count_placeholder_fields_screenshot_2_exact_count(): void + { + $fields = require __DIR__ . '/fixtures/spam-screenshot-2.php'; + // Same shape as screenshot-1: 5 placeholder fields. + self::assertSame(5, Classifier::count_placeholder_fields($fields)); + } + + public function test_count_placeholder_fields_screenshot_3_exact_count(): void + { + $fields = require __DIR__ . '/fixtures/spam-screenshot-3.php'; + // text-347: MU(2) is the only placeholder; tel-185(10), text-subject (long), text-title (long) + // are not. acceptance-data: служебное. + self::assertSame(1, Classifier::count_placeholder_fields($fields)); } public function test_count_placeholder_fields_ignores_empty(): void