1 user.test UserPictureTestCase::testPictureIsValid()

Do the test: Picture is valid (proper size and dimension)

results: The image should be uploaded

File

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

Class

UserPictureTestCase

Code

function testPictureIsValid() {
  if ($this->_directory_test) {
    $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();

    $pic_path = $this->saveUserPicture($image);

    // 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');

    // Set new picture dimensions.
    $test_dim = ($info['width'] + 5) . 'x' . ($info['height'] + 5);
    config_set('system.core', 'user_picture_dimensions', $test_dim);

    $pic_path2 = $this->saveUserPicture($image);
    $this->assertNotEqual($pic_path, $pic_path2, 'Filename of second picture is different.');

    // Check if user picture has a valid file ID after saving the user.
    $account = user_load($this->user->uid, TRUE);
    $this->assertTrue(is_object($account->picture), 'User picture object is valid after user load.');
    $this->assertNotNull($account->picture->fid, 'User picture object has a FID after user load.');
    $this->assertTrue(is_file($account->picture->uri), 'File is located in proper directory after user load.');
    user_save($account);
    // Verify that the user save does not destroy the user picture object.
    $this->assertTrue(is_object($account->picture), 'User picture object is valid after user save.');
    $this->assertNotNull($account->picture->fid, 'User picture object has a FID after user save.');
    $this->assertTrue(is_file($account->picture->uri), 'File is located in proper directory after user save.');
  }
}