3 namespace Drupal\Tests\views\Kernel\Plugin;
5 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
6 use Drupal\block\Entity\Block;
9 * Tests views block config dependencies functionality.
13 class BlockDependenciesTest extends ViewsKernelTestBase {
16 * Views used by this test.
20 public static $testViews = ['test_exposed_block'];
27 public static $modules = ['node', 'block', 'user', 'field'];
30 * Tests that exposed filter blocks have the correct dependencies.
32 * @see \Drupal\views\Plugin\Derivative\ViewsExposedFilterBlock::getDerivativeDefinitions()
34 public function testExposedBlock() {
35 $block = $this->createBlock('views_exposed_filter_block:test_exposed_block-page_1');
36 $dependencies = $block->calculateDependencies()->getDependencies();
38 'config' => ['views.view.test_exposed_block'],
39 'module' => ['views'],
42 $this->assertIdentical($expected, $dependencies);
46 * Tests that exposed filter blocks have the correct dependencies.
48 * @see \Drupal\views\Plugin\Derivative\ViewsBlock::getDerivativeDefinitions()
50 public function testViewsBlock() {
51 $block = $this->createBlock('views_block:content_recent-block_1');
52 $dependencies = $block->calculateDependencies()->getDependencies();
54 'config' => ['views.view.content_recent'],
55 'module' => ['views'],
58 $this->assertIdentical($expected, $dependencies);
62 * Creates a block instance based on default settings.
64 * @param string $plugin_id
65 * The plugin ID of the block type for this block instance.
66 * @param array $settings
67 * (optional) An associative array of settings for the block entity.
68 * Override the defaults by specifying the key and value in the array, for
71 * $this->createBlock('system_powered_by_block', array(
72 * 'label' => t('Hello, world!'),
75 * The following defaults are provided:
76 * - label: Random string.
77 * - id: Random string.
78 * - region: 'sidebar_first'.
79 * - theme: The default theme.
80 * - visibility: Empty array.
82 * @return \Drupal\block\Entity\Block
85 protected function createBlock($plugin_id, array $settings = []) {
87 'plugin' => $plugin_id,
88 'region' => 'sidebar_first',
89 'id' => strtolower($this->randomMachineName(8)),
90 'theme' => $this->config('system.theme')->get('default'),
91 'label' => $this->randomMachineName(8),
96 foreach (['region', 'id', 'theme', 'plugin', 'weight', 'visibility'] as $key) {
97 $values[$key] = $settings[$key];
98 // Remove extra values that do not belong in the settings array.
99 unset($settings[$key]);
101 foreach ($values['visibility'] as $id => $visibility) {
102 $values['visibility'][$id]['id'] = $id;
104 $values['settings'] = $settings;
105 $block = Block::create($values);