LogoutTabTest.php in Logout Tab 8
File
tests/src/Functional/LogoutTabTest.php
View source
<?php
namespace Drupal\Tests\logouttab\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class LogoutTabTest extends BrowserTestBase {
protected static $modules = [
'block',
'logouttab',
'user',
];
protected $defaultTheme = 'stark';
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());
$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());
$session
->responseContains(Url::fromRoute('<front>', [], [
'absolute' => TRUE,
])
->toString());
$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'));
$this
->drupalGet($user
->toUrl());
$tabs = $this
->cssSelect("#block-{$block} ul li a");
$this
->assertCount(3, $tabs);
$this
->assertSame('Log out', $tabs[0]
->getText());
$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);
}
}