Issue #2832856 by yogeshmpawar, LoMo, ranjith_kumar_k_u, smustgrave: Improve PathElementFormTest
parent
66c8012275
commit
d5b2aa9be6
|
@ -92,10 +92,10 @@ class PathElementFormTest extends KernelTestBase implements FormInterface {
|
|||
];
|
||||
|
||||
// A non required converted path.
|
||||
$form['optional_validate'] = [
|
||||
$form['optional_validate_route'] = [
|
||||
'#type' => 'path',
|
||||
'#required' => FALSE,
|
||||
'#title' => 'optional_validate',
|
||||
'#title' => 'optional_validate_route',
|
||||
'#convert_path' => PathElement::CONVERT_ROUTE,
|
||||
];
|
||||
|
||||
|
@ -147,6 +147,8 @@ class PathElementFormTest extends KernelTestBase implements FormInterface {
|
|||
'required_non_validate' => 'magic-ponies',
|
||||
'required_validate_route' => 'user/' . $this->testUser->id(),
|
||||
'required_validate_url' => 'user/' . $this->testUser->id(),
|
||||
'optional_validate' => 'user/' . $this->testUser->id(),
|
||||
'optional_validate_route' => 'user/' . $this->testUser->id(),
|
||||
]);
|
||||
$form_builder = $this->container->get('form_builder');
|
||||
$form_builder->submitForm($this, $form_state);
|
||||
|
@ -159,6 +161,12 @@ class PathElementFormTest extends KernelTestBase implements FormInterface {
|
|||
$this->assertInstanceOf(Url::class, $url);
|
||||
$this->assertEquals('entity.user.canonical', $url->getRouteName());
|
||||
$this->assertEquals(['user' => $this->testUser->id()], $url->getRouteParameters());
|
||||
$this->assertEquals($form_state->getValue('optional_validate_route'), [
|
||||
'route_name' => 'entity.user.canonical',
|
||||
'route_parameters' => [
|
||||
'user' => $this->testUser->id(),
|
||||
],
|
||||
]);
|
||||
|
||||
// Test #required.
|
||||
$form_state = (new FormState())
|
||||
|
@ -173,11 +181,10 @@ class PathElementFormTest extends KernelTestBase implements FormInterface {
|
|||
$this->assertCount(1, $errors);
|
||||
$this->assertEquals(['required_validate' => t('@name field is required.', ['@name' => 'required_validate'])], $errors);
|
||||
|
||||
// Test invalid parameters.
|
||||
// Test invalid required parameters.
|
||||
$form_state = (new FormState())
|
||||
->setValues([
|
||||
'required_validate' => 'user/74',
|
||||
'required_non_validate' => 'magic-ponies',
|
||||
'required_validate_route' => 'user/74',
|
||||
'required_validate_url' => 'user/74',
|
||||
]);
|
||||
|
@ -186,8 +193,33 @@ class PathElementFormTest extends KernelTestBase implements FormInterface {
|
|||
|
||||
// Valid form state.
|
||||
$errors = $form_state->getErrors();
|
||||
$this->assertCount(3, $errors);
|
||||
$this->assertEquals(['required_validate' => t('This path does not exist or you do not have permission to link to %path.', ['%path' => 'user/74']), 'required_validate_route' => t('This path does not exist or you do not have permission to link to %path.', ['%path' => 'user/74']), 'required_validate_url' => t('This path does not exist or you do not have permission to link to %path.', ['%path' => 'user/74'])], $errors);
|
||||
$this->assertCount(4, $errors);
|
||||
$this->assertEquals([
|
||||
'required_validate' => t('This path does not exist or you do not have permission to link to %path.', ['%path' => 'user/74']),
|
||||
'required_validate_route' => t('This path does not exist or you do not have permission to link to %path.', ['%path' => 'user/74']),
|
||||
'required_validate_url' => t('This path does not exist or you do not have permission to link to %path.', ['%path' => 'user/74']),
|
||||
'required_non_validate' => t('@name field is required.', ['@name' => 'required_non_validate']),
|
||||
], $errors);
|
||||
|
||||
// Test invalid optional parameters.
|
||||
$form_state = (new FormState())->setValues([
|
||||
'required_validate' => 'user/' . $this->testUser->id(),
|
||||
'required_non_validate' => 'magic-ponies',
|
||||
'required_validate_route' => 'user/' . $this->testUser->id(),
|
||||
'required_validate_url' => 'user/' . $this->testUser->id(),
|
||||
// Set invalid optional parameters should cause an error.
|
||||
'optional_validate' => 'user/74',
|
||||
'optional_validate_route' => 'user/74',
|
||||
]);
|
||||
$form_builder = $this->container->get('form_builder');
|
||||
$form_builder->submitForm($this, $form_state);
|
||||
// Valid form state.
|
||||
$errors = $form_state->getErrors();
|
||||
$this->assertEquals(count($errors), 2);
|
||||
$this->assertEquals($errors, [
|
||||
'optional_validate' => t('This path does not exist or you do not have permission to link to %path.', ['%path' => 'user/74']),
|
||||
'optional_validate_route' => t('This path does not exist or you do not have permission to link to %path.', ['%path' => 'user/74']),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue