function UserPictureTest::testPictureOnNodeComment

Tests embedded users on node pages.

File

drupal/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php, line 91
Definition of Drupal\user\Tests\UserPictureTest.

Class

UserPictureTest
Tests user picture functionality.

Namespace

Drupal\user\Tests

Code

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

  // 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->container
    ->get('config.factory')
    ->get('system.theme.global')
    ->set('features.node_user_picture', TRUE)
    ->save();

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

  // Enable user pictures on comments, instead of nodes.
  $this->container
    ->get('config.factory')
    ->get('system.theme.global')
    ->set('features.node_user_picture', FALSE)
    ->set('features.comment_user_picture', TRUE)
    ->save();
  $edit = array(
    'comment_body[' . Language::LANGCODE_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.');

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