BlockInstanceTest.php in Collapsiblock 4.x
File
tests/src/Functional/BlockInstanceTest.php
View source
<?php
namespace Drupal\Tests\collapsiblock\Functional;
class BlockInstanceTest extends CollapsiblockFunctionalTestBase {
protected $collapsiblockBlockAdminUser;
protected $collapsiblockTestBlock;
public function setUp() : void {
parent::setUp();
$this->collapsiblockBlockAdminUser = $this
->drupalCreateUser([
'administer blocks',
'access administration pages',
]);
$this->collapsiblockTestBlock = $this
->drupalPlaceBlock('system_powered_by_block');
}
public function testBlockInstanceConfigForm() {
$this
->drupalLogin($this->collapsiblockBlockAdminUser);
$testBlockEditUrl = $this->collapsiblockTestBlock
->toUrl('edit-form');
$this
->drupalGet($testBlockEditUrl);
$this
->assertSession()
->checkboxChecked('edit-collapsiblock-settings-collapse-action-0');
$this
->assertSession()
->checkboxNotChecked('edit-collapsiblock-settings-collapse-action-1');
$this
->assertSession()
->checkboxNotChecked('edit-collapsiblock-settings-collapse-action-2');
$this
->assertSession()
->checkboxNotChecked('edit-collapsiblock-settings-collapse-action-3');
$this
->assertSession()
->checkboxNotChecked('edit-collapsiblock-settings-collapse-action-4');
$this
->assertSession()
->checkboxNotChecked('edit-collapsiblock-settings-collapse-action-5');
$configFormValues = [];
$configFormValues['collapsiblock_settings[collapse_action]'] = 2;
$this
->submitForm($configFormValues, t('Save block'));
$this
->drupalGet($testBlockEditUrl);
$this
->assertSession()
->checkboxNotChecked('edit-collapsiblock-settings-collapse-action-0');
$this
->assertSession()
->checkboxNotChecked('edit-collapsiblock-settings-collapse-action-1');
$this
->assertSession()
->checkboxChecked('edit-collapsiblock-settings-collapse-action-2');
$this
->assertSession()
->checkboxNotChecked('edit-collapsiblock-settings-collapse-action-3');
$this
->assertSession()
->checkboxNotChecked('edit-collapsiblock-settings-collapse-action-4');
$this
->assertSession()
->checkboxNotChecked('edit-collapsiblock-settings-collapse-action-5');
}
public function testBlockInstanceConfigOutput() {
$this
->drupalLogin($this
->getCollapsiblockUnprivilegedUser());
$testBlockHtmlId = 'collapsiblock-wrapper-' . $this->collapsiblockTestBlock
->id();
$this
->setCollapsiblockBlockInstanceSetting($this->collapsiblockTestBlock, 0, 'collapse_action');
$this
->setCollapsiblockGlobalSetting(2, 'default_action');
drupal_flush_all_caches();
$this
->drupalGet('<front>');
$this
->assertSession()
->responseContains('<div id="' . $testBlockHtmlId . '" class="collapsiblock" data-collapsiblock-action="2" data-once="collapsiblock">');
$this
->setCollapsiblockBlockInstanceSetting($this->collapsiblockTestBlock, 3, 'collapse_action');
drupal_flush_all_caches();
$this
->drupalGet('<front>');
$this
->assertSession()
->responseContains('<div id="' . $testBlockHtmlId . '" class="collapsiblock" data-collapsiblock-action="3" data-once="collapsiblock">');
}
}