xref: /web-php/tests/Unit/CleanAntiSpamTest.php (revision 33dd2a89)
1<?php
2
3declare(strict_types=1);
4
5namespace phpweb\Test\Unit;
6
7use PHPUnit\Framework;
8
9#[Framework\Attributes\CoversFunction('clean_AntiSPAM')]
10final class CleanAntiSpamTest extends Framework\TestCase
11{
12    public static function setUpBeforeClass(): void
13    {
14        require_once __DIR__ . '/../../include/email-validation.inc';
15    }
16
17    #[Framework\Attributes\DataProvider('provideEmailAndExpectedEmail')]
18    public function testCleanAntiSpamReturnsCleanedEmail(
19        string $email,
20        string $expectedEmail,
21    ): void
22    {
23        $cleanedEmail = clean_AntiSPAM($email);
24
25        self::assertSame($expectedEmail, $cleanedEmail);
26    }
27
28    /**
29     * @return \Generator<string, array{0: string, 1: string}>
30     */
31    public static function provideEmailAndExpectedEmail(): \Generator
32    {
33        $values = [
34            'asasasd324324@php.net' => 'asasasd324324@php.net',
35            'jcastagnetto-delete-this-@yahoo.com' => 'jcastagnetto@yahoo.com',
36            'jcastagnetto-i-hate-spam@NOSPAMyahoo.com' => 'jcastagnetto@yahoo.com',
37            'jcastagnetto-NO-SPAM@yahoo.com' => 'jcastagnetto@yahoo.com',
38            'jcastagnetto@NoSpam-yahoo.com' => 'jcastagnetto@yahoo.com',
39            'jesusmc@scripps.edu' => 'jesusmc@scripps.edu',
40            'jmcastagnetto@chek2.com' => 'jmcastagnetto@chek2.com',
41            'jmcastagnetto@yahoo.com' => 'jmcastagnetto@yahoo.com',
42            'some-wrong@asdas.com' => 'some-wrong@asdas.com',
43            'wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff' => 'wrong-address-with@@@@and-somestuff',
44            'wrong-email-address@lists.php.net' => 'wrong-email-address@lists.php.net',
45        ];
46
47        foreach ($values as $email => $expectedEmail) {
48            yield $email => [
49                $email,
50                $expectedEmail,
51            ];
52        }
53    }
54}
55