View source
<?php
namespace Drupal\file\Tests\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestData;
class RelationshipUserFileDataTest extends ViewTestBase {
public static $modules = array(
'file',
'file_test_views',
'user',
);
public static $testViews = array(
'test_file_user_file_data',
);
protected function setUp() {
parent::setUp();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'user_file',
'type' => 'file',
'translatable' => '0',
))
->save();
entity_create('field_config', array(
'label' => 'User File',
'description' => '',
'field_name' => 'user_file',
'entity_type' => 'user',
'bundle' => 'user',
'required' => 0,
))
->save();
ViewTestData::createTestViews(get_class($this), array(
'file_test_views',
));
}
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');
$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);
}
}