public function LogoutTabTest::testBaseSettings in Logout Tab 8
Tests that the module actually works.
File
- tests/
src/ Functional/ LogoutTabTest.php, line 28
Class
- LogoutTabTest
- Tests the module functionality.
Namespace
Drupal\Tests\logouttab\FunctionalCode
public function testBaseSettings() {
$block = strtolower($this
->randomMachineName());
$this
->drupalPlaceBlock('local_tasks_block', [
'id' => $block,
]);
$settings = '/admin/config/people/logouttab';
$this
->drupalGet($settings);
$this
->assertSession()
->statusCodeEquals(403);
$user = $this
->createUser([
'administer users',
]);
$this
->drupalLogin($user);
$tabs = $this
->cssSelect("#block-{$block} ul li a");
$this
->assertCount(3, $tabs);
$this
->assertSame('Log out', $tabs[2]
->getText());
// Test default settings.
$this
->drupalGet($settings);
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$element = $this
->cssSelect('input[name="url"]');
$this
->assertSame('user/logout', $element[0]
->getValue());
$element = $this
->cssSelect('select[name="weight"]');
$this
->assertSame('8', $element[0]
->getValue());
// Check field prefix works.
$session
->responseContains(Url::fromRoute('<front>', [], [
'absolute' => TRUE,
])
->toString());
// Check cacheability works.
$edit = [
'weight' => -30,
];
$this
->drupalPostForm(NULL, $edit, 'Save configuration');
$element = $this
->cssSelect('select[name="weight"]');
$this
->assertSame('-30', $element[0]
->getValue());
$this
->assertSame(-30, \Drupal::config('logouttab.settings')
->get('weight'));
// Check the tab displayed first.
$this
->drupalGet($user
->toUrl());
$tabs = $this
->cssSelect("#block-{$block} ul li a");
$this
->assertCount(3, $tabs);
$this
->assertSame('Log out', $tabs[0]
->getText());
// Check tabs are not visible for other users.
$this
->drupalLogin($this
->createUser([
'access user profiles',
]));
$this
->drupalGet($user
->toUrl());
$this
->assertSession()
->responseContains($user
->getDisplayName());
$tabs = $this
->cssSelect("#block-{$block} ul li a");
$this
->assertCount(0, $tabs);
}