You are here

function UserBlocksTest::testUserLoginBlockVisibility in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Tests/UserBlocksTest.php \Drupal\user\Tests\UserBlocksTest::testUserLoginBlockVisibility()

Tests that user login block is hidden from user/login.

File

core/modules/user/src/Tests/UserBlocksTest.php, line 45
Contains \Drupal\user\Tests\UserBlocksTest.

Class

UserBlocksTest
Tests user blocks.

Namespace

Drupal\user\Tests

Code

function testUserLoginBlockVisibility() {

  // Array keyed list where key being the URL address and value being expected
  // visibility as boolean type.
  $paths = [
    'node' => TRUE,
    'user/login' => FALSE,
    'user/register' => TRUE,
    'user/password' => TRUE,
  ];
  foreach ($paths as $path => $expected_visibility) {
    $this
      ->drupalGet($path);
    $elements = $this
      ->xpath('//div[contains(@class,"block-user-login-block") and @role="form"]');
    if ($expected_visibility) {
      $this
        ->assertTrue(!empty($elements), 'User login block in path "' . $path . '" should be visible');
    }
    else {
      $this
        ->assertTrue(empty($elements), 'User login block in path "' . $path . '" should not be visible');
    }
  }
}