View source
<?php
namespace Drupal\Tests\collapsiblock\Functional;
class GlobalConfigurationTest extends CollapsiblockFunctionalTestBase {
protected $collapsiblockGlobalAdminUser;
protected function setUp() : void {
parent::setUp();
$this->collapsiblockGlobalAdminUser = $this
->drupalCreateUser([
'administer site configuration',
'access administration pages',
]);
}
public function testGlobalConfigForm() {
$this
->drupalLogin($this->collapsiblockGlobalAdminUser);
$this
->drupalGet('admin/config/user-interface/collapsiblock');
$this
->assertSession()
->checkboxChecked('edit-default-action-1');
$this
->assertSession()
->checkboxNotChecked('edit-default-action-2');
$this
->assertSession()
->checkboxNotChecked('edit-default-action-3');
$this
->assertSession()
->checkboxNotChecked('edit-default-action-4');
$this
->assertSession()
->checkboxNotChecked('edit-default-action-5');
$this
->assertSession()
->checkboxNotChecked('active_pages');
$this
->assertSession()
->checkboxChecked('edit-slide-type-1');
$this
->assertSession()
->checkboxNotChecked('edit-slide-type-2');
$this
->assertSession()
->selectExists('slide_speed');
$this
->assertSession()
->optionExists('slide_speed', 50);
$this
->assertSession()
->optionExists('slide_speed', 100);
$this
->assertSession()
->optionExists('slide_speed', 200)
->hasAttribute('selected');
$this
->assertSession()
->optionExists('slide_speed', 300);
$this
->assertSession()
->optionExists('slide_speed', 400);
$this
->assertSession()
->optionExists('slide_speed', 500);
$this
->assertSession()
->optionExists('slide_speed', 700);
$this
->assertSession()
->optionExists('slide_speed', 1000);
$this
->assertSession()
->optionExists('slide_speed', 1300);
$configFormValues = [];
$configFormValues['default_action'] = 2;
$configFormValues['active_pages'] = 1;
$configFormValues['slide_type'] = 2;
$configFormValues['slide_speed'] = 500;
$this
->submitForm($configFormValues, t('Save configuration'));
$this
->assertSession()
->checkboxNotChecked('edit-default-action-1');
$this
->assertSession()
->checkboxChecked('edit-default-action-2');
$this
->assertSession()
->checkboxNotChecked('edit-default-action-3');
$this
->assertSession()
->checkboxNotChecked('edit-default-action-4');
$this
->assertSession()
->checkboxNotChecked('edit-default-action-5');
$this
->assertSession()
->checkboxChecked('active_pages');
$this
->assertSession()
->checkboxNotChecked('edit-slide-type-1');
$this
->assertSession()
->checkboxChecked('edit-slide-type-2');
$this
->assertSession()
->optionExists('slide_speed', 500)
->hasAttribute('selected');
}
public function testGlobalConfigOutput() {
$this
->drupalLogin($this
->getCollapsiblockUnprivilegedUser());
$this
->drupalGet('<front>');
$this
->assertSession()
->responseContains('"collapsiblock":{"active_pages":false,"slide_type":1,"slide_speed":200}');
$this
->setCollapsiblockGlobalSetting(2, 'default_action');
drupal_flush_all_caches();
$this
->drupalGet('<front>');
$this
->assertSession()
->responseContains('"collapsiblock":{"active_pages":false,"slide_type":1,"slide_speed":200}');
$this
->setCollapsiblockGlobalSetting(TRUE, 'active_pages');
drupal_flush_all_caches();
$this
->drupalGet('<front>');
$this
->assertSession()
->responseContains('"collapsiblock":{"active_pages":true,"slide_type":1,"slide_speed":200}');
$this
->setCollapsiblockGlobalSetting(2, 'slide_type');
drupal_flush_all_caches();
$this
->drupalGet('<front>');
$this
->assertSession()
->responseContains('"collapsiblock":{"active_pages":true,"slide_type":2,"slide_speed":200}');
$this
->setCollapsiblockGlobalSetting(500, 'slide_speed');
drupal_flush_all_caches();
$this
->drupalGet('<front>');
$this
->assertSession()
->responseContains('"collapsiblock":{"active_pages":true,"slide_type":2,"slide_speed":500}');
}
}