public function ImageFieldValidateTest::testEmpty in Drupal 9
Same name and namespace in other branches
- 8 core/modules/image/tests/src/Functional/ImageFieldValidateTest.php \Drupal\Tests\image\Functional\ImageFieldValidateTest::testEmpty()
- 10 core/modules/image/tests/src/Functional/ImageFieldValidateTest.php \Drupal\Tests\image\Functional\ImageFieldValidateTest::testEmpty()
Tests creating an entity while leaving the image field empty.
This is tested first with edit access to the image field allowed, and then with it forbidden.
@dataProvider providerTestEmpty
File
- core/
modules/ image/ tests/ src/ Functional/ ImageFieldValidateTest.php, line 222
Class
- ImageFieldValidateTest
- Tests validation functions such as min/max resolution.
Namespace
Drupal\Tests\image\FunctionalCode
public function testEmpty($field_name, $required, $cardinality, $form_element_name, $expected_page_text_when_edit_access_allowed, $expected_page_text_when_edit_access_forbidden) {
$this
->createImageField($field_name, 'article', [
'cardinality' => $cardinality,
], [
'required' => $required,
]);
// Test with field edit access allowed.
$this
->drupalGet('node/add/article');
$this
->assertSession()
->fieldExists($form_element_name);
$edit = [
'title[0][value]' => 'Article with edit-access-allowed image field',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains($expected_page_text_when_edit_access_allowed);
// Test with field edit access forbidden.
\Drupal::service('module_installer')
->install([
'image_access_test_hidden',
]);
$this
->drupalGet('node/add/article');
$this
->assertSession()
->fieldNotExists($form_element_name);
$edit = [
'title[0][value]' => 'Article with edit-access-forbidden image field',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains($expected_page_text_when_edit_access_forbidden);
}