Version 1
[yaffs-website] / web / core / modules / block / src / Tests / BlockTestBase.php
1 <?php
2
3 namespace Drupal\block\Tests;
4
5 use Drupal\simpletest\WebTestBase;
6 use Drupal\filter\Entity\FilterFormat;
7
8 /**
9  * Provides setup and helper methods for block module tests.
10  */
11 abstract class BlockTestBase extends WebTestBase {
12
13   /**
14    * Modules to install.
15    *
16    * @var array
17    */
18   public static $modules = ['block', 'filter', 'test_page_test', 'help', 'block_test'];
19
20   /**
21    * A list of theme regions to test.
22    *
23    * @var array
24    */
25   protected $regions;
26
27   /**
28    * A test user with administrative privileges.
29    *
30    * @var \Drupal\user\UserInterface
31    */
32   protected $adminUser;
33
34   protected function setUp() {
35     parent::setUp();
36
37     // Use the test page as the front page.
38     $this->config('system.site')->set('page.front', '/test-page')->save();
39
40     // Create Full HTML text format.
41     $full_html_format = FilterFormat::create([
42       'format' => 'full_html',
43       'name' => 'Full HTML',
44     ]);
45     $full_html_format->save();
46
47     // Create and log in an administrative user having access to the Full HTML
48     // text format.
49     $this->adminUser = $this->drupalCreateUser([
50       'administer blocks',
51       $full_html_format->getPermissionName(),
52       'access administration pages',
53     ]);
54     $this->drupalLogin($this->adminUser);
55
56     // Define the existing regions.
57     $this->regions = [
58       'header',
59       'sidebar_first',
60       'content',
61       'sidebar_second',
62       'footer',
63     ];
64     $block_storage = $this->container->get('entity_type.manager')->getStorage('block');
65     $blocks = $block_storage->loadByProperties(['theme' => $this->config('system.theme')->get('default')]);
66     foreach ($blocks as $block) {
67       $block->delete();
68     }
69   }
70
71 }