You are here

public function UserBlocksTest::testUserLoginBlockVisibility in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/UserBlocksTest.php \Drupal\Tests\user\Functional\UserBlocksTest::testUserLoginBlockVisibility()
  2. 10 core/modules/user/tests/src/Functional/UserBlocksTest.php \Drupal\Tests\user\Functional\UserBlocksTest::testUserLoginBlockVisibility()

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

File

core/modules/user/tests/src/Functional/UserBlocksTest.php, line 47

Class

UserBlocksTest
Tests user blocks.

Namespace

Drupal\Tests\user\Functional

Code

public 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);
    if ($expected_visibility) {
      $this
        ->assertSession()
        ->elementExists('xpath', '//div[contains(@class,"block-user-login-block") and @role="form"]');
    }
    else {
      $this
        ->assertSession()
        ->elementNotExists('xpath', '//div[contains(@class,"block-user-login-block") and @role="form"]');
    }
  }
}