public function SessionExampleTest::testUserIsolation in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/session_example/tests/src/Functional/SessionExampleTest.php \Drupal\Tests\session_example\Functional\SessionExampleTest::testUserIsolation()
 
Ensure the session data does not follow different users around.
File
- session_example/
tests/ src/ Functional/ SessionExampleTest.php, line 136  
Class
- SessionExampleTest
 - Tests the basic functions of the Session Example module.
 
Namespace
Drupal\Tests\session_example\FunctionalCode
public function testUserIsolation() {
  $assert = $this
    ->assertSession();
  // Our setUp() method has already logged in a user, so let's add some data.
  $form_data = [
    'name' => 'Sir Lancelot',
    'quest' => 'To seek the Grail',
    'color' => 'blue',
  ];
  $this
    ->drupalPostForm(Url::fromRoute('session_example.form'), $form_data, 'Save');
  // Check that the report shows our information.
  $this
    ->clickLink('Check here');
  foreach ($form_data as $value) {
    $assert
      ->pageTextContains($value);
  }
  // Let's log in a new user and make sure they can't see the other user's
  // data.
  $this
    ->drupalLogin($this
    ->createUser([
    'access content',
  ]));
  $this
    ->drupalGet(Url::fromRoute('session_example.view'));
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextContains('No name');
  $assert
    ->pageTextContains('No email');
  $assert
    ->pageTextContains('No quest');
  $assert
    ->pageTextContains('No color');
}