public function QuickEditLoadingTest::testImageField in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/quickedit/src/Tests/QuickEditLoadingTest.php \Drupal\quickedit\Tests\QuickEditLoadingTest::testImageField()
Tests that Quick Edit can handle an image field.
File
- core/
modules/ quickedit/ src/ Tests/ QuickEditLoadingTest.php, line 528 - Contains \Drupal\quickedit\Tests\QuickEditLoadingTest.
Class
- QuickEditLoadingTest
- Tests loading of in-place editing functionality and lazy loading of its in-place editors.
Namespace
Drupal\quickedit\TestsCode
public function testImageField() {
// Add an image field to the content type.
FieldStorageConfig::create([
'field_name' => 'field_image',
'type' => 'image',
'entity_type' => 'node',
])
->save();
FieldConfig::create([
'field_name' => 'field_image',
'field_type' => 'image',
'label' => t('Image'),
'entity_type' => 'node',
'bundle' => 'article',
])
->save();
entity_get_form_display('node', 'article', 'default')
->setComponent('field_image', [
'type' => 'image_image',
])
->save();
// Add an image to the node.
$this
->drupalLogin($this->editorUser);
$image = $this
->drupalGetTestFiles('image')[0];
$this
->drupalPostForm('node/1/edit', [
'files[field_image_0]' => $image->uri,
], t('Upload'));
$this
->drupalPostForm(NULL, [
'field_image[0][alt]' => 'Vivamus aliquet elit',
], t('Save'));
// The image field form should load normally.
$response = $this
->drupalPost('quickedit/form/node/1/field_image/en/full', 'application/vnd.drupal-ajax', [
'nocssjs' => 'true',
] + $this
->getAjaxPageStatePostData());
$this
->assertResponse(200);
$ajax_commands = Json::decode($response);
$this
->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.');
}