/**
  * Helper for submitting a message (post or private message)
  *
  * @param string $posting_url
  * @param string $posting_contains
  * @param array $form_data
  * @return \Symfony\Component\DomCrawler\Crawler the crawler object
  */
 protected function submit_message($posting_url, $posting_contains, $form_data)
 {
     if (time() == self::$last_post_timestamp) {
         // Travis is too fast, so we have to wait to not mix up the post/topic order
         sleep(1);
     }
     self::$last_post_timestamp = time();
     $crawler = self::request('GET', $posting_url);
     $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text());
     if (!empty($form_data['upload_files'])) {
         for ($i = 0; $i < $form_data['upload_files']; $i++) {
             $file = array('tmp_name' => __DIR__ . '/../functional/fixtures/files/valid.jpg', 'name' => 'valid.jpg', 'type' => 'image/jpeg', 'size' => filesize(__DIR__ . '/../functional/fixtures/files/valid.jpg'), 'error' => UPLOAD_ERR_OK);
             $crawler = self::$client->request('POST', $posting_url, array('add_file' => $this->lang('ADD_FILE')), array('fileupload' => $file));
         }
         unset($form_data['upload_files']);
     }
     $hidden_fields = array($crawler->filter('[type="hidden"]')->each(function ($node, $i) {
         return array('name' => $node->attr('name'), 'value' => $node->attr('value'));
     }));
     foreach ($hidden_fields as $fields) {
         foreach ($fields as $field) {
             $form_data[$field['name']] = $field['value'];
         }
     }
     // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened)
     // is not at least 2 seconds before submission, cancel the form
     $form_data['lastclick'] = 0;
     // I use a request because the form submission method does not allow you to send data that is not
     // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs)
     // Instead, I send it as a request with the submit button "post" set to true.
     return self::request('POST', $posting_url, $form_data);
 }