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;
|
2017-05-29 13:42:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests {@see WildcardDomainField}
|
|
|
|
*/
|
|
|
|
class WildcardDomainFieldTest extends SapphireTest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that valid domains are accepted
|
|
|
|
*
|
|
|
|
* @dataProvider validDomains
|
2017-06-01 15:10:07 +02:00
|
|
|
* @param $domain
|
2017-05-29 13:42:42 +02:00
|
|
|
*/
|
|
|
|
public function testValidDomains($domain) {
|
|
|
|
$field = new WildcardDomainField('DomainField');
|
|
|
|
$this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain name");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that valid domains are accepted
|
|
|
|
*
|
|
|
|
* @dataProvider invalidDomains
|
2017-06-01 15:10:07 +02:00
|
|
|
* @param $domain
|
2017-05-29 13:42:42 +02:00
|
|
|
*/
|
|
|
|
public function testInvalidDomains($domain) {
|
|
|
|
$field = new WildcardDomainField('DomainField');
|
|
|
|
$this->assertFalse($field->checkHostname($domain), "Validate that {$domain} is an invalid domain name");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that valid domains are accepted
|
|
|
|
*
|
|
|
|
* @dataProvider validWildcards
|
2017-06-01 15:10:07 +02:00
|
|
|
* @param $domain
|
2017-05-29 13:42:42 +02:00
|
|
|
*/
|
|
|
|
public function testValidWildcards($domain) {
|
|
|
|
$field = new WildcardDomainField('DomainField');
|
|
|
|
$this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain wildcard");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validDomains() {
|
|
|
|
return array(
|
|
|
|
array('www.mysite.com'),
|
|
|
|
array('domain7'),
|
|
|
|
array('mysite.co.n-z'),
|
|
|
|
array('subdomain.my-site.com'),
|
|
|
|
array('subdomain.mysite')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function invalidDomains() {
|
|
|
|
return array(
|
|
|
|
array('-mysite'),
|
|
|
|
array('.mysite'),
|
|
|
|
array('mys..ite'),
|
|
|
|
array('mysite-'),
|
|
|
|
array('mysite.'),
|
|
|
|
array('-mysite.*'),
|
|
|
|
array('.mysite.*'),
|
|
|
|
array('mys..ite.*'),
|
|
|
|
array('*.mysite-'),
|
|
|
|
array('*.mysite.')
|
|
|
|
);
|
|
|
|
}
|
2017-04-23 22:23:34 +02:00
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
public function validWildcards() {
|
|
|
|
return array(
|
|
|
|
array('*.mysite.com'),
|
|
|
|
array('mys*ite.com'),
|
|
|
|
array('*.my-site.*'),
|
|
|
|
array('*')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|