You are here

public function RelationshipUserFileDataTest::testViewsHandlerRelationshipUserFileData in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php \Drupal\file\Tests\Views\RelationshipUserFileDataTest::testViewsHandlerRelationshipUserFileData()

Tests using the views file relationship.

File

core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php, line 60
Contains \Drupal\file\Tests\Views\RelationshipUserFileDataTest.

Class

RelationshipUserFileDataTest
Tests file on user relationship handler.

Namespace

Drupal\file\Tests\Views

Code

public function testViewsHandlerRelationshipUserFileData() {
  $file = entity_create('file', array(
    'fid' => 2,
    'uid' => 2,
    'filename' => 'image-test.jpg',
    'uri' => "public://image-test.jpg",
    'filemime' => 'image/jpeg',
    'created' => 1,
    'changed' => 1,
    'status' => FILE_STATUS_PERMANENT,
  ));
  $file
    ->enforceIsNew();
  file_put_contents($file
    ->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png'));
  $file
    ->save();
  $account = $this
    ->drupalCreateUser();
  $account->user_file->target_id = 2;
  $account
    ->save();
  $view = Views::getView('test_file_user_file_data');

  // Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies().
  $expected = [
    'module' => [
      'file',
      'user',
    ],
  ];
  $this
    ->assertIdentical($expected, $view
    ->getDependencies());
  $this
    ->executeView($view);
  $expected_result = array(
    array(
      'file_managed_user__user_file_fid' => '2',
    ),
  );
  $column_map = array(
    'file_managed_user__user_file_fid' => 'file_managed_user__user_file_fid',
  );
  $this
    ->assertIdenticalResultset($view, $expected_result, $column_map);
}