You are here

function UserPictureTest::testPictureOnNodeComment in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Tests/UserPictureTest.php \Drupal\user\Tests\UserPictureTest::testPictureOnNodeComment()

Tests embedded users on node pages.

File

core/modules/user/src/Tests/UserPictureTest.php, line 89
Contains \Drupal\user\Tests\UserPictureTest.

Class

UserPictureTest
Tests user picture functionality.

Namespace

Drupal\user\Tests

Code

function testPictureOnNodeComment() {
  $this
    ->drupalLogin($this->webUser);

  // Save a new picture.
  $image = current($this
    ->drupalGetTestFiles('image'));
  $file = $this
    ->saveUserPicture($image);
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));

  // Enable user pictures on nodes.
  $this
    ->config('system.theme.global')
    ->set('features.node_user_picture', TRUE)
    ->save();
  $image_style_id = $this
    ->config('core.entity_view_display.user.user.compact')
    ->get('content.user_picture.settings.image_style');
  $style = ImageStyle::load($image_style_id);
  $image_url = $style
    ->buildUrl($file
    ->getfileUri());
  $alt_text = 'Profile picture for user ' . $this->webUser
    ->getUsername();

  // Verify that the image is displayed on the node page.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->cssSelect('.node__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]');
  $this
    ->assertEqual(count($elements), 1, 'User picture with alt text found on node page.');

  // Enable user pictures on comments, instead of nodes.
  $this
    ->config('system.theme.global')
    ->set('features.node_user_picture', FALSE)
    ->set('features.comment_user_picture', TRUE)
    ->save();
  $edit = array(
    'comment_body[0][value]' => $this
      ->randomString(),
  );
  $this
    ->drupalPostForm('comment/reply/node/' . $node
    ->id() . '/comment', $edit, t('Save'));
  $elements = $this
    ->cssSelect('.comment__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]');
  $this
    ->assertEqual(count($elements), 1, 'User picture with alt text found on the comment.');

  // Disable user pictures on comments and nodes.
  $this
    ->config('system.theme.global')
    ->set('features.node_user_picture', FALSE)
    ->set('features.comment_user_picture', FALSE)
    ->save();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertNoRaw(file_uri_target($file
    ->getFileUri()), 'User picture not found on node and comment.');
}