function SessionExampleTest::testUserIsolation
Same name 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
-
modules/
session_example/ tests/ src/ Functional/ SessionExampleTest.php, line 140
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->drupalGet(Url::fromRoute('session_example.form'));
$this->submitForm($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');
}