55cecc0fc09d935b55cc4b6398e6b2e7823e6cac
[yaffs-website] / web / core / modules / image / src / Tests / Views / RelationshipUserImageDataTest.php
1 <?php
2
3 namespace Drupal\image\Tests\Views;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\file\Entity\File;
7 use Drupal\views\Tests\ViewTestBase;
8 use Drupal\views\Views;
9 use Drupal\views\Tests\ViewTestData;
10 use Drupal\field\Entity\FieldStorageConfig;
11
12 /**
13  * Tests image on user relationship handler.
14  *
15  * @group image
16  */
17 class RelationshipUserImageDataTest extends ViewTestBase {
18
19   /**
20    * Modules to install.
21    *
22    * @var array
23    */
24   public static $modules = ['image', 'image_test_views', 'user'];
25
26   /**
27    * Views used by this test.
28    *
29    * @var array
30    */
31   public static $testViews = ['test_image_user_image_data'];
32
33   protected function setUp() {
34     parent::setUp();
35
36     // Create the user profile field and instance.
37     FieldStorageConfig::create([
38       'entity_type' => 'user',
39       'field_name' => 'user_picture',
40       'type' => 'image',
41       'translatable' => '0',
42     ])->save();
43     FieldConfig::create([
44       'label' => 'User Picture',
45       'description' => '',
46       'field_name' => 'user_picture',
47       'entity_type' => 'user',
48       'bundle' => 'user',
49       'required' => 0,
50     ])->save();
51
52     ViewTestData::createTestViews(get_class($this), ['image_test_views']);
53   }
54
55   /**
56    * Tests using the views image relationship.
57    */
58   public function testViewsHandlerRelationshipUserImageData() {
59     $file = File::create([
60       'fid' => 2,
61       'uid' => 2,
62       'filename' => 'image-test.jpg',
63       'uri' => "public://image-test.jpg",
64       'filemime' => 'image/jpeg',
65       'created' => 1,
66       'changed' => 1,
67       'status' => FILE_STATUS_PERMANENT,
68     ]);
69     $file->enforceIsNew();
70     file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png'));
71     $file->save();
72
73     $account = $this->drupalCreateUser();
74     $account->user_picture->target_id = 2;
75     $account->save();
76
77     $view = Views::getView('test_image_user_image_data');
78     // Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies().
79     $expected = [
80       'module' => [
81         'file',
82         'user',
83       ],
84     ];
85     $this->assertIdentical($expected, $view->getDependencies());
86     $this->executeView($view);
87     $expected_result = [
88       [
89         'file_managed_user__user_picture_fid' => '2',
90       ],
91     ];
92     $column_map = ['file_managed_user__user_picture_fid' => 'file_managed_user__user_picture_fid'];
93     $this->assertIdenticalResultset($view, $expected_result, $column_map);
94   }
95
96 }