// Test for absence of link to image styles configuration.
$this->
submitForm([], "{
$field_name}_settings_edit"
);
$this->
assertSession()->
linkByHrefNotExists(Url::
fromRoute('entity.image_style.collection'
)->
toString(), 'Link to image styles configuration is absent when permissions are insufficient'
);
// Restore 'administer image styles' permission to testing admin user
user_role_change_permissions(reset($admin_user_roles),
['administer image styles' => TRUE
]);
// Create a new node with an image attached.
$test_image =
current($this->
drupalGetTestFiles('image'
));
// Ensure that preview works.
$this->
previewNodeImage($test_image,
$field_name, 'article'
);
// After previewing, make the alt field required. It cannot be required
// during preview because the form validation will fail.
$instance->
setSetting('alt_field_required', 1
);
$instance->
save();
// Create alt text for the image.
$alt =
$this->
randomMachineName();
// Save node.
$nid =
$this->
uploadNodeImage($test_image,
$field_name, 'article',
$alt);