Version 1
[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   protected function schemaDefinition() {
49     $schema = parent::schemaDefinition();
50
51     $schema['views_test_data']['fields']['uid'] = [
52       'description' => "The {users_field_data}.uid of the author of the beatle entry.",
53       'type' => 'int',
54       'unsigned' => TRUE,
55       'not null' => TRUE,
56       'default' => 0
57     ];
58
59     return $schema;
60   }
61
62   /**
63    * Overrides \Drupal\views\Tests\ViewTestBase::viewsData().
64    *
65    * Adds a relationship for the uid column.
66    */
67   protected function viewsData() {
68     $data = parent::viewsData();
69     $data['views_test_data']['uid'] = [
70       'title' => t('UID'),
71       'help' => t('The test data UID'),
72       'relationship' => [
73         'id' => 'standard',
74         'base' => 'users_field_data',
75         'base field' => 'uid'
76       ]
77     ];
78
79     return $data;
80   }
81
82 }