diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 27ff7c3..4299874 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1081,6 +1081,17 @@ function comment_build_content(Comment $comment, Node $node, $view_mode = 'full' } /** + * Implements hook_entity_prepare_view(). + * + * Load user account objects into comment entities. + */ +function comment_entity_prepare_view($entities, $type) { + if ($type == 'comment') { + user_attach_accounts($entities); + } +} + +/** * Adds reply, edit, delete, etc. links, depending on user permissions. * * @param Drupal\comment\Comment $comment @@ -1705,7 +1716,6 @@ function comment_preview(Comment $comment) { $comment->name = check_plain($account->name); $comment->signature = $account->signature; $comment->signature_format = $account->signature_format; - $comment->picture = $account->picture; } elseif (empty($comment->name)) { $comment->name = config('user.settings')->get('anonymous'); @@ -1761,7 +1771,14 @@ function template_preprocess_comment(&$variables) { $variables['changed'] = format_date($comment->changed); $variables['new'] = !empty($comment->new) ? t('new') : ''; - $variables['user_picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', array('account' => $comment)) : ''; + if (theme_get_setting('toggle_comment_user_picture')) { + // To change user picture settings (e.g., image style), edit the 'compact' + // view mode on the User entity. + $variables['user_picture'] = user_view($comment->account, 'compact'); + } + else { + $variables['user_picture'] = array(); + } $variables['signature'] = $comment->signature; $uri = $comment->uri(); diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 4d447a5..50dde39 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -34,7 +34,7 @@ protected function buildQuery($ids, $revision_id = FALSE) { $query->addField('n', 'type', 'node_type'); $query->innerJoin('users', 'u', 'base.uid = u.uid'); $query->addField('u', 'name', 'registered_name'); - $query->fields('u', array('uid', 'signature', 'signature_format', 'picture')); + $query->fields('u', array('uid', 'signature', 'signature_format')); return $query; } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php index e9ca2d9..438d15f 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php @@ -36,12 +36,11 @@ function testCommentPreview() { // Login as web user and add a signature and a user picture. $this->drupalLogin($this->web_user); config('user.settings')->set('signatures', 1)->save(); - variable_set('user_pictures', 1); $test_signature = $this->randomName(); $edit['signature[value]'] = '' . $test_signature. ''; $edit['signature[format]'] = 'filtered_html'; $image = current($this->drupalGetTestFiles('image')); - $edit['files[picture_upload]'] = drupal_realpath($image->uri); + $edit['files[user_picture_und_0]'] = drupal_realpath($image->uri); $this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save')); // As the web user, fill in the comment form and preview the comment. diff --git a/core/modules/comment/templates/comment.tpl.php b/core/modules/comment/templates/comment.tpl.php index a6caa52..f7765b7 100644 --- a/core/modules/comment/templates/comment.tpl.php +++ b/core/modules/comment/templates/comment.tpl.php @@ -20,7 +20,8 @@ * - $permalink: Comment permalink. * - $submitted: Submission information created from $author and $created during * template_preprocess_comment(). - * - $user_picture: The comment author's picture from user-picture.tpl.php. + * - $user_picture: The comment author's picture. Use render($user_picture) to + * print it. * - $signature: Authors signature. * - $status: Comment status. Possible values are: * unpublished, published, or preview. @@ -65,7 +66,7 @@ diff --git a/core/modules/field/modules/field_sql_storage/field_sql_storage.install b/core/modules/field/modules/field_sql_storage/field_sql_storage.install index 4d4fe57..9607a9c 100644 --- a/core/modules/field/modules/field_sql_storage/field_sql_storage.install +++ b/core/modules/field/modules/field_sql_storage/field_sql_storage.install @@ -118,11 +118,15 @@ function field_sql_storage_update_8000(&$sandbox) { $table_info = array($data_table => $primary_key_data, $revision_table => $primary_key_revision); foreach ($table_info as $table => $primary_key) { - db_drop_primary_key($table); - db_drop_index($table, 'language'); - db_change_field($table, 'language', 'langcode', $field_langcode); - db_add_primary_key($table, $primary_key); - db_add_index($table, 'langcode', $langcode_index); + // Do not attempt to rename the 'language' column for fields that already + // contain it (created during the upgrade before this update function). + if (db_field_exists($table, 'language')) { + db_drop_primary_key($table); + db_drop_index($table, 'language'); + db_change_field($table, 'language', 'langcode', $field_langcode); + db_add_primary_key($table, $primary_key); + db_add_index($table, 'langcode', $langcode_index); + } } } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php index 39324bf..a67ad1f 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php @@ -32,6 +32,19 @@ function setUp() { $type_name = strtolower($this->randomName(8)) . '_test'; $type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name)); $this->type = $type->type; + + // Create a default vocabulary. + $vocabulary = entity_create('taxonomy_vocabulary', array( + 'name' => $this->randomName(), + 'description' => $this->randomName(), + 'machine_name' => drupal_strtolower($this->randomName()), + 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'help' => '', + 'nodes' => array('article' => 'article'), + 'weight' => mt_rand(0, 10), + )); + taxonomy_vocabulary_save($vocabulary); + $this->vocabulary = $vocabulary->machine_name; } /** diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php index 96f59a2..509b94f 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php @@ -171,11 +171,11 @@ function testViewModeCustom() { * Tests hiding the view modes fieldset when there's only one available. */ function testSingleViewMode() { - $this->drupalGet('admin/config/people/accounts/display'); + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary . '/display'); $this->assertNoText('Use custom display settings for the following view modes', 'Custom display settings fieldset found.'); // This may not trigger a notice when 'view_modes_custom' isn't available. - $this->drupalPost('admin/config/people/accounts/display', array(), t('Save')); + $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary . '/display', array(), t('Save')); } /** diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 2dd1b57..d9625e3 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1314,6 +1314,17 @@ function node_build_content(Node $node, $view_mode = 'full', $langcode = NULL) { } /** + * Implements hook_entity_prepare_view(). + * + * Load user account objects into node entities. + */ +function node_entity_prepare_view($entities, $type) { + if ($type == 'node') { + user_attach_accounts($entities); + } +} + +/** * Page callback: Generates an array which displays a node detail page. * * @param Drupal\node\Node $node @@ -1420,7 +1431,14 @@ function template_preprocess_node(&$variables) { if (variable_get('node_submitted_' . $node->type, TRUE)) { $variables['display_submitted'] = TRUE; $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date'])); - $variables['user_picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', array('account' => $node)) : ''; + if (theme_get_setting('toggle_node_user_picture')) { + // To change user picture settings (e.g. image style), edit the 'compact' + // view mode on User entity. + $variables['user_picture'] = user_view($node->account, 'compact'); + } + else { + $variables['user_picture'] = array(); + } } else { $variables['display_submitted'] = FALSE; diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 570ae88..024ec73 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -135,7 +135,6 @@ function node_preview(Node $node) { // user ID 0 denotes the anonymous user. if ($user = user_load_by_name($node->name)) { $node->uid = $user->uid; - $node->picture = $user->picture; } else { $node->uid = 0; // anonymous user @@ -144,7 +143,6 @@ function node_preview(Node $node) { elseif ($node->uid) { $user = user_load($node->uid); $node->name = $user->name; - $node->picture = $user->picture; } $node->changed = REQUEST_TIME; diff --git a/core/modules/node/templates/node.tpl.php b/core/modules/node/templates/node.tpl.php index b1da4aa..4696b83 100644 --- a/core/modules/node/templates/node.tpl.php +++ b/core/modules/node/templates/node.tpl.php @@ -10,7 +10,7 @@ * or print a subset such as render($content['field_example']). Use * hide($content['field_example']) to temporarily suppress the printing of a * given element. - * - $user_picture: The node author's picture from user-picture.tpl.php. + * - $user_picture: The node author's picture. Use render() to print it. * - $date: Formatted creation date. Preprocess functions can reformat it by * calling format_date() with the desired parameters on the $created variable. * - $name: Themed username of node author output from theme_username(). @@ -88,7 +88,7 @@ diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php new file mode 100644 index 0000000..a4f9ca2 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php @@ -0,0 +1,53 @@ + 'User picture upgrade test', + 'description' => 'Upgrade tests with user picture data.', + 'group' => 'Upgrade path', + ); + } + + public function setUp() { + $path = drupal_get_path('module', 'system') . '/tests/upgrade'; + $this->databaseDumpFiles = array( + $path . '/drupal-7.bare.standard_all.database.php.gz', + $path . '/drupal-7.user_picture.database.php', + ); + parent::setUp(); + } + + /** + * Tests expected user picture conversions after a successful upgrade. + */ + public function testUserPictureUpgrade() { + $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + + // Retrieve the field instance and check for migrated settings. + $instance = field_info_instance('user', 'user_picture', 'user'); + $file = entity_load('file', $instance['settings']['default_image']); + $this->assertIdentical($instance['settings']['default_image'], $file->id(), 'Default user picture has been migrated.'); + $this->assertEqual($file->uri, 'public://druplicon.png', 'File id matches the uri expected.'); + $this->assertEqual($instance['settings']['max_resolution'], '800x800', 'User picture maximum resolution has been migrated.'); + $this->assertEqual($instance['settings']['max_filesize'], '700 KB', 'User picture maximum filesize has been migrated.'); + $this->assertEqual($instance['description'], 'These are user picture guidelines.', 'User picture guidelines are now the user picture field description.'); + $this->assertEqual($instance['settings']['file_directory'], 'user_pictures_dir', 'User picture directory path has been migrated.'); + $this->assertEqual($instance['display']['default']['settings']['image_style'], 'thumbnail', 'User picture image style setting has been migrated.'); + } + +} diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 8033ad0..3375acd 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -409,7 +409,7 @@ function system_theme_settings($form, &$form_state, $key = '') { // Some features are not always available $disabled = array(); - if (!variable_get('user_pictures', 0)) { + if (!user_picture_enabled()) { $disabled['toggle_node_user_picture'] = TRUE; $disabled['toggle_comment_user_picture'] = TRUE; } diff --git a/core/modules/system/tests/upgrade/drupal-7.user_picture.database.php b/core/modules/system/tests/upgrade/drupal-7.user_picture.database.php new file mode 100644 index 0000000..288171b --- /dev/null +++ b/core/modules/system/tests/upgrade/drupal-7.user_picture.database.php @@ -0,0 +1,62 @@ +condition('name', $deleted_variables, 'IN') + ->execute(); + +db_insert('variable')->fields(array( + 'name', + 'value', +)) +->values(array( + 'name' => 'user_pictures', + 'value' => 'i:1;', +)) +->values(array( + 'name' => 'user_picture_default', + 'value' => 's:22:"public://druplicon.png";', +)) +->values(array( + 'name' => 'user_picture_dimensions', + 'value' => 's:7:"800x800";', +)) +->values(array( + 'name' => 'user_picture_file_size', + 'value' => 's:3:"700";', +)) +->values(array( + 'name' => 'user_picture_guidelines', + 'value' => 's:34:"These are user picture guidelines.";', +)) +->values(array( + 'name' => 'user_picture_path', + 'value' => 's:17:"user_pictures_dir";', +)) +->values(array( + 'name' => 'user_picture_style', + 'value' => 's:9:"thumbnail";', +)) +->execute(); + +// Copy the default file to files for managing it. +$result = file_unmanaged_copy('core/misc/druplicon.png', 'public://druplicon.png', FILE_EXISTS_ERROR); \ No newline at end of file diff --git a/core/modules/user/lib/Drupal/user/AccountFormController.php b/core/modules/user/lib/Drupal/user/AccountFormController.php index b79e983..30a6740 100644 --- a/core/modules/user/lib/Drupal/user/AccountFormController.php +++ b/core/modules/user/lib/Drupal/user/AccountFormController.php @@ -171,39 +171,6 @@ public function form(array $form, array &$form_state, EntityInterface $account) '#format' => isset($account->signature_format) ? $account->signature_format : NULL, ); - // Picture/avatar. - $form['picture'] = array( - '#type' => 'fieldset', - '#title' => t('Picture'), - '#weight' => 1, - '#access' => (!$register && variable_get('user_pictures', 0)), - ); - - $form['picture']['picture'] = array( - '#type' => 'value', - '#value' => isset($account->picture) ? $account->picture : NULL, - ); - - $form['picture']['picture_current'] = array( - '#markup' => theme('user_picture', array('account' => $account)), - ); - - $form['picture']['picture_delete'] = array( - '#type' => 'checkbox', - '#title' => t('Delete picture'), - '#access' => !empty($account->picture->fid), - '#description' => t('Check this box to delete your current picture.'), - ); - - $form['picture']['picture_upload'] = array( - '#type' => 'file', - '#title' => t('Upload picture'), - '#size' => 48, - '#description' => t('Your virtual face or picture. Pictures larger than @dimensions pixels will be scaled down.', array('@dimensions' => variable_get('user_picture_dimensions', '85x85'))) . ' ' . filter_xss_admin(variable_get('user_picture_guidelines', '')), - ); - - $form['#validate'][] = 'user_validate_picture'; - $user_preferred_langcode = $register ? $language_interface->langcode : user_preferred_langcode($account); $user_preferred_admin_langcode = $register ? $language_interface->langcode : user_preferred_langcode($account, 'admin'); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserEditTest.php b/core/modules/user/lib/Drupal/user/Tests/UserEditTest.php index 6bf60bc..cc2e141 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserEditTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserEditTest.php @@ -26,8 +26,7 @@ public static function getInfo() { * Test user edit page. */ function testUserEdit() { - // Test user edit functionality with user pictures disabled. - variable_set('user_pictures', 0); + // Test user edit functionality. $user1 = $this->drupalCreateUser(array('change own username')); $user2 = $this->drupalCreateUser(array()); $this->drupalLogin($user1); @@ -37,11 +36,6 @@ function testUserEdit() { $this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); $this->assertRaw(t('The name %name is already taken.', array('%name' => $edit['name']))); - // Repeat the test with user pictures enabled, which modifies the form. - variable_set('user_pictures', 1); - $this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); - $this->assertRaw(t('The name %name is already taken.', array('%name' => $edit['name']))); - // Check that filling out a single password field does not validate. $edit = array(); $edit['pass[pass1]'] = ''; diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php index ddfae72..d364dac 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php @@ -9,6 +9,9 @@ use Drupal\simpletest\WebTestBase; +/** + * Tests user picture functionality. + */ class UserPictureTest extends WebTestBase { /** @@ -16,312 +19,117 @@ class UserPictureTest extends WebTestBase { * * @var array */ - public static $modules = array('image'); + public static $modules = array('image', 'comment'); protected $user; protected $_directory_test; public static function getInfo() { return array( - 'name' => 'Upload user picture', - 'description' => 'Assure that dimension check, extension check and image scaling work as designed.', - 'group' => 'User' + 'name' => 'User pictures', + 'description' => 'Tests user picture functionality.', + 'group' => 'User', ); } function setUp() { parent::setUp(); - // Enable user pictures. - variable_set('user_pictures', 1); - - // Configure default user picture settings. - variable_set('user_picture_dimensions', '1024x1024'); - variable_set('user_picture_file_size', '800'); - variable_set('user_picture_style', 'thumbnail'); - - $this->user = $this->drupalCreateUser(); - - // Test if directories specified in settings exist in filesystem. - $file_dir = 'public://'; - $file_check = file_prepare_directory($file_dir, FILE_CREATE_DIRECTORY); - // TODO: Test public and private methods? - - $picture_dir = variable_get('user_picture_path', 'pictures'); - $picture_path = $file_dir . $picture_dir; - - $pic_check = file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY); - $this->_directory_test = is_writable($picture_path); - $this->assertTrue($this->_directory_test, "The directory $picture_path doesn't exist or is not writable. Further tests won't be made."); - } - - function testNoPicture() { - $this->drupalLogin($this->user); - - // Try to upload a file that is not an image for the user picture. - $not_an_image = current($this->drupalGetTestFiles('html')); - $this->saveUserPicture($not_an_image); - $this->assertRaw(t('Only JPEG, PNG and GIF images are allowed.'), t('Non-image files are not accepted.')); - } - - /** - * Do the test: - * GD Toolkit is installed - * Picture has invalid dimension - * - * results: The image should be uploaded because ImageGDToolkit resizes the picture - */ - function testWithGDinvalidDimension() { - if ($this->_directory_test && image_get_toolkit()) { - $this->drupalLogin($this->user); - - $image = current($this->drupalGetTestFiles('image')); - $info = image_get_info($image->uri); - - // Set new variables: invalid dimensions, valid filesize (0 = no limit). - $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', 0); - - $pic_path = $this->saveUserPicture($image); - // Check that the image was resized and is being displayed on the - // user's profile page. - $text = t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $test_dim)); - $this->assertRaw($text, t('Image was resized.')); - $alt = t("@user's picture", array('@user' => user_format_name($this->user))); - $style = variable_get('user_picture_style', ''); - $this->assertRaw(image_style_url($style, $pic_path), t("Image is displayed in user's edit page")); - - // Check if file is located in proper directory. - $this->assertTrue(is_file($pic_path), t("File is located in proper directory")); - } - } - - /** - * Do the test: - * GD Toolkit is installed - * Picture has invalid size - * - * results: The image should be uploaded because ImageGDToolkit resizes the picture - */ - function testWithGDinvalidSize() { - if ($this->_directory_test && image_get_toolkit()) { - $this->drupalLogin($this->user); - - // Images are sorted first by size then by name. We need an image - // bigger than 1 KB so we'll grab the last one. - $files = $this->drupalGetTestFiles('image'); - $image = end($files); - $info = image_get_info($image->uri); - - // Set new variables: valid dimensions, invalid filesize. - $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); - $test_size = 1; - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', $test_size); - - $pic_path = $this->saveUserPicture($image); - - // Test that the upload failed and that the correct reason was cited. - $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename)); - $this->assertRaw($text, t('Upload failed.')); - $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->uri)), '%maxsize' => format_size($test_size * 1024))); - $this->assertRaw($text, t('File size cited as reason for failure.')); - - // Check if file is not uploaded. - $this->assertFalse(is_file($pic_path), t('File was not uploaded.')); - } - } - - /** - * Do the test: - * GD Toolkit is not installed - * Picture has invalid size - * - * results: The image shouldn't be uploaded - */ - function testWithoutGDinvalidDimension() { - if ($this->_directory_test && !image_get_toolkit()) { - $this->drupalLogin($this->user); - - $image = current($this->drupalGetTestFiles('image')); - $info = image_get_info($image->uri); - - // Set new variables: invalid dimensions, valid filesize (0 = no limit). - $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', 0); - - $pic_path = $this->saveUserPicture($image); - - // Test that the upload failed and that the correct reason was cited. - $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename)); - $this->assertRaw($text, t('Upload failed.')); - $text = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $test_dim)); - $this->assertRaw($text, t('Checking response on invalid image (dimensions).')); - - // Check if file is not uploaded. - $this->assertFalse(is_file($pic_path), t('File was not uploaded.')); - } - } - - /** - * Do the test: - * GD Toolkit is not installed - * Picture has invalid size - * - * results: The image shouldn't be uploaded - */ - function testWithoutGDinvalidSize() { - if ($this->_directory_test && !image_get_toolkit()) { - $this->drupalLogin($this->user); - - $image = current($this->drupalGetTestFiles('image')); - $info = image_get_info($image->uri); - - // Set new variables: valid dimensions, invalid filesize. - $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); - $test_size = 1; - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', $test_size); - - $pic_path = $this->saveUserPicture($image); - - // Test that the upload failed and that the correct reason was cited. - $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename)); - $this->assertRaw($text, t('Upload failed.')); - $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->uri)), '%maxsize' => format_size($test_size * 1024))); - $this->assertRaw($text, t('File size cited as reason for failure.')); - - // Check if file is not uploaded. - $this->assertFalse(is_file($pic_path), t('File was not uploaded.')); - } + $this->web_user = $this->drupalCreateUser(array( + 'access content', + 'access comments', + 'post comments', + 'skip comment approval', + )); + $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); + + // @see standard.install + module_load_install('user'); + _user_install_picture_field(); + + // Remove 'summary' pseudo-field from compact view mode on the User entity. + $bundle_settings = field_bundle_settings('user', 'user'); + $bundle_settings['extra_fields']['display']['member_for']['compact'] = array( + 'visible' => FALSE, + 'weight' => 10, + ); + field_bundle_settings('user', 'user', $bundle_settings); } /** - * Do the test: - * Picture is valid (proper size and dimension) - * - * results: The image should be uploaded + * Tests creation, display, and deletion of user pictures. */ - function testPictureIsValid() { - if ($this->_directory_test) { - $this->drupalLogin($this->user); - - $image = current($this->drupalGetTestFiles('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); - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', 0); - - $pic_path = $this->saveUserPicture($image); - - // Check if image is displayed in user's profile page. - $this->drupalGet('user'); - $this->assertRaw(file_uri_target($pic_path), t("Image is displayed in user's profile page")); + function testCreateDeletePicture() { + $this->drupalLogin($this->web_user); - // Check if file is located in proper directory. - $this->assertTrue(is_file($pic_path), t('File is located in proper directory')); - - // Set new picture dimensions. - $test_dim = ($info['width'] + 5) . 'x' . ($info['height'] + 5); - variable_set('user_picture_dimensions', $test_dim); - - $pic_path2 = $this->saveUserPicture($image); - $this->assertNotEqual($pic_path, $pic_path2, t('Filename of second picture is different.')); - } - } - - /** - * Test HTTP schema working with user pictures. - */ - function testExternalPicture() { - $this->drupalLogin($this->user); - // Set the default picture to an URI with a HTTP schema. - $images = $this->drupalGetTestFiles('image'); - $image = $images[0]; - $pic_path = file_create_url($image->uri); - variable_set('user_picture_default', $pic_path); + // Save a new picture. + $image = current($this->drupalGetTestFiles('image')); + $file = $this->saveUserPicture($image); - // Check if image is displayed in user's profile page. + // Verify that the image is displayed on the user account page. $this->drupalGet('user'); - - // Get the user picture image via xpath. - $elements = $this->xpath('//div[@class="user-picture"]/img'); - $this->assertEqual(count($elements), 1, t("There is exactly one user picture on the user's profile page")); - $this->assertEqual($pic_path, (string) $elements[0]['src'], t("User picture source is correct: " . $pic_path . " " . print_r($elements, TRUE))); + $this->assertRaw(file_uri_target($file->uri), t('User picture found on user account page.')); + + // Delete the picture. + $edit = array(); + $this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Remove')); + $this->drupalPost(NULL, array(), t('Save')); + + // Call system_cron() to clean up the file. Make sure the timestamp + // of the file is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE. + db_update('file_managed') + ->fields(array( + 'timestamp' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1), + )) + ->condition('fid', $file->fid) + ->execute(); + drupal_cron_run(); + + // Verify that the image has been deleted. + $this->assertFalse(file_load($file->fid), 'File was removed from the database.'); + // Clear out PHP's file stat cache so we see the current value. + clearstatcache(TRUE, $file->uri); + $this->assertFalse(is_file($file->uri), 'File was removed from the file system.'); } /** - * Tests deletion of user pictures. + * Tests embedded users on node pages. */ - function testDeletePicture() { - $this->drupalLogin($this->user); - - $image = current($this->drupalGetTestFiles('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); - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', 0); + function testPictureOnNodeComment() { + $this->drupalLogin($this->web_user); // Save a new picture. - $edit = array('files[picture_upload]' => drupal_realpath($image->uri)); - $this->drupalPost('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->drupalGet('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'); + $image = current($this->drupalGetTestFiles('image')); + $file = $this->saveUserPicture($image); - $edit = array('picture_delete' => 1); - $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save')); + $node = $this->drupalCreateNode(array('type' => 'article')); - // Load actual user data from database. - $account1 = user_load($this->user->uid, TRUE); - $this->assertFalse($account1->picture, 'User object has no picture'); + // Enable user pictures on nodes. + variable_set('theme_settings', array('toggle_node_user_picture' => TRUE)); - $file = file_load($account->picture->fid); - $this->assertFalse($file, 'File is removed from database'); + // Verify that the image is displayed on the user account page. + $this->drupalGet('node/' . $node->nid); + $this->assertRaw(file_uri_target($file->uri), 'User picture found on node page.'); - // Clear out PHP's file stat cache so we see the current value. - clearstatcache(TRUE, $pic_path); - $this->assertFalse(is_file($pic_path), 'File is removed from file system'); - } + // Enable user pictures on comments, instead of nodes. + variable_set('theme_settings', array('toggle_comment_user_picture' => TRUE)); - function saveUserPicture($image) { - $edit = array('files[picture_upload]' => drupal_realpath($image->uri)); - $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save')); - - // Load actual user data from database. - $account = user_load($this->user->uid, TRUE); - return !empty($account->picture) ? $account->picture->uri : NULL; + $edit = array( + 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this->randomString(), + ); + $this->drupalPost('comment/reply/' . $node->nid, $edit, t('Save')); + $this->assertRaw(file_uri_target($file->uri), 'User picture found on comment.'); } /** - * Tests the admin form validates user picture settings. + * Edits the user picture for the test user. */ - function testUserPictureAdminFormValidation() { - $this->drupalLogin($this->drupalCreateUser(array('administer users'))); - - // The default values are valid. - $this->drupalPost('admin/config/people/accounts', array(), t('Save configuration')); - $this->assertText(t('The configuration options have been saved.'), 'The default values are valid.'); + function saveUserPicture($image) { + $edit = array('files[user_picture_und_0]' => drupal_realpath($image->uri)); + $this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save')); - // The form does not save with an invalid file size. - $edit = array( - 'user_picture_file_size' => $this->randomName(), - ); - $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration')); - $this->assertNoText(t('The configuration options have been saved.'), 'The form does not save with an invalid file size.'); + // Load actual user data from database. + $account = user_load($this->web_user->uid, TRUE); + return file_load($account->user_picture[LANGUAGE_NOT_SPECIFIED][0]['fid']); } } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php index d89192f..857390f 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php @@ -185,7 +185,6 @@ function testRegistrationDefaultValues() { $this->assertEqual($new_user->timezone, variable_get('date_default_timezone'), t('Correct time zone field.')); $this->assertEqual($new_user->langcode, language_default()->langcode, t('Correct language field.')); $this->assertEqual($new_user->preferred_langcode, language_default()->langcode, t('Correct preferred language field.')); - $this->assertEqual($new_user->picture, 0, t('Correct picture field.')); $this->assertEqual($new_user->init, $mail, t('Correct init field.')); } diff --git a/core/modules/user/lib/Drupal/user/User.php b/core/modules/user/lib/Drupal/user/User.php index 2217588..1b59976 100644 --- a/core/modules/user/lib/Drupal/user/User.php +++ b/core/modules/user/lib/Drupal/user/User.php @@ -129,13 +129,6 @@ class User extends Entity { public $preferred_admin_langcode = LANGUAGE_NOT_SPECIFIED; /** - * The file ID of the user's picture. - * - * @var integer - */ - public $picture = 0; - - /** * The email address used for initial account creation. * * @var string diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index 2660300..f7ffa6b 100644 --- a/core/modules/user/lib/Drupal/user/UserStorageController.php +++ b/core/modules/user/lib/Drupal/user/UserStorageController.php @@ -23,12 +23,7 @@ class UserStorageController extends DatabaseStorageController { * Overrides Drupal\Core\Entity\DatabaseStorageController::attachLoad(). */ function attachLoad(&$queried_users, $load_revision = FALSE) { - // Build an array of user picture IDs so that these can be fetched later. - $picture_fids = array(); foreach ($queried_users as $key => $record) { - if ($record->picture) { - $picture_fids[] = $record->picture; - } $queried_users[$key]->data = unserialize($record->data); $queried_users[$key]->roles = array(); if ($record->uid) { @@ -45,15 +40,6 @@ function attachLoad(&$queried_users, $load_revision = FALSE) { $queried_users[$record->uid]->roles[$record->rid] = $record->name; } - // Add the full file objects for user pictures if enabled. - if (!empty($picture_fids) && variable_get('user_pictures', 1) == 1) { - $pictures = file_load_multiple($picture_fids); - foreach ($queried_users as $entity) { - if (!empty($entity->picture) && isset($pictures[$entity->picture])) { - $entity->picture = $pictures[$entity->picture]; - } - } - } // Call the default attachLoad() method. This will add fields and call // hook_user_load(). parent::attachLoad($queried_users, $load_revision); @@ -98,45 +84,7 @@ protected function preSave(EntityInterface $entity) { } } - if (!empty($entity->picture_upload)) { - $entity->picture = $entity->picture_upload; - } - // Delete the picture if the submission indicates that it should be deleted - // and no replacement was submitted. - elseif (!empty($entity->picture_delete)) { - $entity->picture = 0; - file_usage_delete($entity->original->picture, 'user', 'user', $entity->uid); - file_delete($entity->original->picture->fid); - } - if (!$entity->isNew()) { - // Process picture uploads. - if (!empty($entity->picture->fid) && (!isset($entity->original->picture->fid) || $entity->picture->fid != $entity->original->picture->fid)) { - $picture = $entity->picture; - // If the picture is a temporary file, move it to its final location - // and make it permanent. - if (!$picture->status) { - $info = image_get_info($picture->uri); - $picture_directory = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); - - // Prepare the pictures directory. - file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY); - $destination = file_stream_wrapper_uri_normalize($picture_directory . '/picture-' . $entity->uid . '-' . REQUEST_TIME . '.' . $info['extension']); - - // Move the temporary file into the final location. - if ($picture = file_move($picture, $destination, FILE_EXISTS_RENAME)) { - $entity->picture = $picture; - file_usage_add($picture, 'user', 'user', $entity->uid); - } - } - // Delete the previous picture if it was deleted or replaced. - if (!empty($entity->original->picture->fid)) { - file_usage_delete($entity->original->picture, 'user', 'user', $entity->uid); - file_delete($entity->original->picture->fid); - } - } - $entity->picture = empty($entity->picture->fid) ? 0 : $entity->picture->fid; - // If the password is empty, that means it was not changed, so use the // original password. if (empty($entity->pass)) { diff --git a/core/modules/user/templates/user-picture.tpl.php b/core/modules/user/templates/user-picture.tpl.php deleted file mode 100644 index ee82187..0000000 --- a/core/modules/user/templates/user-picture.tpl.php +++ /dev/null @@ -1,23 +0,0 @@ - - -
diff --git a/core/themes/bartik/templates/node.tpl.php b/core/themes/bartik/templates/node.tpl.php index ce30175..fbd80ab 100644 --- a/core/themes/bartik/templates/node.tpl.php +++ b/core/themes/bartik/templates/node.tpl.php @@ -10,7 +10,7 @@ * or print a subset such as render($content['field_example']). Use * hide($content['field_example']) to temporarily suppress the printing of a * given element. - * - $user_picture: The node author's picture from user-picture.tpl.php. + * - $user_picture: The node author's picture. Use render() when printing. * - $date: Formatted creation date. Preprocess functions can reformat it by * calling format_date() with the desired parameters on the $created variable. * - $name: Themed username of node author output from theme_username(). @@ -90,7 +90,7 @@
diff --git a/core/update.php b/core/update.php index 2273b40..22c40a3 100644 --- a/core/update.php +++ b/core/update.php @@ -200,7 +200,8 @@ function update_results_page() { $output = 'Updates were attempted. If you see no failures below, you may proceed happily back to your site. Otherwise, you may need to update your database manually.' . $log_message . '
'; } else { - list($module, $version) = array_pop(reset($_SESSION['updates_remaining'])); + $last = reset($_SESSION['updates_remaining']); + list($module, $version) = array_pop($last); $output = 'The update process was aborted prematurely while running update #' . $version . ' in ' . $module . '.module.' . $log_message;
if (module_exists('dblog')) {
$output .= ' You may need to check the watchdog
database table manually.';