function ImageFieldTestBase::uploadNodeImage
Same name in other branches
- 9 core/modules/image/tests/src/Functional/ImageFieldTestBase.php \Drupal\Tests\image\Functional\ImageFieldTestBase::uploadNodeImage()
- 8.9.x core/modules/image/src/Tests/ImageFieldTestBase.php \Drupal\image\Tests\ImageFieldTestBase::uploadNodeImage()
- 8.9.x core/modules/image/tests/src/Functional/ImageFieldTestBase.php \Drupal\Tests\image\Functional\ImageFieldTestBase::uploadNodeImage()
- 10 core/modules/image/tests/src/Functional/ImageFieldTestBase.php \Drupal\Tests\image\Functional\ImageFieldTestBase::uploadNodeImage()
Upload an image to a node.
Parameters
\stdClass $image: A file object representing the image to upload.
string $field_name: Name of the image field the image should be attached to.
string $type: The type of node to create.
string $alt: The alt text for the image. Use if the field settings require alt text.
13 calls to ImageFieldTestBase::uploadNodeImage()
- ImageAdminStylesTest::testConfigImport in core/
modules/ image/ tests/ src/ Functional/ ImageAdminStylesTest.php - Tests image style configuration import that does a delete.
- ImageAdminStylesTest::testStyleReplacement in core/
modules/ image/ tests/ src/ Functional/ ImageAdminStylesTest.php - Tests deleting a style and choosing a replacement style.
- ImageFieldDisplayTest::testImageFieldDefaultImage in core/
modules/ image/ tests/ src/ Functional/ ImageFieldDisplayTest.php - Tests use of a default image with an image field.
- ImageFieldDisplayTest::testImageFieldSettings in core/
modules/ image/ tests/ src/ Functional/ ImageFieldDisplayTest.php - Tests for image field settings.
- ImageFieldDisplayTest::testImageLoadingAttribute in core/
modules/ image/ tests/ src/ Functional/ ImageFieldDisplayTest.php - Tests for image loading attribute settings.
File
-
core/
modules/ image/ tests/ src/ Functional/ ImageFieldTestBase.php, line 106
Class
- ImageFieldTestBase
- This class provides methods specifically for testing Image's field handling.
Namespace
Drupal\Tests\image\FunctionalCode
public function uploadNodeImage($image, $field_name, $type, $alt = '') {
$edit = [
'title[0][value]' => $this->randomMachineName(),
];
$edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri);
$this->drupalGet('node/add/' . $type);
$this->submitForm($edit, 'Save');
if ($alt) {
// Add alt text.
$this->submitForm([
$field_name . '[0][alt]' => $alt,
], 'Save');
}
// Retrieve ID of the newly created node from the current URL.
$matches = [];
preg_match('/node\\/([0-9]+)/', $this->getUrl(), $matches);
return $matches[1] ?? FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.