aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/includes
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-01-19 20:35:43 +0000
committerMario <mario@mariovavti.com>2024-01-19 20:35:43 +0000
commit00d403e729a1139a2c4f8b1fcbbcf75c69858023 (patch)
treef57bb086bfbc5ce211010e353e6aae708bbe84e2 /tests/unit/includes
parentd83e2daf36da64b8222b37ff63a278f189a1b59f (diff)
parent403539919a9a5b1e3e2ac9725a3b8b17403b2935 (diff)
downloadvolse-hubzilla-00d403e729a1139a2c4f8b1fcbbcf75c69858023.tar.gz
volse-hubzilla-00d403e729a1139a2c4f8b1fcbbcf75c69858023.tar.bz2
volse-hubzilla-00d403e729a1139a2c4f8b1fcbbcf75c69858023.zip
Merge branch 'improve-validate-email' into 'dev'
Improve validate_email function See merge request hubzilla/core!2088
Diffstat (limited to 'tests/unit/includes')
-rw-r--r--tests/unit/includes/NetworkTest.php89
1 files changed, 64 insertions, 25 deletions
diff --git a/tests/unit/includes/NetworkTest.php b/tests/unit/includes/NetworkTest.php
index 0b9b42e00..9fb00e9d3 100644
--- a/tests/unit/includes/NetworkTest.php
+++ b/tests/unit/includes/NetworkTest.php
@@ -5,29 +5,68 @@
* @package test.util
*/
-use PHPUnit\Framework\TestCase;
-
-require_once('include/network.php');
-
-class NetworkTest extends TestCase {
-
- public function setup() : void {
- \App::set_baseurl("https://mytest.org");
- }
-
- /**
- * @dataProvider localUrlTestProvider
- */
- public function testIsLocalURL($url, $expected) {
- $this->assertEquals($expected, is_local_url($url));
- }
-
- public function localUrlTestProvider() : array {
- return [
- [ '/some/path', true ],
- [ 'https://mytest.org/some/path', true ],
- [ 'https://other.site/some/path', false ],
- ];
- }
-}
+class NetworkTest extends Zotlabs\Tests\Unit\UnitTestCase {
+
+ public function setUp() : void {
+ parent::setUp();
+
+ \App::set_baseurl("https://mytest.org");
+ }
+
+ /**
+ * @dataProvider localUrlTestProvider
+ */
+ public function testIsLocalURL($url, $expected) {
+ $this->assertEquals($expected, is_local_url($url));
+ }
+
+ public function localUrlTestProvider() : array {
+ return [
+ [ '/some/path', true ],
+ [ 'https://mytest.org/some/path', true ],
+ [ 'https://other.site/some/path', false ],
+ ];
+ }
+
+ /**
+ * Test the validate_email function.
+ *
+ * @dataProvider validate_email_provider
+ */
+ public function test_validate_email(string $email, bool $expected) : void {
+ $this->assertEquals($expected, validate_email($email));
+ }
+ /**
+ * Test that the validate_email function is disabled when configured to.
+ *
+ * @dataProvider validate_email_provider
+ */
+ public function test_disable_validate_email(string $email) : void {
+ \Zotlabs\Lib\Config::Set('system', 'disable_email_validation', true);
+ $this->assertTrue(validate_email($email));
+ }
+
+ function validate_email_provider() : array {
+ return [
+ // First some invalid email addresses
+ ['', false],
+ ['not_an_email', false],
+ ['@not_an_email', false],
+ ['not@an@email', false],
+ ['not@an@email.com', false],
+
+ // then test valid addresses too
+ ['test@example.com', true],
+
+ // Should also work with international domains
+ ['some.email@dømain.net', true],
+
+ // Should also work with the new top-level domains
+ ['some.email@example.cancerresearch', true],
+
+ // And internationalized TLD's
+ ['some.email@example.شبكة', true]
+ ];
+ }
+}