public function QuickEditLoadingTest::testCustomPipeline in Quick Edit 7
Tests that Quick Edit works with custom render pipelines.
File
- ./
quickedit.test, line 445 - Tests loading of Quick Edit and lazy-loading of in-place editors.
Class
- QuickEditLoadingTest
- Tests loading of Quick Edit and lazy-loading of in-place editors.
Code
public function testCustomPipeline() {
module_enable(array(
'quickedit_test',
));
$custom_render_url = 'quickedit/form/node/1/body/und/quickedit_test-custom-render-data';
$this
->drupalLogin($this->editor_user);
// Request editing to render results with the custom render pipeline.
$post = array(
'nocssjs' => 'true',
) + $this
->getAjaxPageStatePostData();
$response = $this
->drupalPostCustom($custom_render_url, 'application/vnd.drupal-ajax', $post);
$ajax_commands = drupal_json_decode($response);
// Prepare form values for submission. drupalPostAJAX() is not suitable for
// handling pages with JSON responses, so we need our own solution here.
$form_tokens_found = preg_match('/\\sname="form_token" value="([^"]+)"/', $ajax_commands[0]['data'], $token_match) && preg_match('/\\sname="form_build_id" value="([^"]+)"/', $ajax_commands[0]['data'], $build_id_match);
$this
->assertTrue($form_tokens_found, 'Form tokens found in output.');
if ($form_tokens_found) {
$post = array(
'form_id' => 'quickedit_field_form',
'form_token' => $token_match[1],
'form_build_id' => $build_id_match[1],
'body[und][0][summary]' => '',
'body[und][0][value]' => '<p>Fine thanks.</p>',
'body[und][0][format]' => 'filtered_html',
'op' => t('Save'),
);
// Assume there is another field on this page, which doesn't use a custom
// render pipeline, but the default one, and it uses the "full" view mode.
$post += array(
'other_view_modes[]' => 'full',
);
// Submit field form and check response. Should render with the custom
// render pipeline.
$response = $this
->drupalPostCustom($custom_render_url, 'application/vnd.drupal-ajax', $post);
$this
->assertResponse(200);
$ajax_commands = drupal_json_decode($response);
$this
->assertIdentical(2, count($ajax_commands), 'The field form HTTP request results in two AJAX commands.');
$this
->assertIdentical('settings', $ajax_commands[0]['command'], 'The first AJAX command is a settings command.');
$this
->assertIdentical('quickeditFieldFormSaved', $ajax_commands[1]['command'], 'The second AJAX command is an quickeditFieldFormSaved command.');
$this
->assertTrue(strpos($ajax_commands[1]['data'], 'Fine thanks.'), 'Form value saved and printed back.');
$this
->assertTrue(strpos($ajax_commands[1]['data'], '<div class="quickedit-test-wrapper">') !== FALSE, 'Custom render pipeline used to render the value.');
$this
->assertIdentical(array_keys($ajax_commands[1]['other_view_modes']), array(
'full',
), 'Field was also rendered in the "full" view mode.');
$this
->assertTrue(strpos($ajax_commands[1]['other_view_modes']['full'], 'Fine thanks.'), '"full" version of field contains the form value.');
}
}