class RenameAdminPathsSettingsFormTest in Rename Admin Paths 8.2
@group tests
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\rename_admin_paths\Unit\Form\RenameAdminPathsSettingsFormTest
Expanded class hierarchy of RenameAdminPathsSettingsFormTest
File
- tests/
src/ Unit/ Form/ RenameAdminPathsSettingsFormTest.php, line 16
Namespace
Drupal\Tests\rename_admin_paths\Unit\FormView source
class RenameAdminPathsSettingsFormTest extends UnitTestCase {
public function testValidatePathWithoutValue() {
$element = [];
$this
->getForm()
->validate($element, $this
->getInvalidFormState());
}
/**
* @dataProvider validValues
*
* @param string $value
*/
public function testWithValidValue(string $value) {
$element = [
'#value' => $value,
];
$this
->getForm()
->validate($element, $this
->getValidFormState());
}
/**
* @dataProvider invalidValues
*
* @param string $value
*/
public function testWithInvalidValue(string $value) {
$element = [
'#value' => $value,
];
$this
->getForm()
->validate($element, $this
->getInvalidFormState());
}
/**
* @return \Generator
*/
public function validValues() {
(yield [
'backend',
]);
(yield [
'back-end',
]);
(yield [
'Backend',
]);
(yield [
'Back-End',
]);
(yield [
'Back_End',
]);
(yield [
'Back-End_123',
]);
(yield [
'admin2',
]);
(yield [
'user2',
]);
}
/**
* @return \Generator
*/
public function invalidValues() {
(yield [
'backend!',
]);
(yield [
'back@end',
]);
(yield [
'(Backend)',
]);
(yield [
'Back~End',
]);
(yield [
'Back=End',
]);
(yield [
'Back-End+123',
]);
(yield [
'admin',
]);
(yield [
'user',
]);
(yield [
'Admin',
]);
}
/**
* @return RenameAdminPathsSettingsForm
*/
private function getForm() {
$config = $this
->createMock(Config::class);
$routeBuilder = $this
->createMock(RouteBuilderInterface::class);
$translator = $this
->createMock(TranslationInterface::class);
$translator
->method('translateString')
->willReturn('Error');
return new RenameAdminPathsSettingsForm($config, $routeBuilder, $translator);
}
/**
* @return FormStateInterface
*/
private function getValidFormState() {
$formState = $this
->prophesize(FormStateInterface::class);
$formState
->setError()
->shouldNotBeCalled();
return $formState
->reveal();
}
/**
* @return FormStateInterface
*/
private function getInvalidFormState() {
$formState = $this
->prophesize(FormStateInterface::class);
$formState
->setError(Argument::any(), Argument::any())
->shouldBeCalled();
return $formState
->reveal();
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RenameAdminPathsSettingsFormTest:: |
private | function | ||
RenameAdminPathsSettingsFormTest:: |
private | function | ||
RenameAdminPathsSettingsFormTest:: |
private | function | ||
RenameAdminPathsSettingsFormTest:: |
public | function | ||
RenameAdminPathsSettingsFormTest:: |
public | function | ||
RenameAdminPathsSettingsFormTest:: |
public | function | @dataProvider invalidValues | |
RenameAdminPathsSettingsFormTest:: |
public | function | @dataProvider validValues | |
RenameAdminPathsSettingsFormTest:: |
public | function | ||
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |