3 namespace Drupal\Tests\system\Functional\Form;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\TestFileCreationTrait;
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".
15 class StateValuesCleanAdvancedTest extends BrowserTestBase {
17 use TestFileCreationTrait {
18 getTestFiles as drupalGetTestFiles;
26 public static $modules = ['file', 'form_test'];
29 * An image file path for uploading.
34 * Tests \Drupal\Core\Form\FormState::cleanValues().
36 public function testFormStateValuesCleanAdvanced() {
38 // Get an image for uploading.
39 $image_files = $this->drupalGetTestFiles('image');
40 $this->image = current($image_files);
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.");
45 // "Browse" for the desired file.
46 $edit = ['files[image]' => drupal_realpath($this->image->uri)];
49 $this->drupalPostForm('form_test/form-state-values-clean-advanced', $edit, t('Submit'));
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.');