2018-02-28 03:57:35 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace common\tests\unit\validators;
|
2018-02-28 03:57:35 +05:30
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\unit\TestCase;
|
2019-02-23 04:41:57 +05:30
|
|
|
use common\validators\MinecraftServerAddressValidator;
|
2018-02-28 03:57:35 +05:30
|
|
|
|
|
|
|
class MinecraftServerAddressValidatorTest extends TestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider domainNames
|
|
|
|
*/
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testValidate(string $address, bool $shouldBeValid): void {
|
2018-02-28 03:57:35 +05:30
|
|
|
$validator = new MinecraftServerAddressValidator();
|
2019-02-26 04:56:02 +05:30
|
|
|
$validator->message = 'mock message';
|
2018-02-28 03:57:35 +05:30
|
|
|
$validator->validate($address, $errors);
|
2019-02-26 04:56:02 +05:30
|
|
|
if ($shouldBeValid) {
|
|
|
|
$this->assertNull($errors);
|
|
|
|
} else {
|
|
|
|
$this->assertSame('mock message', $errors);
|
|
|
|
}
|
2018-02-28 03:57:35 +05:30
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function domainNames(): array {
|
2018-02-28 03:57:35 +05:30
|
|
|
return [
|
2019-02-26 04:56:02 +05:30
|
|
|
['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 03:57:35 +05:30
|
|
|
['http://ely.by', false],
|
|
|
|
['http://ely.by:80', false],
|
|
|
|
['ely.by/abcd', false],
|
|
|
|
['ely.by?abcd', false],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|