$file_system =
$this->container->
get('file_system'
);
$image_files =
$this->
drupalGetTestFiles('image'
);
$field_name =
strtolower($this->
randomMachineName());
$this->
createImageField($field_name, 'article',
[],
['file_directory' => 'test-upload'
]);
$expected_path = 'public://test-upload';
// Create alt text for the image.
$alt =
$this->
randomMachineName();
// Create a node with a valid image.
$node =
$this->
uploadNodeImage($image_files[0
],
$field_name, 'article',
$alt);
$this->
assertFileExists($expected_path . '/' .
$image_files[0
]->filename
);
// Remove the image.
$this->
drupalGet('node/' .
$node . '/edit'
);
$this->
submitForm([], 'Remove'
);
$this->
submitForm([], 'Save'
);
// Get invalid image test files.
$dir = 'core/tests/fixtures/files';
$files =
[];
if (is_dir($dir)) {