本文整理汇总了PHP中Drupal\simpletest\WebTestBase::drupalPostAjaxForm方法的典型用法代码示例。如果您正苦于以下问题:PHP WebTestBase::drupalPostAjaxForm方法的具体用法?PHP WebTestBase::drupalPostAjaxForm怎么用?PHP WebTestBase::drupalPostAjaxForm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\simpletest\WebTestBase
的用法示例。
在下文中一共展示了WebTestBase::drupalPostAjaxForm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ucPostAjax
/**
* Extends WebTestBase::drupalPostAjaxForm() to replace additional content
* on the page after an ajax submission.
*
* WebTestBase::drupalPostAjaxForm() will only process ajax insertions which
* don't have a 'selector' attribute, because it's not easy to convert from a
* jQuery selector to an XPath. However, Ubercart uses many simple, id-based
* selectors, and these can be converted easily
* (eg: '#my-identifier' => '//*[@id="my-identifier"]').
*
* This helper method post-processes the command array returned by
* drupalPostAjaxForm() to perform these insertions.
*
* @see WebTestBase::drupalPostAjaxForm()
*/
protected function ucPostAjax($path, $edit, $triggering_element, $ajax_path = NULL, array $options = [], array $headers = [], $form_html_id = NULL, $ajax_settings = NULL)
{
$commands = parent::drupalPostAjaxForm($path, $edit, $triggering_element, $ajax_path, $options, $headers, $form_html_id, $ajax_settings);
$dom = new \DOMDocument();
@$dom->loadHTML($this->getRawContent());
foreach ($commands as $command) {
if ($command['command'] == 'insert' && isset($command['selector']) && preg_match('/^\\#-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/', $command['selector'])) {
$xpath = new \DOMXPath($dom);
$wrapperNode = $xpath->query('//*[@id="' . substr($command['selector'], 1) . '"]')->item(0);
if ($wrapperNode) {
// ajax.js adds an enclosing DIV to work around a Safari bug.
$newDom = new \DOMDocument();
@$newDom->loadHTML('<div>' . $command['data'] . '</div>');
$newNode = $dom->importNode($newDom->documentElement->firstChild->firstChild, TRUE);
$method = isset($command['method']) ? $command['method'] : $ajax_settings['method'];
// The "method" is a jQuery DOM manipulation function. Emulate
// each one using PHP's DOMNode API.
switch ($method) {
case 'replaceWith':
$wrapperNode->parentNode->replaceChild($newNode, $wrapperNode);
break;
case 'append':
$wrapperNode->appendChild($newNode);
break;
case 'prepend':
// If no firstChild, insertBefore() falls back to
// appendChild().
$wrapperNode->insertBefore($newNode, $wrapperNode->firstChild);
break;
case 'before':
$wrapperNode->parentNode->insertBefore($newNode, $wrapperNode);
break;
case 'after':
// If no nextSibling, insertBefore() falls back to
// appendChild().
$wrapperNode->parentNode->insertBefore($newNode, $wrapperNode->nextSibling);
break;
case 'html':
foreach ($wrapperNode->childNodes as $childNode) {
$wrapperNode->removeChild($childNode);
}
$wrapperNode->appendChild($newNode);
break;
}
}
}
}
$content = $dom->saveHTML();
$this->setRawContent($content);
$this->verbose('Page content after ajax submission:<hr />' . $this->content);
return $commands;
}