You are here

public function RenderExampleMenuTest::testRenderExampleLinksExist in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/render_example/tests/src/Functional/RenderExampleMenuTest.php \Drupal\Tests\render_example\Functional\RenderExampleMenuTest::testRenderExampleLinksExist()

Verify and validate that default menu links were loaded for this module.

File

render_example/tests/src/Functional/RenderExampleMenuTest.php, line 43

Class

RenderExampleMenuTest
Test the user-facing menus in Render Example.

Namespace

Drupal\Tests\render_example\Functional

Code

public function testRenderExampleLinksExist() {

  // Login a user that can access content.
  $this
    ->drupalLogin($this
    ->createUser([
    'access content',
    'access user profiles',
  ]));
  $assertion = $this
    ->assertSession();

  // Routes with menu links, and their form buttons.
  $routes = [
    'render_example.description' => [],
    'render_example.altering' => [
      'Save configuration',
    ],
    'render_example.arrays' => [],
  ];

  // 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.
  $routes = array_merge($routes, $routes);
  foreach ($routes as $route => $buttons) {
    $path = Url::fromRoute($route);
    $this
      ->drupalGet($path);
    $assertion
      ->statusCodeEquals(200);
    foreach ($buttons as $button) {
      $this
        ->drupalPostForm($path, [], $button);
      $assertion
        ->statusCodeEquals(200);
    }
  }
}