BlockTestBase.php 1.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

/**
 * @file
 * Contains \Drupal\block\Tests\BlockTestBase.
 */

namespace Drupal\block\Tests;

use Drupal\simpletest\WebTestBase;

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

  /**
   * Modules to enable.
   *
   * @var array
   */
22
  public static $modules = array('block', 'filter', 'test_page_test');
23
24
25
26
27
28
29
30
31
32
33

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

  /**
   * A test user with administrative privileges.
   *
34
   * @var \Drupal\user\UserInterface
35
36
37
   */
  protected $adminUser;

38
  protected function setUp() {
39
40
41
    parent::setUp();

    // Use the test page as the front page.
42
    \Drupal::config('system.site')->set('page.front', 'test-page')->save();
43
44
45
46
47
48
49
50
51
52
53
54

    // Create Full HTML text format.
    $full_html_format = entity_create('filter_format', array(
      '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',
55
      $full_html_format->getPermissionName(),
56
57
58
59
60
61
62
63
64
65
66
67
      'access administration pages',
    ));
    $this->drupalLogin($this->adminUser);

    // Define the existing regions.
    $this->regions = array(
      'header',
      'sidebar_first',
      'content',
      'sidebar_second',
      'footer',
    );
68
    $block_storage = $this->container->get('entity.manager')->getStorage('block');
69
70
71
72
    $blocks = $block_storage->loadByProperties(array('theme' => \Drupal::config('system.theme')->get('default')));
    foreach ($blocks as $block) {
      $block->delete();
    }
73
74
  }
}