View source
<?php
namespace Drupal\Tests\node_revision_delete\Functional;
use Drupal\Tests\BrowserTestBase;
class NodeRevisionDeleteAdminSettingsTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'node_revision_delete',
'node',
];
protected $configurationFileName;
public function setUp() {
parent::setUp();
$this->configurationFileName = 'node_revision_delete.settings';
}
public function testConfigurationForm() {
$this
->drupalGet('/admin/config/content/node_revision_delete');
$this
->assertSession()
->statusCodeEquals(403);
$account = $this
->drupalCreateUser([
'administer node_revision_delete',
'access administration pages',
]);
$this
->drupalLogin($account);
$this
->drupalGet('/admin/config/content');
$this
->assertSession()
->linkByHrefExists('/admin/config/content/node_revision_delete');
$this
->drupalGet('/admin/config/content/node_revision_delete');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->elementTextContains('css', 'h1', 'Node Revision Delete');
$this
->assertSession()
->checkboxNotChecked('run_now');
$this
->assertSession()
->checkboxNotChecked('dry_run');
$config_factory = $this->container
->get('config.factory');
$form_values = [
[
'delete_newer' => TRUE,
'node_revision_delete_cron' => 20,
'node_revision_delete_time' => 86400,
'node_revision_delete_minimum_age_to_delete_time_max_number' => 10,
'node_revision_delete_minimum_age_to_delete_time_time' => 'weeks',
'node_revision_delete_when_to_delete_time_max_number' => 30,
'node_revision_delete_when_to_delete_time_time' => 'days',
'run_now' => FALSE,
'dry_run' => FALSE,
],
[
'delete_newer' => FALSE,
'node_revision_delete_cron' => 15,
'node_revision_delete_time' => 7776000,
'node_revision_delete_minimum_age_to_delete_time_max_number' => 20,
'node_revision_delete_minimum_age_to_delete_time_time' => 'days',
'node_revision_delete_when_to_delete_time_max_number' => 24,
'node_revision_delete_when_to_delete_time_time' => 'months',
'run_now' => FALSE,
'dry_run' => FALSE,
],
];
foreach ($form_values as $edit) {
$this
->submitForm($edit, 'op');
$this
->assertSession()
->pageTextContains('The configuration options have been saved.');
$config_file = $config_factory
->get($this->configurationFileName);
$this
->assertEquals($edit['delete_newer'], $config_file
->get('delete_newer'));
$this
->assertEquals($edit['node_revision_delete_cron'], $config_file
->get('node_revision_delete_cron'));
$this
->assertEquals($edit['node_revision_delete_time'], $config_file
->get('node_revision_delete_time'));
$this
->assertEquals($edit['node_revision_delete_minimum_age_to_delete_time_max_number'], $config_file
->get('node_revision_delete_minimum_age_to_delete_time')['max_number']);
$this
->assertEquals($edit['node_revision_delete_minimum_age_to_delete_time_time'], $config_file
->get('node_revision_delete_minimum_age_to_delete_time')['time']);
$this
->assertEquals($edit['node_revision_delete_when_to_delete_time_max_number'], $config_file
->get('node_revision_delete_when_to_delete_time')['max_number']);
$this
->assertEquals($edit['node_revision_delete_when_to_delete_time_time'], $config_file
->get('node_revision_delete_when_to_delete_time')['time']);
}
}
}