Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / file / tests / src / Functional / MultipleFileUploadTest.php
1 <?php
2
3 namespace Drupal\Tests\file\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests multiple file upload.
9  *
10  * @group file
11  */
12 class MultipleFileUploadTest extends BrowserTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = ['file'];
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function setUp() {
23     parent::setUp();
24
25     $admin = $this->drupalCreateUser(['administer themes']);
26     $this->drupalLogin($admin);
27   }
28
29   /**
30    * Tests multiple file field with all file extensions.
31    */
32   public function testMultipleFileFieldWithAllFileExtensions() {
33     $theme = 'test_theme_settings';
34     \Drupal::service('theme_handler')->install([$theme]);
35     $this->drupalGet("admin/appearance/settings/$theme");
36
37     $edit = [];
38     // Create few files with non-typical extensions.
39     foreach (['file1.wtf', 'file2.wtf'] as $i => $file) {
40       $file_path = $this->root . "/sites/default/files/simpletest/$file";
41       file_put_contents($file_path, 'File with non-default extension.', FILE_APPEND | LOCK_EX);
42       $edit["files[multi_file][$i]"] = $file_path;
43     }
44
45     // @todo: Replace after https://www.drupal.org/project/drupal/issues/2917885
46     $this->drupalGet("admin/appearance/settings/$theme");
47     $submit_xpath = $this->assertSession()->buttonExists('Save configuration')->getXpath();
48     $client = $this->getSession()->getDriver()->getClient();
49     $form = $client->getCrawler()->filterXPath($submit_xpath)->form();
50     $client->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $edit);
51
52     $page = $this->getSession()->getPage();
53     $this->assertNotContains('Only files with the following extensions are allowed', $page->getContent());
54     $this->assertContains('The configuration options have been saved.', $page->getContent());
55     $this->assertContains('file1.wtf', $page->getContent());
56     $this->assertContains('file2.wtf', $page->getContent());
57   }
58
59 }