function UserPictureTest::testCreateDeletePicture
Same name in other branches
- 8.9.x core/modules/user/tests/src/Functional/UserPictureTest.php \Drupal\Tests\user\Functional\UserPictureTest::testCreateDeletePicture()
- 10 core/modules/user/tests/src/Functional/UserPictureTest.php \Drupal\Tests\user\Functional\UserPictureTest::testCreateDeletePicture()
- 11.x core/modules/user/tests/src/Functional/UserPictureTest.php \Drupal\Tests\user\Functional\UserPictureTest::testCreateDeletePicture()
Tests creation, display, and deletion of user pictures.
File
-
core/
modules/ user/ tests/ src/ Functional/ UserPictureTest.php, line 69
Class
- UserPictureTest
- Tests user picture functionality.
Namespace
Drupal\Tests\user\FunctionalCode
public function testCreateDeletePicture() {
$this->drupalLogin($this->webUser);
// Save a new picture.
$image = current($this->drupalGetTestFiles('image'));
$file = $this->saveUserPicture($image);
// Verify that the image is displayed on the user account page.
$this->drupalGet('user');
$this->assertSession()
->responseContains(StreamWrapperManager::getTarget($file->getFileUri()));
// Delete the picture.
$edit = [];
$this->drupalGet('user/' . $this->webUser
->id() . '/edit');
$this->submitForm($edit, 'Remove');
$this->submitForm([], 'Save');
// Call file_cron() to clean up the file. Make sure the timestamp
// of the file is older than the system.file.temporary_maximum_age
// configuration value. We use an UPDATE statement because using the API
// would set the timestamp.
Database::getConnection()->update('file_managed')
->fields([
'changed' => REQUEST_TIME - ($this->config('system.file')
->get('temporary_maximum_age') + 1),
])
->condition('fid', $file->id())
->execute();
\Drupal::service('cron')->run();
// Verify that the image has been deleted.
$this->assertNull(File::load($file->id()), 'File was removed from the database.');
// Clear out PHP's file stat cache so we see the current value.
clearstatcache(TRUE, $file->getFileUri());
$this->assertFileDoesNotExist($file->getFileUri());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.