Version 1
[yaffs-website] / web / modules / contrib / linkit / src / Tests / LinkitTestBase.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\linkit\Tests\LinkitTestBase.
6  */
7
8 namespace Drupal\linkit\Tests;
9
10 use Drupal\Component\Utility\Unicode;
11 use Drupal\linkit\Entity\Profile;
12 use Drupal\simpletest\WebTestBase;
13
14 /**
15  * Sets up page and article content types.
16  */
17 abstract class LinkitTestBase extends WebTestBase {
18
19   /**
20    * Modules to enable.
21    *
22    * Enable block module to get the local_actions_block to work.
23    *
24    * @var array
25    */
26   public static $modules = ['linkit', 'linkit_test', 'block'];
27
28   /**
29    * A user with the 'administer linkit profiles' permission.
30    *
31    * @var \Drupal\user\UserInterface
32    */
33   protected $adminUser;
34
35   /**
36    * A user without the 'administer linkit profiles' permission.
37    *
38    * @var \Drupal\user\UserInterface
39    */
40   protected $baseUser;
41
42   /**
43    * {@inheritdoc}
44    */
45   protected function setUp() {
46     parent::setUp();
47     $this->adminUser = $this->drupalCreateUser(['administer linkit profiles']);
48     $this->baseUser = $this->drupalCreateUser();
49
50     $this->drupalPlaceBlock('page_title_block', ['region' => 'content']);
51     $this->drupalPlaceBlock('local_tasks_block', ['region' => 'content']);
52     $this->drupalPlaceBlock('local_actions_block', ['region' => 'content']);
53     $this->drupalPlaceBlock('system_messages_block', ['region' => 'highlighted']);
54   }
55
56   /**
57    * Creates a profile based on default settings.
58    *
59    * @param array $settings
60    *   (optional) An associative array of settings for the profile, as used in
61    *   entity_create(). Override the defaults by specifying the key and value
62    *   in the array
63    *
64    *   The following defaults are provided:
65    *   - label: Random string.
66    *
67    * @return \Drupal\linkit\ProfileInterface
68    *   The created profile entity.
69    */
70   protected function createProfile(array $settings = []) {
71     // Populate defaults array.
72     $settings += [
73       'id' => Unicode::strtolower($this->randomMachineName()),
74       'label' => $this->randomMachineName(),
75     ];
76
77     $profile = Profile::create($settings);
78     $profile->save();
79
80     return $profile;
81   }
82
83 }