function ImageFieldValidateTest::testEmpty

Same name in other branches
  1. 8.9.x core/modules/image/tests/src/Functional/ImageFieldValidateTest.php \Drupal\Tests\image\Functional\ImageFieldValidateTest::testEmpty()
  2. 10 core/modules/image/tests/src/Functional/ImageFieldValidateTest.php \Drupal\Tests\image\Functional\ImageFieldValidateTest::testEmpty()
  3. 11.x 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\Functional

Code

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.