diff options
Diffstat (limited to 'tests/unit/includes/NetworkTest.php')
-rw-r--r-- | tests/unit/includes/NetworkTest.php | 70 |
1 files changed, 60 insertions, 10 deletions
diff --git a/tests/unit/includes/NetworkTest.php b/tests/unit/includes/NetworkTest.php index 9fb00e9d3..0d99fc9c3 100644 --- a/tests/unit/includes/NetworkTest.php +++ b/tests/unit/includes/NetworkTest.php @@ -7,12 +7,6 @@ class NetworkTest extends Zotlabs\Tests\Unit\UnitTestCase { - public function setUp() : void { - parent::setUp(); - - \App::set_baseurl("https://mytest.org"); - } - /** * @dataProvider localUrlTestProvider */ @@ -20,10 +14,10 @@ class NetworkTest extends Zotlabs\Tests\Unit\UnitTestCase { $this->assertEquals($expected, is_local_url($url)); } - public function localUrlTestProvider() : array { + public static function localUrlTestProvider() : array { return [ [ '/some/path', true ], - [ 'https://mytest.org/some/path', true ], + [ 'https://hubzilla.test/some/path', true ], [ 'https://other.site/some/path', false ], ]; } @@ -47,7 +41,7 @@ class NetworkTest extends Zotlabs\Tests\Unit\UnitTestCase { $this->assertTrue(validate_email($email)); } - function validate_email_provider() : array { + public static function validate_email_provider() : array { return [ // First some invalid email addresses ['', false], @@ -66,7 +60,63 @@ class NetworkTest extends Zotlabs\Tests\Unit\UnitTestCase { ['some.email@example.cancerresearch', true], // And internationalized TLD's - ['some.email@example.شبكة', true] + ['some.email@example.شبكة', true], + + // Allow plus/minus addressing + ['address+tag@example.com', true], + ['address-tag@example.com', true], ]; } + + /** + * Test the unparse_url function. + * + */ + public function test_unparse_url_full() + { + $parsed_url = [ + 'scheme' => 'https', + 'host' => 'www.example.com', + 'port' => '8080', + 'user' => 'username', + 'pass' => 'password', + 'path' => '/path', + 'query' => 'param=value', + 'fragment' => 'section' + ]; + + $expected = 'https://username:password@www.example.com:8080/path?param=value#section'; + $this->assertEquals($expected, unparse_url($parsed_url)); + } + + public function test_unparse_url_partial() + { + $parsed_url = [ + 'scheme' => 'http', + 'host' => 'example.com', + 'path' => '/index.php' + ]; + + $expected = 'http://example.com/index.php'; + $this->assertEquals($expected, unparse_url($parsed_url)); + } + + public function test_unparse_url_custom() + { + $parsed_url = [ + 'scheme' => 'https', + 'host' => 'www.example.com', + 'port' => '443', + 'path' => '/api' + ]; + + $parts = ['scheme', 'host']; + $expected = 'https://www.example.com'; + $this->assertEquals($expected, unparse_url($parsed_url, $parts)); + } + + public function test_unparse_url_empty() + { + $this->assertEquals('', unparse_url([])); + } } |