d30b4f110b116b1301e0b5a107649a6571eafa15
[yaffs-website] / web / core / modules / system / tests / src / Functional / Form / StateValuesCleanAdvancedTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Form;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\TestFileCreationTrait;
7
8 /**
9  * Tests proper removal of submitted form values using
10  * \Drupal\Core\Form\FormState::cleanValues() when having forms with elements
11  * containing buttons like "managed_file".
12  *
13  * @group Form
14  */
15 class StateValuesCleanAdvancedTest extends BrowserTestBase {
16
17   use TestFileCreationTrait {
18     getTestFiles as drupalGetTestFiles;
19   }
20
21   /**
22    * Modules to enable.
23    *
24    * @var array
25    */
26   public static $modules = ['file', 'form_test'];
27
28   /**
29    * An image file path for uploading.
30    */
31   protected $image;
32
33   /**
34    * Tests \Drupal\Core\Form\FormState::cleanValues().
35    */
36   public function testFormStateValuesCleanAdvanced() {
37
38     // Get an image for uploading.
39     $image_files = $this->drupalGetTestFiles('image');
40     $this->image = current($image_files);
41
42     // Check if the physical file is there.
43     $this->assertTrue(is_file($this->image->uri), "The image file we're going to upload exists.");
44
45     // "Browse" for the desired file.
46     $edit = ['files[image]' => \Drupal::service('file_system')->realpath($this->image->uri)];
47
48     // Post the form.
49     $this->drupalPostForm('form_test/form-state-values-clean-advanced', $edit, t('Submit'));
50
51     // Expecting a 200 HTTP code.
52     $this->assertResponse(200, 'Received a 200 response for posted test file.');
53     $this->assertRaw(t('You WIN!'), 'Found the success message.');
54   }
55
56 }