OnlyOneAdminSettingsTest.php in Allow a content type only once (Only One) 8
File
tests/src/Functional/OnlyOneAdminSettingsTest.php
View source
<?php
namespace Drupal\Tests\onlyone\Functional;
use Drupal\Tests\BrowserTestBase;
class OnlyOneAdminSettingsTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'onlyone',
];
public function testConfigurationForm() {
$this
->drupalGet('/admin/config/content/onlyone/settings');
$this
->assertSession()
->statusCodeEquals(403);
$account = $this
->drupalCreateUser([
'administer onlyone',
'access administration pages',
]);
$this
->drupalLogin($account);
$this
->drupalGet('/admin/config/content');
$this
->assertSession()
->linkByHrefExists('/admin/config/content/onlyone');
$this
->drupalGet('/admin/config/content/onlyone/settings');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->elementTextContains('css', 'h1', 'Only One Settings');
$this
->assertSession()
->checkboxNotChecked('onlyone_new_menu_entry');
$edit = [
'onlyone_new_menu_entry' => 1,
'onlyone_redirect' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'op');
$this
->assertSession()
->pageTextContains('The configuration options have been saved.');
$config_factory = $this->container
->get('config.factory');
$onlyone_new_menu_entry = $config_factory
->get('onlyone.settings')
->get('onlyone_new_menu_entry');
$onlyone_redirect = $config_factory
->get('onlyone.settings')
->get('onlyone_redirect');
$this
->assertTrue($onlyone_new_menu_entry, 'The configuration value for onlyone_new_menu_entry should be TRUE.');
$this
->assertTrue($onlyone_redirect, 'The configuration value for onlyone_redirect should be TRUE.');
$edit = [
'onlyone_new_menu_entry' => 0,
'onlyone_redirect' => 0,
];
$this
->drupalPostForm(NULL, $edit, 'op');
$onlyone_new_menu_entry = $config_factory
->get('onlyone.settings')
->get('onlyone_new_menu_entry');
$onlyone_redirect = $config_factory
->get('onlyone.settings')
->get('onlyone_redirect');
$this
->assertFalse($onlyone_new_menu_entry, 'The configuration value for onlyone_new_menu_entry should be FALSE.');
$this
->assertFalse($onlyone_redirect, 'The configuration value for onlyone_redirect should be FALSE.');
}
}