Newer
Older
Alex Pott
committed
<?php
/**
* @file
* Contains \Drupal\image\Tests\Views\RelationshipUserImageDataTest.
*/
namespace Drupal\image\Tests\Views;
use Drupal\field\Entity\FieldConfig;
Alex Pott
committed
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestData;
use Drupal\field\Entity\FieldStorageConfig;
Alex Pott
committed
/**
* Tests image on user relationship handler.
*
* @group image
*/
class RelationshipUserImageDataTest extends ViewTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('image', 'image_test_views', 'user');
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_image_user_image_data');
protected function setUp() {
parent::setUp();
// Create the user profile field and instance.
FieldStorageConfig::create(array(
Alex Pott
committed
'entity_type' => 'user',
'field_name' => 'user_picture',
'type' => 'image',
'translatable' => '0',
))->save();
FieldConfig::create([
Alex Pott
committed
'label' => 'User Picture',
'description' => '',
'field_name' => 'user_picture',
'entity_type' => 'user',
'bundle' => 'user',
'required' => 0,
])->save();
Alex Pott
committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
ViewTestData::createTestViews(get_class($this), array('image_test_views'));
}
/**
* Tests using the views image relationship.
*/
public function testViewsHandlerRelationshipUserImageData() {
$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_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->assertIdentical($expected, $view->getDependencies());
Alex Pott
committed
$this->executeView($view);
$expected_result = array(
array(
'file_managed_user__user_picture_fid' => '2',
),
);
$column_map = array('file_managed_user__user_picture_fid' => 'file_managed_user__user_picture_fid');
$this->assertIdenticalResultset($view, $expected_result, $column_map);
}
}