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

namespace Drupal\block\Tests;

5
6
@trigger_error(__NAMESPACE__ . '\BlockTestBase is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\block\Functional\BlockTestBase, see https://www.drupal.org/node/2901823.', E_USER_DEPRECATED);

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

/**
 * Provides setup and helper methods for block module tests.
12
13
14
15
16
 *
 * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
 *   Use \Drupal\Tests\block\Functional\BlockTestBase.
 *
 * @see https://www.drupal.org/node/2901823
17
18
19
20
 */
abstract class BlockTestBase extends WebTestBase {

  /**
21
   * Modules to install.
22
23
24
   *
   * @var array
   */
25
  public static $modules = ['block', 'filter', 'test_page_test', 'help', 'block_test'];
26
27
28
29
30
31
32
33
34
35
36

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

  /**
   * A test user with administrative privileges.
   *
37
   * @var \Drupal\user\UserInterface
38
39
40
   */
  protected $adminUser;

41
  protected function setUp() {
42
43
44
    parent::setUp();

    // Use the test page as the front page.
45
    $this->config('system.site')->set('page.front', '/test-page')->save();
46
47

    // Create Full HTML text format.
48
    $full_html_format = FilterFormat::create([
49
50
      'format' => 'full_html',
      'name' => 'Full HTML',
51
    ]);
52
53
54
55
    $full_html_format->save();

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

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

78
}