[web-php] master: Fix: Replace script with tests

From: Date: Sat, 09 Jul 2022 15:09:46 +0000
Subject: [web-php] master: Fix: Replace script with tests
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-30321@lists.php.net to get a copy of this message
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 ( - "wrong-email-address@lists.php.net","jmcastagnetto@yahoo.com", - "some-wrong@asdas.com", "jcastagnetto-NO-SPAM@yahoo.com", - "jcastagnetto@NoSpam-yahoo.com", "jmcastagnetto@chek2.com", - "jcastagnetto-i-hate-spam@NOSPAMyahoo.com", "jesusmc@scripps.edu", - "asasasd324324@php.net", "jcastagnetto-delete-this-@yahoo.com", - "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 jesusmc@scripps.edu, jmcastagnetto@yahoo.com and jcastagnetto@yahoo.com -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 ( + 'asasasd324324@php.net', + 'jcastagnetto-delete-this-@yahoo.com', + 'jcastagnetto-i-hate-spam@NOSPAMyahoo.com', + 'jcastagnetto-NO-SPAM@yahoo.com', + 'jcastagnetto@NoSpam-yahoo.com', + 'jesusmc@scripps.edu', + 'jmcastagnetto@chek2.com', + 'jmcastagnetto@yahoo.com', + 'some-wrong@asdas.com', + 'wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff', + 'wrong-email-address@lists.php.net', +); + +$cleanedEmails = array_map(static function (string $email): string { + return clean_AntiSPAM($email); +}, $emails); + +var_dump($cleanedEmails); + +?> +--EXPECT-- +array(11) { + [0]=> + string(21) "asasasd324324@php.net" + [1]=> + string(22) "jcastagnetto@yahoo.com" + [2]=> + string(22) "jcastagnetto@yahoo.com" + [3]=> + string(22) "jcastagnetto@yahoo.com" + [4]=> + string(22) "jcastagnetto@yahoo.com" + [5]=> + string(19) "jesusmc@scripps.edu" + [6]=> + string(23) "jmcastagnetto@chek2.com" + [7]=> + string(23) "jmcastagnetto@yahoo.com" + [8]=> + string(20) "some-wrong@asdas.com" + [9]=> + string(35) "wrong-address-with@@@@and-somestuff" + [10]=> + string(33) "wrong-email-address@lists.php.net" +} 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( + 'asasasd324324@php.net', + 'jcastagnetto-delete-this-@yahoo.com', + 'jcastagnetto-i-hate-spam@NOSPAMyahoo.com', + 'jcastagnetto-NO-SPAM@yahoo.com', + 'jcastagnetto@NoSpam-yahoo.com', + 'jesusmc@scripps.edu', + 'jmcastagnetto@chek2.com', + 'jmcastagnetto@yahoo.com', + 'some-wrong@asdas.com', + 'wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff', + 'wrong-email-address@lists.php.net', +); + +$emailsThatAreEmailableAddresses = array_filter($emails, static function (string $email): bool { + return is_emailable_address($email); +}); + +var_dump($emailsThatAreEmailableAddresses); + +?> +--EXPECT-- +array(6) { + [0]=> + string(21) "asasasd324324@php.net" + [1]=> + string(35) "jcastagnetto-delete-this-@yahoo.com" + [3]=> + string(30) "jcastagnetto-NO-SPAM@yahoo.com" + [5]=> + string(19) "jesusmc@scripps.edu" + [7]=> + string(23) "jmcastagnetto@yahoo.com" + [8]=> + string(20) "some-wrong@asdas.com" +}

« previous php.webmaster (#30321) next »