BlockTestBase.php 1.68 KB
Newer Older
1
2
3
4
5
<?php

namespace Drupal\block\Tests;

use Drupal\simpletest\WebTestBase;
6
use Drupal\filter\Entity\FilterFormat;
7
8
9
10
11
12
13

/**
 * Provides setup and helper methods for block module tests.
 */
abstract class BlockTestBase extends WebTestBase {

  /**
14
   * Modules to install.
15
16
17
   *
   * @var array
   */
18
  public static $modules = array('block', 'filter', 'test_page_test', 'help', 'block_test');
19
20
21
22
23
24
25
26
27
28
29

  /**
   * A list of theme regions to test.
   *
   * @var array
   */
  protected $regions;

  /**
   * A test user with administrative privileges.
   *
30
   * @var \Drupal\user\UserInterface
31
32
33
   */
  protected $adminUser;

34
  protected function setUp() {
35
36
37
    parent::setUp();

    // 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(array(
42
43
44
45
46
47
48
49
50
      'format' => 'full_html',
      'name' => 'Full HTML',
    ));
    $full_html_format->save();

    // Create and log in an administrative user having access to the Full HTML
    // text format.
    $this->adminUser = $this->drupalCreateUser(array(
      'administer blocks',
51
      $full_html_format->getPermissionName(),
52
53
54
55
56
57
58
59
60
61
62
63
      'access administration pages',
    ));
    $this->drupalLogin($this->adminUser);

    // Define the existing regions.
    $this->regions = array(
      'header',
      'sidebar_first',
      'content',
      'sidebar_second',
      'footer',
    );
64
    $block_storage = $this->container->get('entity_type.manager')->getStorage('block');
65
    $blocks = $block_storage->loadByProperties(array('theme' => $this->config('system.theme')->get('default')));
66
67
68
    foreach ($blocks as $block) {
      $block->delete();
    }
69
70
  }
}