class ConditionPluginBaseTest

Tests Drupal\Core\Condition\ConditionPluginBase.

Attributes

#[CoversClass(ConditionPluginBase::class)] #[Group('Condition')]

Hierarchy

Expanded class hierarchy of ConditionPluginBaseTest

File

core/tests/Drupal/Tests/Core/Condition/ConditionPluginBaseTest.php, line 17

Namespace

Drupal\Tests\Core\Condition
View source
class ConditionPluginBaseTest extends UnitTestCase {
  
  /**
   * Tests that the negate form value is cast to a boolean on validation.
   */
  public function testValidateConfigurationForm(mixed $value, bool $expected) : void {
    $condition = new TestConditionPluginBase([], '', '');
    $form = [];
    $form_state = new FormState();
    $form_state->setValue('negate', $value);
    $condition->validateConfigurationForm($form, $form_state);
    $this->assertSame($expected, $form_state->getValue('negate'));
  }
  
  /**
   * Data provider for testValidateConfigurationForm().
   */
  public static function providerTestValidateConfigurationForm() : \Iterator {
    yield 'unchecked checkbox' => [
      0,
      FALSE,
    ];
    yield 'checked checkbox' => [
      1,
      TRUE,
    ];
    yield 'unchecked checkbox as string' => [
      '0',
      FALSE,
    ];
    yield 'checked checkbox as string' => [
      '1',
      TRUE,
    ];
    yield 'empty string' => [
      '',
      FALSE,
    ];
    yield 'boolean false' => [
      FALSE,
      FALSE,
    ];
    yield 'boolean true' => [
      TRUE,
      TRUE,
    ];
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.