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>
|
|
|
|
*/
|
|
|
|
|
2022-08-01 22:22:04 +12:00
|
|
|
namespace Tests\Unit\Network\Validators;
|
2021-03-24 06:27:51 +13:00
|
|
|
|
2022-08-01 22:22:04 +12:00
|
|
|
use Appwrite\Network\Validator\URL;
|
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-10-07 15:09:22 +13:00
|
|
|
$this->assertEquals(true, $this->url->isValid('https://example.com/foo%2\u00c2\u00ä9zbär'));
|
2021-03-24 06:27:51 +13:00
|
|
|
}
|
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
|
|
|
}
|