protected function DraggableviewsTestCase::drupalDraggableviewsPost in DraggableViews 7.2
Fork from drupalPost().
When action of the form determined we don't care about exposed filter arguments passed to the view. In this fork we use $this->getUrl() unconditionally.
1 call to DraggableviewsTestCase::drupalDraggableviewsPost()
File
- test/
draggableviews.test, line 33 - Test cases file.
Class
- DraggableviewsTestCase
- Class for testing Draggableviews module.
Code
protected function drupalDraggableviewsPost($path, $edit, $submit, array $options = array(), array $headers = array(), $form_html_id = NULL, $extra_post = NULL) {
$submit_matches = FALSE;
$ajax = is_array($submit);
if (isset($path)) {
$this
->drupalGet($path, $options);
}
if ($this
->parse()) {
$edit_save = $edit;
// Let's iterate over all the forms.
$xpath = "//form";
if (!empty($form_html_id)) {
$xpath .= "[@id='" . $form_html_id . "']";
}
$forms = $this
->xpath($xpath);
foreach ($forms as $form) {
// We try to set the fields of this form as specified in $edit.
$edit = $edit_save;
$post = array();
$upload = array();
$submit_matches = $this
->handleForm($post, $edit, $upload, $ajax ? NULL : $submit, $form);
// $action = isset($form['action']) ? $this->getAbsoluteUrl((string) $form['action']) : $this->getUrl();
$action = $this
->getUrl();
if ($ajax) {
$action = $this
->getAbsoluteUrl(!empty($submit['path']) ? $submit['path'] : 'system/ajax');
// Ajax callbacks verify the triggering element if necessary, so while
// we may eventually want extra code that verifies it in the
// handleForm() function, it's not currently a requirement.
$submit_matches = TRUE;
}
// We post only if we managed to handle every field in edit and the
// submit button matches.
if (!$edit && ($submit_matches || !isset($submit))) {
$post_array = $post;
if ($upload) {
// TODO: cURL handles file uploads for us, but the implementation
// is broken. This is a less than elegant workaround. Alternatives
// are being explored at #253506.
foreach ($upload as $key => $file) {
$file = drupal_realpath($file);
if ($file && is_file($file)) {
$post[$key] = '@' . $file;
}
}
}
else {
foreach ($post as $key => $value) {
// Encode according to application/x-www-form-urlencoded
// Both names and values needs to be urlencoded, according to
// http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
$post[$key] = urlencode($key) . '=' . urlencode($value);
}
$post = implode('&', $post) . $extra_post;
}
$out = $this
->curlExec(array(
CURLOPT_URL => $action,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $post,
CURLOPT_HTTPHEADER => $headers,
));
// Ensure that any changes to variables in the other thread are picked up.
$this
->refreshVariables();
// Replace original page output with new output from redirected page(s).
if ($new = $this
->checkForMetaRefresh()) {
$out = $new;
}
$this
->verbose('POST request to: ' . $path . '<hr />Ending URL: ' . $this
->getUrl() . '<hr />Fields: ' . highlight_string('<?php ' . var_export($post_array, TRUE), TRUE) . '<hr />' . $out);
return $out;
}
}
// We have not found a form which contained all fields of $edit.
foreach ($edit as $name => $value) {
$this
->fail(t('Failed to set field @name to @value', array(
'@name' => $name,
'@value' => $value,
)));
}
if (!$ajax && isset($submit)) {
$this
->assertTrue($submit_matches, t('Found the @submit button', array(
'@submit' => $submit,
)));
}
$this
->fail(t('Found the requested form fields at @path', array(
'@path' => $path,
)));
}
}