ThemeSettingsFormTest.php in Drupal 10
File
core/modules/system/tests/src/FunctionalJavascript/ThemeSettingsFormTest.php
View source
<?php
namespace Drupal\Tests\system\FunctionalJavascript;
use Drupal\file\Entity\File;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\TestFileCreationTrait;
class ThemeSettingsFormTest extends WebDriverTestBase {
use TestFileCreationTrait;
protected static $modules = [
'file',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$admin = $this
->drupalCreateUser([
'administer themes',
]);
$this
->drupalLogin($admin);
}
public function testFormSettingsSubmissionHandler($theme) {
\Drupal::service('theme_installer')
->install([
$theme,
]);
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$this
->drupalGet("admin/appearance/settings/{$theme}");
$file = current($this
->getTestFiles('image'));
$image_file_path = \Drupal::service('file_system')
->realpath($file->uri);
$page
->attachFileToField('files[custom_logo]', $image_file_path);
$assert_session
->waitForButton('custom_logo_remove_button');
$image_field = $this
->assertSession()
->hiddenFieldExists('custom_logo[fids]');
$file = File::load($image_field
->getValue());
$this
->assertFalse($file
->isPermanent());
$page
->pressButton('Save configuration');
\Drupal::entityTypeManager()
->getStorage('file')
->resetCache();
$image_field = $this
->assertSession()
->hiddenFieldExists('custom_logo[fids]');
$file = File::load($image_field
->getValue());
$this
->assertTrue($file
->isPermanent());
}
public function providerTestFormSettingsSubmissionHandler() {
return [
'test theme.theme' => [
'test_theme_theme',
],
'test theme-settings.php' => [
'test_theme_settings',
],
];
}
}