Skip to content
Snippets Groups Projects
Commit 65bc9e7f authored by danielveza's avatar danielveza Committed by Chris Snyder
Browse files

Issue #3262406 by DanielVeza, larowlan, chrissnyder: Unticking the 'limit to...

Issue #3262406 by DanielVeza, larowlan, chrissnyder: Unticking the 'limit to pages' checkbox doesn't work until you empty the 'pages' textarea
parent 90611e17
Branches
Tags
1 merge request!17Issue #3262406: Unticking the 'limit to pages' checkbox doesn't work until you empty the 'pages' textarea
......@@ -218,7 +218,7 @@ class SitewideAlertForm extends ContentEntityForm {
}
// Clear any previously set limit by pages if the option to limit them is not set.
if (!$form_state->isValueEmpty('limit_alert_by_pages') && !$form_state->getValue('limit_alert_by_pages')) {
if ($form_state->isValueEmpty('limit_alert_by_pages') && !$form_state->getValue('limit_alert_by_pages')) {
$entity->set('limit_to_pages', '');
}
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\sitewide_alert\Functional;
use Drupal\Component\Utility\Random;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\sitewide_alert\Entity\SitewideAlert;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\sitewide_alert\Traits\SitewideAlertTestTrait;
/**
* Defines a class for testing sitewide alerts.
*
* @group sitewide_alert
*/
final class SitewideAlertLimitTest extends BrowserTestBase {
use SitewideAlertTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'sitewide_alert',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests the limit pages functionality.
*/
public function testAlertLimitPageVisibilityForm(): void {
$random = $this->getRandomGenerator();
$sentences = $random->sentences(10);
$user = $this->createUser([], NULL, TRUE);
$this->drupalLogin($user);
// Create the initial alert.
$alert = $this->createSiteWideAlert([
'message' => [
'value' => $sentences,
],
'limit_to_pages' => '/user/*'
]);
$this->drupalLogin($user);
// Untick the limit field.
$url = Url::fromRoute('entity.sitewide_alert.edit_form', ['sitewide_alert' => $alert->id()])->toString();
$this->drupalGet($url);
$this->submitForm(['limit_alert_by_pages' => FALSE], 'Save');
$alert = SitewideAlert::load($alert->id());
$this->assertEmpty($alert->get('limit_to_pages')->getValue());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment