Mercurial > hg > isophonics-drupal-site
comparison core/modules/quickedit/src/Tests/QuickEditLoadingTest.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 7a779792577d |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\quickedit\Tests; | 3 namespace Drupal\quickedit\Tests; |
4 | 4 |
5 use Drupal\Component\Serialization\Json; | 5 use Drupal\Component\Serialization\Json; |
6 use Drupal\Component\Utility\Unicode; | |
7 use Drupal\block_content\Entity\BlockContent; | 6 use Drupal\block_content\Entity\BlockContent; |
8 use Drupal\field\Entity\FieldConfig; | 7 use Drupal\field\Entity\FieldConfig; |
9 use Drupal\field\Entity\FieldStorageConfig; | 8 use Drupal\field\Entity\FieldStorageConfig; |
10 use Drupal\Core\EventSubscriber\MainContentViewSubscriber; | 9 use Drupal\Core\EventSubscriber\MainContentViewSubscriber; |
11 use Drupal\Core\Url; | 10 use Drupal\Core\Url; |
85 'type' => 'article', | 84 'type' => 'article', |
86 'body' => [ | 85 'body' => [ |
87 0 => [ | 86 0 => [ |
88 'value' => '<p>How are you?</p>', | 87 'value' => '<p>How are you?</p>', |
89 'format' => 'filtered_html', | 88 'format' => 'filtered_html', |
90 ] | 89 ], |
91 ], | 90 ], |
92 'revision_log' => $this->randomString(), | 91 'revision_log' => $this->randomString(), |
93 ]); | 92 ]); |
94 | 93 |
95 // Create 2 users, the only difference being the ability to use in-place | 94 // Create 2 users, the only difference being the ability to use in-place |
186 $expected = [ | 185 $expected = [ |
187 'node/1/body/en/full' => [ | 186 'node/1/body/en/full' => [ |
188 'label' => 'Body', | 187 'label' => 'Body', |
189 'access' => TRUE, | 188 'access' => TRUE, |
190 'editor' => 'form', | 189 'editor' => 'form', |
191 ] | 190 ], |
192 ]; | 191 ]; |
193 $this->assertIdentical(Json::decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.'); | 192 $this->assertIdentical(Json::decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.'); |
194 // Restore drupalSettings to build the next requests; simpletest wipes them | 193 // Restore drupalSettings to build the next requests; simpletest wipes them |
195 // after a JSON response. | 194 // after a JSON response. |
196 $this->drupalSettings = $htmlPageDrupalSettings; | 195 $this->drupalSettings = $htmlPageDrupalSettings; |
214 $response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); | 213 $response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); |
215 $this->assertResponse(200); | 214 $this->assertResponse(200); |
216 $ajax_commands = Json::decode($response); | 215 $ajax_commands = Json::decode($response); |
217 $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); | 216 $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); |
218 $this->assertIdentical('quickeditFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is a quickeditFieldForm command.'); | 217 $this->assertIdentical('quickeditFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is a quickeditFieldForm command.'); |
219 $this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.'); | 218 $this->assertIdentical('<form ', mb_substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.'); |
220 | 219 |
221 // Prepare form values for submission. drupalPostAjaxForm() is not suitable | 220 // Prepare form values for submission. drupalPostAjaxForm() is not suitable |
222 // for handling pages with JSON responses, so we need our own solution here. | 221 // for handling pages with JSON responses, so we need our own solution here. |
223 $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); | 222 $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); |
224 $this->assertTrue($form_tokens_found, 'Form tokens found in output.'); | 223 $this->assertTrue($form_tokens_found, 'Form tokens found in output.'); |
284 $response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); | 283 $response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); |
285 $this->assertResponse(200); | 284 $this->assertResponse(200); |
286 $ajax_commands = Json::decode($response); | 285 $ajax_commands = Json::decode($response); |
287 $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); | 286 $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); |
288 $this->assertIdentical('quickeditFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is a quickeditFieldForm command.'); | 287 $this->assertIdentical('quickeditFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is a quickeditFieldForm command.'); |
289 $this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.'); | 288 $this->assertIdentical('<form ', mb_substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.'); |
290 | 289 |
291 // Submit field form. | 290 // Submit field form. |
292 preg_match('/\sname="form_token" value="([^"]+)"/', $ajax_commands[0]['data'], $token_match); | 291 preg_match('/\sname="form_token" value="([^"]+)"/', $ajax_commands[0]['data'], $token_match); |
293 preg_match('/\sname="form_build_id" value="([^"]+)"/', $ajax_commands[0]['data'], $build_id_match); | 292 preg_match('/\sname="form_build_id" value="([^"]+)"/', $ajax_commands[0]['data'], $build_id_match); |
294 $edit['body[0][value]'] = '<p>kthxbye</p>'; | 293 $edit['body[0][value]'] = '<p>kthxbye</p>'; |
372 $expected = [ | 371 $expected = [ |
373 'node/1/title/en/full' => [ | 372 'node/1/title/en/full' => [ |
374 'label' => 'Title', | 373 'label' => 'Title', |
375 'access' => TRUE, | 374 'access' => TRUE, |
376 'editor' => 'plain_text', | 375 'editor' => 'plain_text', |
377 ] | 376 ], |
378 ]; | 377 ]; |
379 $this->assertIdentical(Json::decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.'); | 378 $this->assertIdentical(Json::decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.'); |
380 // Restore drupalSettings to build the next requests; simpletest wipes them | 379 // Restore drupalSettings to build the next requests; simpletest wipes them |
381 // after a JSON response. | 380 // after a JSON response. |
382 $this->drupalSettings = $htmlPageDrupalSettings; | 381 $this->drupalSettings = $htmlPageDrupalSettings; |
387 $response = $this->drupalPost('quickedit/form/' . 'node/1/title/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); | 386 $response = $this->drupalPost('quickedit/form/' . 'node/1/title/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); |
388 $this->assertResponse(200); | 387 $this->assertResponse(200); |
389 $ajax_commands = Json::decode($response); | 388 $ajax_commands = Json::decode($response); |
390 $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); | 389 $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); |
391 $this->assertIdentical('quickeditFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is a quickeditFieldForm command.'); | 390 $this->assertIdentical('quickeditFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is a quickeditFieldForm command.'); |
392 $this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.'); | 391 $this->assertIdentical('<form ', mb_substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.'); |
393 | 392 |
394 // Prepare form values for submission. drupalPostAjaxForm() is not suitable | 393 // Prepare form values for submission. drupalPostAjaxForm() is not suitable |
395 // for handling pages with JSON responses, so we need our own solution | 394 // for handling pages with JSON responses, so we need our own solution |
396 // here. | 395 // here. |
397 $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); | 396 $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); |
600 | 599 |
601 // The image field form should load normally. | 600 // The image field form should load normally. |
602 $response = $this->drupalPost('quickedit/form/node/1/field_image/en/full', '', ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData(), ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); | 601 $response = $this->drupalPost('quickedit/form/node/1/field_image/en/full', '', ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData(), ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]); |
603 $this->assertResponse(200); | 602 $this->assertResponse(200); |
604 $ajax_commands = Json::decode($response); | 603 $ajax_commands = Json::decode($response); |
605 $this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.'); | 604 $this->assertIdentical('<form ', mb_substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.'); |
606 } | 605 } |
607 | 606 |
608 } | 607 } |