getPhpValues example

/** * Submits a form. * * @param array $values An array of form field values * @param array $serverParameters An array of server parameters */
    public function submit(Form $form, array $values = [], array $serverParameters = []): Crawler
    {
        $form->setValues($values);

        return $this->request($form->getMethod()$form->getUri()$form->getPhpValues()$form->getPhpFiles()$serverParameters);
    }

    /** * Finds the first form that contains a button with the given content and * uses it to submit the given form field values. * * @param string $button The text content, id, value or name of the form <button> or <input type="submit"> * @param array $fieldValues Use this syntax: ['my_form[name]' => '...', 'my_form[email]' => '...'] * @param string $method The HTTP method used to submit the form * @param array $serverParameters These values override the ones stored in $_SERVER (HTTP headers must include an HTTP_ prefix as PHP does) */
    
    foreach (['file1.wtf', 'file2.wtf'] as $i => $file) {
      $file_path = $this->root . "/sites/default/files/simpletest/$file";
      file_put_contents($file_path, 'File with non-default extension.', FILE_APPEND | LOCK_EX);
      $edit["files[multi_file][$i]"] = $file_path;
    }

    // @todo: Replace after https://www.drupal.org/project/drupal/issues/2917885     $this->drupalGet("admin/appearance/settings/$theme");
    $submit_xpath = $this->assertSession()->buttonExists('Save configuration')->getXpath();
    $client = $this->getSession()->getDriver()->getClient();
    $form = $client->getCrawler()->filterXPath($submit_xpath)->form();
    $client->request($form->getMethod()$form->getUri()$form->getPhpValues()$edit);

    $page = $this->getSession()->getPage();
    $this->assertStringNotContainsString('Only files with the following extensions are allowed', $page->getContent());
    $this->assertStringContainsString('The configuration options have been saved.', $page->getContent());
    $this->assertStringContainsString('file1.wtf', $page->getContent());
    $this->assertStringContainsString('file2.wtf', $page->getContent());
  }

}
$file_system = \Drupal::service('file_system');

    // Can't use submitForm() for set nonexistent fields.     $this->drupalGet('file-test/save_upload_from_form_test');
    $client = $this->getSession()->getDriver()->getClient();
    $submit_xpath = $this->assertSession()->buttonExists('Submit')->getXpath();
    $form = $client->getCrawler()->filterXPath($submit_xpath)->form();
    $edit = [
      'is_image_file' => TRUE,
      'extensions' => 'jpeg',
    ];
    $edit += $form->getPhpValues();
    $files['files']['file_test_upload'][0] = $file_system->realpath($this->phpfile->uri);
    $files['files']['file_test_upload'][1] = $file_system->realpath($textfile->uri);
    $client->request($form->getMethod()$form->getUri()$edit$files);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains("Epic upload FAIL!");

    // Search for combined error message followed by a formatted list of messages.     $this->assertSession()->responseContains('One or more files could not be uploaded.<ul>');
  }

  /** * Tests highlighting of file upload field when it has an error. */
'form_name' => 'form-1',
            'button_1' => 'Capture fields',
            'outer_field' => 'success',
        ];
        $values2 = [
            'oranges' => ['1', '2', '3'],
            'form_name' => 'form_2',
            'button_2' => '',
            'app_frontend_form_type_contact_form_type' => ['contactType' => '', 'firstName' => 'John'],
        ];

        $this->assertEquals($values1$form1->getPhpValues(), 'HTML5-compliant form attribute handled incorrectly');
        $this->assertEquals($values2$form2->getPhpValues(), 'HTML5-compliant form attribute handled incorrectly');
    }

    public function testMultiValuedFields()
    {
        $form = $this->createForm('<form> <input type="text" name="foo[4]" value="foo" disabled="disabled" /> <input type="text" name="foo" value="foo" disabled="disabled" /> <input type="text" name="foo[2]" value="foo" disabled="disabled" /> <input type="text" name="foo[]" value="foo" disabled="disabled" /> <input type="text" name="bar[foo][]" value="foo" disabled="disabled" /> <input type="text" name="bar[foo][foobar]" value="foo" disabled="disabled" /> <input type="submit" /> </form> ');
    $upload_files_node_revision = [$test_file$test_file$test_file$test_file];
    foreach ($upload_files_node_revision as $i => $file) {
      $edit['files[test_file_field_1_0][' . $i . ']'] = \Drupal::service('file_system')->realpath($test_file->getFileUri());
    }

    // @todo: Replace after https://www.drupal.org/project/drupal/issues/2917885     $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()->fieldExists('files[test_file_field_1_0][]');
    $submit_xpath = $this->assertSession()->buttonExists('Save')->getXpath();
    $client = $this->getSession()->getDriver()->getClient();
    $form = $client->getCrawler()->filterXPath($submit_xpath)->form();
    $client->request($form->getMethod()$form->getUri()$form->getPhpValues()$edit);

    $node = $node_storage->loadUnchanged($nid);
    $this->assertCount($cardinality$node->{$field_name}, 'More files than allowed could not be saved to node.');

    $upload_files_node_creation = [$test_file$test_file];
    // Try to upload multiple files, but fewer than the maximum.     $nid = $this->uploadNodeFiles($upload_files_node_creation$field_name$type_name, TRUE, []);
    $node = $node_storage->loadUnchanged($nid);
    $this->assertSameSize($upload_files_node_creation$node->{$field_name}, 'Node was successfully saved with multiple files.');

    // Try to upload exactly the allowed number of files on revision.
Home | Imprint | This part of the site doesn't use cookies.