View source
<?php
namespace Drupal\Tests\auditfiles\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\RoleInterface;
use Drupal\Core\Url;
use Drupal\Tests\TestFileCreationTrait;
class AuditFilesConfigTest extends BrowserTestBase {
use TestFileCreationTrait;
protected static $modules = [
'node',
'file',
'user',
'auditfiles',
];
protected $user;
protected $rid;
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this->user = $this
->drupalCreateUser([
'configure audit files reports',
]);
$all_rids = $this->user
->getRoles();
unset($all_rids[array_search(RoleInterface::AUTHENTICATED_ID, $all_rids)]);
$this->rid = reset($all_rids);
}
public function testReportPage() {
$path = URL::fromRoute('auditfiles.auditfiles_configuration');
$session = $this
->assertSession();
$this
->drupalGet($path);
$session
->statusCodeEquals(403);
$this
->drupalLogin($this->user);
$this
->drupalGet($path);
$session
->statusCodeEquals(200);
}
public function testConfigPageContent() {
$path = URL::fromRoute('auditfiles.auditfiles_configuration');
$session = $this
->assertSession();
$this
->drupalLogin($this->user);
$this
->drupalGet($path);
$session
->pageTextContains("Audit Files");
$session
->elementExists('css', '#edit-auditfiles-file-system-path');
$session
->elementExists('css', '#edit-auditfiles-file-system-path > option:nth-child(1)');
$session
->elementAttributeContains('css', '#edit-auditfiles-file-system-path > option:nth-child(1)', 'value', 'public');
$session
->elementExists('css', '#edit-auditfiles-file-system-path > option:nth-child(2)');
$session
->elementAttributeContains('css', '#edit-auditfiles-file-system-path > option:nth-child(2)', 'value', 'temporary');
$session
->elementExists('css', '#edit-auditfiles-exclude-files');
$session
->elementAttributeContains('css', '#edit-auditfiles-exclude-files', 'value', '.htaccess');
$session
->elementExists('css', '#edit-auditfiles-exclude-extensions');
$session
->elementAttributeContains('css', '#edit-auditfiles-exclude-extensions', 'value', '');
$session
->elementExists('css', '#edit-auditfiles-exclude-paths');
$session
->elementAttributeContains('css', '#edit-auditfiles-exclude-paths', 'value', 'color;css;ctools;js');
$session
->elementExists('css', '#edit-auditfiles-include-domains');
$session
->elementAttributeContains('css', '#edit-auditfiles-include-domains', 'value', '');
$session
->elementExists('css', '#edit-auditfiles-report-options-date-format');
$session
->elementExists('css', '#edit-auditfiles-report-options-date-format > option:nth-child(1)');
$session
->elementAttributeContains('css', '#edit-auditfiles-report-options-date-format > option:nth-child(1)', 'value', 'fallback');
$session
->elementExists('css', '#edit-auditfiles-report-options-items-per-page');
$session
->elementAttributeContains('css', '#edit-auditfiles-report-options-items-per-page', 'value', '50');
$session
->elementExists('css', '#edit-auditfiles-report-options-maximum-records');
$session
->elementAttributeContains('css', '#edit-auditfiles-report-options-maximum-records', 'value', '250');
$session
->elementNotExists('css', '#edit-auditfiles-report-options-batch-size');
}
public function testConfigPageSaveConfig() {
$path = URL::fromRoute('auditfiles.auditfiles_configuration');
$session = $this
->assertSession();
$this
->drupalLogin($this->user);
$this
->drupalGet($path);
$session
->pageTextContains("Audit Files");
$edit = [
'edit-auditfiles-file-system-path' => 'public',
'edit-auditfiles-exclude-files' => '.htaccess',
'edit-auditfiles-exclude-extensions' => '',
'edit-auditfiles-exclude-paths' => 'color;css;ctools;js',
'edit-auditfiles-include-domains' => '',
'edit-auditfiles-report-options-date-format' => 'fallback',
'edit-auditfiles-report-options-items-per-page' => '50',
'edit-auditfiles-report-options-maximum-records' => '250',
];
$this
->submitForm($edit, 'Save configuration');
$session
->pageTextContains('The configuration options have been saved.');
$session
->pageTextContains("Audit Files");
$session
->elementAttributeExists('css', '#edit-auditfiles-file-system-path > option:nth-child(1)', 'selected');
$session
->elementAttributeContains('css', '#edit-auditfiles-file-system-path > option:nth-child(1)', 'selected', 'selected');
$session
->elementAttributeContains('css', '#edit-auditfiles-exclude-files', 'value', '.htaccess');
$session
->elementAttributeContains('css', '#edit-auditfiles-exclude-extensions', 'value', '');
$session
->elementAttributeContains('css', '#edit-auditfiles-exclude-paths', 'value', 'color;css;ctools;js');
$session
->elementAttributeContains('css', '#edit-auditfiles-include-domains', 'value', '');
$session
->elementAttributeExists('css', '#edit-auditfiles-report-options-date-format > option:nth-child(1)', 'value');
$session
->elementAttributeContains('css', '#edit-auditfiles-report-options-date-format > option:nth-child(1)', 'value', 'fallback');
$session
->elementAttributeExists('css', '#edit-auditfiles-report-options-date-format > option:nth-child(1)', 'selected');
$session
->elementAttributeContains('css', '#edit-auditfiles-report-options-date-format > option:nth-child(1)', 'selected', 'selected');
$session
->elementAttributeContains('css', '#edit-auditfiles-report-options-items-per-page', 'value', '50');
$session
->elementAttributeContains('css', '#edit-auditfiles-report-options-maximum-records', 'value', '250');
}
}