3 namespace Drupal\Tests\system\FunctionalJavascript;
5 use Drupal\file\Entity\File;
6 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
7 use Drupal\Tests\TestFileCreationTrait;
10 * Tests that theme form settings works correctly.
14 class ThemeFormSettingsTest extends JavascriptTestBase {
16 use TestFileCreationTrait;
21 public static $modules = ['file'];
26 protected function setUp() {
29 $admin = $this->drupalCreateUser(['administer themes']);
30 $this->drupalLogin($admin);
34 * Tests that submission handler works correctly.
36 * @dataProvider providerTestFormSettingsSubmissionHandler
38 public function testFormSettingsSubmissionHandler($theme) {
40 \Drupal::service('theme_handler')->install([$theme]);
42 $page = $this->getSession()->getPage();
43 $assert_session = $this->assertSession();
45 $this->drupalGet("admin/appearance/settings/$theme");
47 // Add a new managed file.
48 $file = current($this->getTestFiles('image'));
49 $image_file_path = \Drupal::service('file_system')->realpath($file->uri);
50 $page->attachFileToField('files[custom_logo]', $image_file_path);
51 $assert_session->waitForButton('custom_logo_remove_button');
53 // Assert the new file is uploaded as temporary. This file should not be
54 // saved as permanent if settings are not submited.
55 $image_field = $this->xpath('//input[@name="custom_logo[fids]"]')[0];
56 $file = File::load($image_field->getValue());
57 $this->assertFalse($file->isPermanent());
59 $page->pressButton('Save configuration');
60 \Drupal::entityTypeManager()->getStorage('file')->resetCache();
62 // Assert the uploaded file is saved as permanent.
63 $image_field = $this->xpath('//input[@name="custom_logo[fids]"]')[0];
64 $file = File::load($image_field->getValue());
65 $this->assertTrue($file->isPermanent());
69 * Provides test data for ::testFormSettingsSubmissionHandler().
71 public function providerTestFormSettingsSubmissionHandler() {
73 'test theme.theme' => ['test_theme_theme'],
74 'test theme-settings.php' => ['test_theme_settings'],