Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / src / FunctionalJavascript / ThemeFormSettingsTest.php
1 <?php
2
3 namespace Drupal\Tests\system\FunctionalJavascript;
4
5 use Drupal\file\Entity\File;
6 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
7 use Drupal\Tests\TestFileCreationTrait;
8
9 /**
10  * Tests that theme form settings works correctly.
11  *
12  * @group system
13  */
14 class ThemeFormSettingsTest extends JavascriptTestBase {
15
16   use TestFileCreationTrait;
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = ['file'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp() {
27     parent::setUp();
28
29     $admin = $this->drupalCreateUser(['administer themes']);
30     $this->drupalLogin($admin);
31   }
32
33   /**
34    * Tests that submission handler works correctly.
35    *
36    * @dataProvider providerTestFormSettingsSubmissionHandler
37    */
38   public function testFormSettingsSubmissionHandler($theme) {
39
40     \Drupal::service('theme_handler')->install([$theme]);
41
42     $page = $this->getSession()->getPage();
43     $assert_session = $this->assertSession();
44
45     $this->drupalGet("admin/appearance/settings/$theme");
46
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');
52
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());
58
59     $page->pressButton('Save configuration');
60     \Drupal::entityTypeManager()->getStorage('file')->resetCache();
61
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());
66   }
67
68   /**
69    * Provides test data for ::testFormSettingsSubmissionHandler().
70    */
71   public function providerTestFormSettingsSubmissionHandler() {
72     return [
73       'test theme.theme' => ['test_theme_theme'],
74       'test theme-settings.php' => ['test_theme_settings'],
75     ];
76   }
77
78 }