Author: Andreas Möller (localheinz) Committer: GitHub (web-flow) Pusher: cmb69 Date: 2022-07-09T17:03:23+02:00
Commit: https://github.com/php/web-php/commit/d31e1873247ce1597582839a4a8f0ac6ffc663ea Raw diff: https://github.com/php/web-php/commit/d31e1873247ce1597582839a4a8f0ac6ffc663ea.diff Fix: Replace script with tests Closes GH-631. Changed paths: A tests/clean-anti-spam.phpt A tests/is-emailable-address.phpt D include/check_email_func.php Diff: diff --git a/include/check_email_func.php b/include/check_email_func.php deleted file mode 100644 index 8f617f34d6..0000000000 --- a/include/check_email_func.php +++ /dev/null @@ -1,28 +0,0 @@ -<html> -<head><title>email validation test</title></head> -<body> -<?php - -require getcwd()."/email-validation.inc"; - -$test_add = array ( - "[email protected]","[email protected]", - "[email protected]", "[email protected]", - "[email protected]", "[email protected]", - "[email protected]", "[email protected]", - "[email protected]", "[email protected]", - "wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff"); - -foreach ($test_add as $v) { - echo "The address: $v (".clean_AntiSpam($v).") is"; - if (!is_emailable_address(clean_AntiSPAM($v))) - echo " not"; - echo " valid\n<br>"; -} - -?> -<hr> -The [email protected], [email protected] and [email protected] -should validate OK as of 2001-02-28 --- JMC -</body> -</html> diff --git a/tests/clean-anti-spam.phpt b/tests/clean-anti-spam.phpt new file mode 100644 index 0000000000..a90f128d48 --- /dev/null +++ b/tests/clean-anti-spam.phpt @@ -0,0 +1,53 @@ +--TEST-- +clean_AntiSPAM() removes spam terms +--FILE-- +<?php + +require_once __DIR__ . '/../include/email-validation.inc'; + +$emails = array ( + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + 'wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff', + '[email protected]', +); + +$cleanedEmails = array_map(static function (string $email): string { + return clean_AntiSPAM($email); +}, $emails); + +var_dump($cleanedEmails); + +?> +--EXPECT-- +array(11) { + [0]=> + string(21) "[email protected]" + [1]=> + string(22) "[email protected]" + [2]=> + string(22) "[email protected]" + [3]=> + string(22) "[email protected]" + [4]=> + string(22) "[email protected]" + [5]=> + string(19) "[email protected]" + [6]=> + string(23) "[email protected]" + [7]=> + string(23) "[email protected]" + [8]=> + string(20) "[email protected]" + [9]=> + string(35) "wrong-address-with@@@@and-somestuff" + [10]=> + string(33) "[email protected]" +} diff --git a/tests/is-emailable-address.phpt b/tests/is-emailable-address.phpt new file mode 100644 index 0000000000..8ad4eab30c --- /dev/null +++ b/tests/is-emailable-address.phpt @@ -0,0 +1,43 @@ +--TEST-- +is_emailable_address() returns whether email is emailable +--FILE-- +<?php + +require_once __DIR__ . '/../include/email-validation.inc'; + +$emails = array( + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + '[email protected]', + 'wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff', + '[email protected]', +); + +$emailsThatAreEmailableAddresses = array_filter($emails, static function (string $email): bool { + return is_emailable_address($email); +}); + +var_dump($emailsThatAreEmailableAddresses); + +?> +--EXPECT-- +array(6) { + [0]=> + string(21) "[email protected]" + [1]=> + string(35) "[email protected]" + [3]=> + string(30) "[email protected]" + [5]=> + string(19) "[email protected]" + [7]=> + string(23) "[email protected]" + [8]=> + string(20) "[email protected]" +} -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
