2021-03-24 06:27:51 +13:00
|
|
|
<?php
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2021-03-24 06:27:51 +13:00
|
|
|
/**
|
|
|
|
* Utopia PHP Framework
|
|
|
|
*
|
|
|
|
* @package Framework
|
|
|
|
* @subpackage Tests
|
|
|
|
*
|
|
|
|
* @link https://github.com/utopia-php/framework
|
|
|
|
* @author Appwrite Team <team@appwrite.io>
|
|
|
|
* @version 1.0 RC4
|
|
|
|
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
|
|
|
|
*/
|
|
|
|
|
2021-03-25 07:34:47 +13:00
|
|
|
namespace Appwrite\Network\Validator;
|
2021-03-24 06:27:51 +13:00
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class URLTest extends TestCase
|
|
|
|
{
|
2022-02-17 04:16:37 +13:00
|
|
|
protected ?URL $url;
|
2021-03-24 06:27:51 +13:00
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
public function setUp(): void
|
2021-03-24 06:27:51 +13:00
|
|
|
{
|
|
|
|
$this->url = new URL();
|
|
|
|
}
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
public function tearDown(): void
|
2021-03-24 06:27:51 +13:00
|
|
|
{
|
|
|
|
$this->url = null;
|
|
|
|
}
|
|
|
|
|
2022-02-17 04:16:37 +13:00
|
|
|
public function testIsValid(): void
|
2021-03-24 06:27:51 +13:00
|
|
|
{
|
2022-02-17 04:16:37 +13:00
|
|
|
$this->assertEquals('Value must be a valid URL', $this->url->getDescription());
|
2021-03-24 06:27:51 +13:00
|
|
|
$this->assertEquals(true, $this->url->isValid('http://example.com'));
|
|
|
|
$this->assertEquals(true, $this->url->isValid('https://example.com'));
|
|
|
|
$this->assertEquals(true, $this->url->isValid('htts://example.com')); // does not validate protocol
|
|
|
|
$this->assertEquals(false, $this->url->isValid('example.com')); // though, requires some kind of protocol
|
2022-05-24 02:54:50 +12:00
|
|
|
$this->assertEquals(false, $this->url->isValid('http:/example.com'));
|
2021-03-24 06:27:51 +13:00
|
|
|
$this->assertEquals(true, $this->url->isValid('http://exa-mple.com'));
|
|
|
|
$this->assertEquals(false, $this->url->isValid('htt@s://example.com'));
|
|
|
|
$this->assertEquals(true, $this->url->isValid('http://www.example.com/foo%2\u00c2\u00a9zbar'));
|
|
|
|
$this->assertEquals(true, $this->url->isValid('http://www.example.com/?q=%3Casdf%3E'));
|
|
|
|
}
|
2022-02-17 04:16:37 +13:00
|
|
|
|
|
|
|
public function testIsValidAllowedSchemes(): void
|
|
|
|
{
|
|
|
|
$this->url = new URL(['http', 'https']);
|
|
|
|
$this->assertEquals('Value must be a valid URL with following schemes (http, https)', $this->url->getDescription());
|
|
|
|
$this->assertEquals(true, $this->url->isValid('http://example.com'));
|
|
|
|
$this->assertEquals(true, $this->url->isValid('https://example.com'));
|
|
|
|
$this->assertEquals(false, $this->url->isValid('gopher://www.example.com'));
|
|
|
|
}
|
2021-03-24 06:27:51 +13:00
|
|
|
}
|