$this->drupalPostAJAX
does not work for ajax_command_replace() commands in my form that has several commands returned in ajax callback function.
To reproduce you need to:
1. Return ajax_command_replace() command in form callback.
2. Call $this->drupalPostAJAX() on a page with form in question.
3. Check that form or some other content on the page was not replaced.
At the same time if I just return $form in the callback, it's content is being rebuild as expected.
Expected
Content within selector
of ajax_command_replace to be replaced when $this->drupalPostAJAX
is called in tests.
The reason of this bug explained in the @todo comment within drupalPostAJAX() function:
// @todo Ajax commands can target any jQuery selector, but these are
// hard to fully emulate with XPath. For now, just handle 'head'
// and 'body', since these are used by ajax_render().
Comment | File | Size | Author |
---|---|---|---|
#1 | drupal-fix_drupalpostajax_for_replace_command-2066101-1.patch | 876 bytes | bulat |
Comments
Comment #1
bulat CreditAttribution: bulat commentedComment #2
bulat CreditAttribution: bulat commentedPatch in #1 only fixes the issue for simple id selectors like
#my-replacement-block
.I guess it should be said in comments for
drupalPostAJAX
function that complex jQuery selectors are not supported. It should be clear that there is no way to test whatajax_command_replace
does for selectors that have more than a single element ID.Comment #3
czigor CreditAttribution: czigor at Liip for FREITAG lab. AG commentedIt's quite easy to use the symfony CssSelector component here which can convert css selectors into xpath. Just override drupalPostAJAX() in your test class and replace this part:
with this:
and add
to the beginning of the class.
Look at https://symfony.com/doc/current/components/css_selector.html for unsupported css selectors.