View source
<?php
namespace Drupal\Tests\rename_admin_paths\Unit\Form;
use Drupal\rename_admin_paths\Form\RenameAdminPathsValidator;
use Drupal\Tests\UnitTestCase;
class RenameAdminPathsValidatorTest extends UnitTestCase {
public function testMatchDefaultPath(string $value) {
$this
->assertTrue(RenameAdminPathsValidator::isDefaultPath($value));
}
public function defaultPaths() {
(yield [
'user',
]);
(yield [
'admin',
]);
(yield [
'ADMIN',
]);
(yield [
'Admin',
]);
(yield [
'USER',
]);
(yield [
'User',
]);
}
public function testDefaultPath(string $value) {
$this
->assertFalse(RenameAdminPathsValidator::isDefaultPath($value));
}
public function nonDefaultPaths() {
(yield [
'user2',
]);
(yield [
'myadmin',
]);
(yield [
'backend',
]);
}
public function testValidPath(string $value) {
$this
->assertTrue(RenameAdminPathsValidator::isValidPath($value));
}
public function validPaths() {
(yield [
'backend',
]);
(yield [
'back-end',
]);
(yield [
'Backend',
]);
(yield [
'Back-End',
]);
(yield [
'Back_End',
]);
(yield [
'Back-End_123',
]);
(yield [
'admin2',
]);
(yield [
'user2',
]);
(yield [
'admin',
]);
(yield [
'user',
]);
(yield [
'Admin',
]);
}
public function testInvalidPath(string $value) {
$this
->assertFalse(RenameAdminPathsValidator::isValidPath($value));
}
public function invalidPaths() {
(yield [
'backend!',
]);
(yield [
'back@end',
]);
(yield [
'(Backend)',
]);
(yield [
'Back~End',
]);
(yield [
'Back=End',
]);
(yield [
'Back-End+123',
]);
(yield [
'admin!',
]);
(yield [
'@user',
]);
}
}