BlockTestBase.php 1.7 KB

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