2017-05-29 13:42:42 +02:00
|
|
|
<?php
|
|
|
|
|
2017-04-23 22:23:34 +02:00
|
|
|
namespace SilverStripe\Subsites\Tests;
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-04-23 22:23:34 +02:00
|
|
|
use SilverStripe\Subsites\Forms\WildcardDomainField;
|
2024-09-10 01:28:27 +02:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
2017-05-29 13:42:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests {@see WildcardDomainField}
|
|
|
|
*/
|
2017-06-01 15:57:53 +02:00
|
|
|
class WildcardDomainFieldTest extends SapphireTest
|
|
|
|
{
|
2017-05-29 13:42:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that valid domains are accepted
|
|
|
|
*
|
2017-06-01 15:10:07 +02:00
|
|
|
* @param $domain
|
2017-05-29 13:42:42 +02:00
|
|
|
*/
|
2024-09-10 01:28:27 +02:00
|
|
|
#[DataProvider('validDomains')]
|
2017-06-01 15:57:53 +02:00
|
|
|
public function testValidDomains($domain)
|
|
|
|
{
|
2017-05-29 13:42:42 +02:00
|
|
|
$field = new WildcardDomainField('DomainField');
|
|
|
|
$this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain name");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that valid domains are accepted
|
|
|
|
*
|
2017-06-01 15:10:07 +02:00
|
|
|
* @param $domain
|
2017-05-29 13:42:42 +02:00
|
|
|
*/
|
2024-09-10 01:28:27 +02:00
|
|
|
#[DataProvider('invalidDomains')]
|
2017-06-01 15:57:53 +02:00
|
|
|
public function testInvalidDomains($domain)
|
|
|
|
{
|
2017-05-29 13:42:42 +02:00
|
|
|
$field = new WildcardDomainField('DomainField');
|
|
|
|
$this->assertFalse($field->checkHostname($domain), "Validate that {$domain} is an invalid domain name");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that valid domains are accepted
|
|
|
|
*
|
2017-06-01 15:10:07 +02:00
|
|
|
* @param $domain
|
2017-05-29 13:42:42 +02:00
|
|
|
*/
|
2024-09-10 01:28:27 +02:00
|
|
|
#[DataProvider('validWildcards')]
|
2017-06-01 15:57:53 +02:00
|
|
|
public function testValidWildcards($domain)
|
|
|
|
{
|
2017-05-29 13:42:42 +02:00
|
|
|
$field = new WildcardDomainField('DomainField');
|
|
|
|
$this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain wildcard");
|
|
|
|
}
|
|
|
|
|
2024-09-10 01:28:27 +02:00
|
|
|
public static function validDomains()
|
2017-06-01 15:57:53 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
['www.mysite.com'],
|
|
|
|
['domain7'],
|
|
|
|
['mysite.co.n-z'],
|
|
|
|
['subdomain.my-site.com'],
|
2017-09-11 21:20:42 +02:00
|
|
|
['subdomain.mysite'],
|
|
|
|
['subdomain.mysite.com:80'],
|
|
|
|
['mysite:80']
|
2017-06-01 15:57:53 +02:00
|
|
|
];
|
2017-05-29 13:42:42 +02:00
|
|
|
}
|
|
|
|
|
2024-09-10 01:28:27 +02:00
|
|
|
public static function invalidDomains()
|
2017-06-01 15:57:53 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
['-mysite'],
|
|
|
|
['.mysite'],
|
|
|
|
['mys..ite'],
|
|
|
|
['mysite-'],
|
|
|
|
['mysite.'],
|
|
|
|
['-mysite.*'],
|
|
|
|
['.mysite.*'],
|
|
|
|
['mys..ite.*'],
|
|
|
|
['*.mysite-'],
|
2017-09-11 21:20:42 +02:00
|
|
|
['*.mysite.'],
|
|
|
|
[':1234']
|
2017-06-01 15:57:53 +02:00
|
|
|
];
|
2017-05-29 13:42:42 +02:00
|
|
|
}
|
2017-04-23 22:23:34 +02:00
|
|
|
|
2024-09-10 01:28:27 +02:00
|
|
|
public static function validWildcards()
|
2017-06-01 15:57:53 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
['*.mysite.com'],
|
|
|
|
['mys*ite.com'],
|
|
|
|
['*.my-site.*'],
|
|
|
|
['*']
|
|
|
|
];
|
2017-05-29 13:42:42 +02:00
|
|
|
}
|
|
|
|
}
|