public function FapiExampleTest::doTestRoutes in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/form_api_example/tests/src/Functional/FapiExampleTest.php \Drupal\Tests\form_api_example\Functional\FapiExampleTest::doTestRoutes()
Tests links.
1 call to FapiExampleTest::doTestRoutes()
- FapiExampleTest::testFunctional in form_api_example/
tests/ src/ Functional/ FapiExampleTest.php - Aggregate all the tests.
File
- form_api_example/
tests/ src/ Functional/ FapiExampleTest.php, line 63
Class
- FapiExampleTest
- Ensure that the form_api_example forms work properly.
Namespace
Drupal\Tests\form_api_example\FunctionalCode
public function doTestRoutes() {
$assertion = $this
->assertSession();
// Routes with menu links, and their form buttons.
$routes = [
'form_api_example.description' => [],
'form_api_example.simple_form' => [
'Submit',
],
'form_api_example.input_demo' => [
'Submit',
],
'form_api_example.state_demo' => [
'Submit',
],
'form_api_example.container_demo' => [
'Submit',
],
'form_api_example.vertical_tabs_demo' => [
'Submit',
],
// Modal form has a submit button, but requires input.
'form_api_example.modal_form' => [],
'form_api_example.ajax_color_demo' => [
'Submit',
],
'form_api_example.build_demo' => [
'Submit',
],
'form_api_example.ajax_addmore' => [
'Submit',
],
// Multistep form has submit buttons, but requires input.
'form_api_example.multistep_form' => [],
];
// Ensure the links appear in the tools menu sidebar.
$this
->drupalGet('');
foreach (array_keys($routes) as $route) {
$assertion
->linkByHrefExists(Url::fromRoute($route)
->getInternalPath());
}
// Go to all the routes and click all the buttons.
foreach ($routes as $route => $buttons) {
$path = Url::fromRoute($route);
error_log($route);
$this
->drupalGet($path);
$assertion
->statusCodeEquals(200);
foreach ($buttons as $button) {
$this
->drupalPostForm($path, [], $button);
$assertion
->statusCodeEquals(200);
}
}
}