From 1168a733a40b9e025c457815a85ca02d8a4cbee5 Mon Sep 17 00:00:00 2001 From: Vladimir Bryzgalov Date: Tue, 21 Apr 2026 16:04:18 +0500 Subject: [PATCH] test(classifier): boundary + array-value tests for has_short_latin_name; @return tags - Add @return bool to has_valid_email_anywhere docblock - Add @return bool to has_short_latin_name docblock - Add Cyrillic note to has_short_latin_name docblock - Add test_has_short_latin_name_true_for_single_letter_boundary (lower bound) - Add test_has_short_latin_name_false_for_four_letters_boundary (upper bound) - Add test_has_short_latin_name_false_for_array_value_with_space_join (regression) Addresses code review feedback from commit 660a0d2. Co-Authored-By: Claude Opus 4.7 (1M context) --- includes/class-classifier.php | 4 ++++ tests/ClassifierDropTest.php | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/includes/class-classifier.php b/includes/class-classifier.php index 4eaaf13..63c6860 100644 --- a/includes/class-classifier.php +++ b/includes/class-classifier.php @@ -226,6 +226,7 @@ final class Classifier * shape). Deeper nesting is intentionally NOT supported. * * @param array $fields CF7 posted_data + * @return bool True if any value contains a syntactically valid email */ public static function has_valid_email_anywhere(array $fields): bool { @@ -252,7 +253,10 @@ final class Classifier * the value-based heuristic in FieldDetector::find_name(). Returns false if no name * field is present (i.e. forms without a name field are immune to this rule). * + * Cyrillic look-alikes (e.g. 'ОВ') are rejected because the regex is byte-range. + * * @param array $fields CF7 posted_data + * @return bool True if a name field exists and is 1-3 ASCII alphanumeric chars */ public static function has_short_latin_name(array $fields): bool { diff --git a/tests/ClassifierDropTest.php b/tests/ClassifierDropTest.php index 6b91278..ff77f92 100644 --- a/tests/ClassifierDropTest.php +++ b/tests/ClassifierDropTest.php @@ -81,4 +81,25 @@ final class ClassifierDropTest extends Cf7stgTestCase $fields = ['text-211' => 'XY', 'text-212' => '+79991234567']; self::assertTrue(Classifier::has_short_latin_name($fields)); } + + public function test_has_short_latin_name_true_for_single_letter_boundary(): void + { + // Lower boundary of {1,3}: 1 char accepted + $fields = ['your-name' => 'A']; + self::assertTrue(Classifier::has_short_latin_name($fields)); + } + + public function test_has_short_latin_name_false_for_four_letters_boundary(): void + { + // Upper boundary of {1,3}: 4 chars rejected + $fields = ['your-name' => 'ABCD']; + self::assertFalse(Classifier::has_short_latin_name($fields)); + } + + public function test_has_short_latin_name_false_for_array_value_with_space_join(): void + { + // pick_field joins array values with a space → "OB MU" is 5 chars → no false positive. + $fields = ['your-name' => ['OB', 'MU']]; + self::assertFalse(Classifier::has_short_latin_name($fields)); + } }