2018-02-28 01:27:35 +03:00
|
|
|
<?php
|
2019-02-20 22:58:52 +03:00
|
|
|
namespace common\tests\unit\validators;
|
2018-02-28 01:27:35 +03:00
|
|
|
|
2019-02-20 22:58:52 +03:00
|
|
|
use common\tests\unit\TestCase;
|
2019-02-23 02:11:57 +03:00
|
|
|
use common\validators\MinecraftServerAddressValidator;
|
2018-02-28 01:27:35 +03:00
|
|
|
|
|
|
|
class MinecraftServerAddressValidatorTest extends TestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider domainNames
|
|
|
|
*/
|
|
|
|
public function testValidate($address, $shouldBeValid) {
|
|
|
|
$validator = new MinecraftServerAddressValidator();
|
2019-02-26 02:26:02 +03:00
|
|
|
$validator->message = 'mock message';
|
2018-02-28 01:27:35 +03:00
|
|
|
$validator->validate($address, $errors);
|
2019-02-26 02:26:02 +03:00
|
|
|
if ($shouldBeValid) {
|
|
|
|
$this->assertNull($errors);
|
|
|
|
} else {
|
|
|
|
$this->assertSame('mock message', $errors);
|
|
|
|
}
|
2018-02-28 01:27:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function domainNames() {
|
|
|
|
return [
|
2019-02-26 02:26:02 +03:00
|
|
|
['localhost', true],
|
|
|
|
['localhost:25565', true],
|
|
|
|
['mc.hypixel.net', true],
|
|
|
|
['mc.hypixel.net:25565', true],
|
|
|
|
['136.243.88.97', true],
|
|
|
|
['136.243.88.97:25565', true],
|
2018-02-28 01:27:35 +03:00
|
|
|
['http://ely.by', false],
|
|
|
|
['http://ely.by:80', false],
|
|
|
|
['ely.by/abcd', false],
|
|
|
|
['ely.by?abcd', false],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|