Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / views / tests / src / Kernel / Plugin / RelationshipJoinTestBase.php
1 <?php
2
3 namespace Drupal\Tests\views\Kernel\Plugin;
4
5 use Drupal\user\Entity\User;
6 use Drupal\views\Views;
7
8 /**
9  * Provides a base class for a testing a relationship.
10  *
11  * @see \Drupal\views\Tests\Handler\JoinTest
12  * @see \Drupal\views\Tests\Plugin\RelationshipTest
13  */
14 abstract class RelationshipJoinTestBase extends PluginKernelTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['system', 'user', 'field'];
22
23   /**
24    * @var \Drupal\user\Entity\User
25    */
26   protected $rootUser;
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUpFixtures() {
32     $this->installEntitySchema('user');
33     $this->installConfig(['user']);
34     parent::setUpFixtures();
35
36     // Create a record for uid 1.
37     $this->rootUser = User::create(['name' => $this->randomMachineName()]);
38     $this->rootUser->save();
39
40     Views::viewsData()->clear();
41   }
42
43   /**
44    * Overrides \Drupal\views\Tests\ViewTestBase::schemaDefinition().
45    *
46    * Adds a uid column to test the relationships.
47    *
48    * @internal
49    */
50   protected function schemaDefinition() {
51     $schema = parent::schemaDefinition();
52
53     $schema['views_test_data']['fields']['uid'] = [
54       'description' => "The {users_field_data}.uid of the author of the beatle entry.",
55       'type' => 'int',
56       'unsigned' => TRUE,
57       'not null' => TRUE,
58       'default' => 0
59     ];
60
61     return $schema;
62   }
63
64   /**
65    * Overrides \Drupal\views\Tests\ViewTestBase::viewsData().
66    *
67    * Adds a relationship for the uid column.
68    */
69   protected function viewsData() {
70     $data = parent::viewsData();
71     $data['views_test_data']['uid'] = [
72       'title' => t('UID'),
73       'help' => t('The test data UID'),
74       'relationship' => [
75         'id' => 'standard',
76         'base' => 'users_field_data',
77         'base field' => 'uid'
78       ]
79     ];
80
81     return $data;
82   }
83
84 }