From 16cd8caef3336d88ebf6dc77e7281968a9380859 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 7 Jan 2024 19:16:30 +0100 Subject: tests: Add tests for check_account_email --- tests/unit/includes/AccountTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/includes/AccountTest.php b/tests/unit/includes/AccountTest.php index d123a0c70..af5bcd3c1 100644 --- a/tests/unit/includes/AccountTest.php +++ b/tests/unit/includes/AccountTest.php @@ -9,4 +9,26 @@ class AccountTest extends Zotlabs\Tests\Unit\UnitTestCase { $this->assertNotFalse($account); $this->assertEquals($this->fixtures['account'][0]['account_email'], $account['account_email']); } + + /** + * Test the `check_account_email` function. + * + * @dataProvider check_account_email_provider + */ + public function test_check_account_email(string $email, array $expected) { + $this->assertEquals($expected, check_account_email($email)); + } + + function check_account_email_provider() : array { + return [ + // Empty and valid emails return the same result + ['', ['error' => false, 'message' => '']], + ['newuser@example.com', ['error' => false, 'message' => '']], + + // Check emails not valid for various readons + ['not_an_email', ['error' => true, 'message' => 'The provided email address is not valid']], + ['baduser@example.com', ['error' => true, 'message' => 'The provided email domain is not among those allowed on this site']], + ['hubzilla@example.com', ['error' => true, 'message' => 'The provided email address is already registered at this site']], + ]; + } } -- cgit v1.2.3