function RelationshipUserImageDataTest::testViewsHandlerRelationshipUserImageData

Same name and namespace in other branches
  1. 9 core/modules/image/tests/src/Kernel/Views/RelationshipUserImageDataTest.php \Drupal\Tests\image\Kernel\Views\RelationshipUserImageDataTest::testViewsHandlerRelationshipUserImageData()
  2. 8.9.x core/modules/image/tests/src/Kernel/Views/RelationshipUserImageDataTest.php \Drupal\Tests\image\Kernel\Views\RelationshipUserImageDataTest::testViewsHandlerRelationshipUserImageData()
  3. 11.x core/modules/image/tests/src/Kernel/Views/RelationshipUserImageDataTest.php \Drupal\Tests\image\Kernel\Views\RelationshipUserImageDataTest::testViewsHandlerRelationshipUserImageData()

Tests using the views image relationship.

File

core/modules/image/tests/src/Kernel/Views/RelationshipUserImageDataTest.php, line 73

Class

RelationshipUserImageDataTest
Tests image on user relationship handler.

Namespace

Drupal\Tests\image\Kernel\Views

Code

public function testViewsHandlerRelationshipUserImageData() : void {
  $file = File::create([
    'fid' => 2,
    'uid' => 2,
    'filename' => 'image-test.jpg',
    'uri' => "public://image-test.jpg",
    'filemime' => 'image/jpeg',
    'created' => 1,
    'changed' => 1,
  ]);
  $file->setPermanent();
  $file->enforceIsNew();
  file_put_contents($file->getFileUri(), file_get_contents('core/tests/fixtures/files/image-1.png'));
  $file->save();
  $account = User::create([
    'name' => 'foo',
  ]);
  $account->user_picture->target_id = 2;
  $account->save();
  $view = Views::getView('test_image_user_image_data');
  // Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies().
  $expected = [
    'module' => [
      'file',
      'user',
    ],
  ];
  $this->assertSame($expected, $view->getDependencies());
  $this->executeView($view);
  $expected_result = [
    [
      'file_managed_user__user_picture_fid' => '2',
    ],
  ];
  $column_map = [
    'file_managed_user__user_picture_fid' => 'file_managed_user__user_picture_fid',
  ];
  $this->assertIdenticalResultset($view, $expected_result, $column_map);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.