BlockGroupTest.php in Block Group 8
File
tests/src/Functional/BlockGroupTest.php
View source
<?php
namespace Drupal\Tests\blockgroup\Functional;
use Drupal\Component\Utility\Html;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
class BlockGroupTest extends BrowserTestBase {
use StringTranslationTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'block',
'blockgroup',
];
public function testBlockGroupUserAccess() {
$this
->drupalGet('admin/structure/block_group_content');
$this
->assertSession()
->statusCodeEquals(403);
$web_user1 = $this
->drupalCreateUser();
$this
->drupalLogin($web_user1);
$this
->drupalGet('admin/structure/block_group_content');
$this
->assertSession()
->statusCodeEquals(403);
$web_user2 = $this
->drupalCreateUser([
'administer blockgroups',
]);
$this
->drupalLogin($web_user2);
$this
->drupalGet('admin/structure/block_group_content');
$this
->assertSession()
->statusCodeEquals(200);
}
public function testBlockGroupCreation() {
$web_user = $this
->drupalCreateUser([
'administer blockgroups',
]);
$this
->drupalLogin($web_user);
$blockgroup_label = 'group_test';
$blockgroup_machine_name = 'group_test';
$this
->drupalPostForm('/admin/structure/block_group_content/add', [
'label' => $blockgroup_label,
'id' => $blockgroup_machine_name,
], $this
->t('Save'));
$this
->drupalGet('/admin/structure/block_group_content');
$this
->assertSession()
->pageTextContains($blockgroup_machine_name);
$this
->drupalGet('/admin/structure/block_group_content/' . $blockgroup_machine_name);
$this
->assertSession()
->fieldExists('label');
$this
->drupalPostForm('/admin/structure/block_group_content/' . $blockgroup_machine_name . '/delete', [], $this
->t('Delete'));
}
public function testBlockGroupDisplay() {
$this
->drupalLogin($this->rootUser);
$theme = $this
->config('system.theme')
->get('default');
$blockgroup_label = 'TestBlockGroup';
$blockgroup_machine_name = 'block_group_test';
$block_group = [
'label' => $blockgroup_label,
'id' => $blockgroup_machine_name,
];
$this
->drupalPostForm('/admin/structure/block_group_content/add', $block_group, $this
->t('Save'));
$this
->drupalGet('/admin/structure/block_group_content');
$this
->assertSession()
->pageTextContains($blockgroup_machine_name);
$this
->drupalGet("admin/structure/block/list/{$theme}");
$this
->assertSession()
->pageTextContains("Block group: {$blockgroup_label}");
$block_label = 'BlockInBlockGroup';
$block_id = 'block_in_block_group';
$block = [];
$block['id'] = $block_id;
$block['theme'] = $theme;
$block['region'] = $blockgroup_machine_name;
$block['settings[label]'] = $block_label;
$block['settings[label_display]'] = TRUE;
$this
->drupalPostForm('admin/structure/block/add/system_powered_by_block', $block, $this
->t('Save block'));
$this
->assertSession()
->addressEquals("admin/structure/block/list/{$theme}?block-placement=" . Html::getClass($block['id']));
$this
->drupalGet('');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains($block_label);
$group_block_label = 'TheGroupBlock';
$group_block = [];
$group_block['id'] = 'the_group_block';
$group_block['theme'] = $theme;
$group_block['region'] = 'content';
$group_block['settings[label]'] = $group_block_label;
$group_block['settings[label_display]'] = TRUE;
$this
->drupalPostForm("admin/structure/block/add/block_group:{$blockgroup_machine_name}", $group_block, $this
->t('Save block'));
$this
->assertSession()
->addressEquals("admin/structure/block/list/{$theme}?block-placement=" . Html::getClass($group_block['id']));
$this
->drupalGet('');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($block_label);
}
}