1 user.test UserPictureTestCase::testDeletePicture()

Tests deletion of user pictures.

File

core/modules/user/tests/user.test, line 1327
Tests for user.module.

Class

UserPictureTestCase

Code

function testDeletePicture() {
  $this->backdropLogin($this->user);

  $image = current($this->backdropGetTestFiles('image'));
  $info = image_get_info($image->uri);

  // Set new variables: valid dimensions, valid filesize (0 = no limit).
  $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
  config('system.core')
    ->set('user_picture_dimensions', $test_dim)
    ->set('user_picture_file_size', 0)
    ->save();

  // Save a new picture.
  $edit = array('files[picture_upload]' => backdrop_realpath($image->uri));
  $this->backdropPost('user/' . $this->user->uid . '/edit', $edit, t('Save'));

  // Load actual user data from database.
  $account = user_load($this->user->uid, TRUE);
  $pic_path = !empty($account->picture) ? $account->picture->uri : NULL;

  // Check if image is displayed in user's profile page.
  $this->backdropGet('user');
  $this->assertRaw(file_uri_target($pic_path), "Image is displayed in user's profile page");

  // Check if file is located in proper directory.
  $this->assertTrue(is_file($pic_path), 'File is located in proper directory');

  $edit = array('picture_delete' => 1);
  $this->backdropPost('user/' . $this->user->uid . '/edit', $edit, t('Save'));

  // Load actual user data from database.
  $account1 = user_load($this->user->uid, TRUE);
  $this->assertFalse($account1->picture, 'User object has no picture');

  $file = file_load($account->picture->fid);
  $this->assertFalse($file, 'File is removed from database');

  // Clear out PHP's file stat cache so we see the current value.
  clearstatcache();
  $this->assertFalse(is_file($pic_path), 'File is removed from file system');
}