valueCallback example


class PasswordTest extends UnitTestCase {

  /** * @covers ::valueCallback * * @dataProvider providerTestValueCallback */
  public function testValueCallback($expected$input) {
    $element = [];
    $form_state = $this->prophesize(FormStateInterface::class)->reveal();
    $this->assertSame($expected, Password::valueCallback($element$input$form_state));
  }

  /** * Data provider for testValueCallback(). */
  public function providerTestValueCallback() {
    $data = [];
    $data[] = [NULL, FALSE];
    $data[] = [NULL, NULL];
    $data[] = ['', ['test']];
    $data[] = ['test', 'test'];
    

  public static function value($element$input, FormStateInterface $form_state) {
    if ($input) {
      // Checkboxes lose their value when empty.       // If the display field is present make sure its unchecked value is saved.       if (empty($input['display'])) {
        $input['display'] = $element['#display_field'] ? 0 : 1;
      }
    }

    // We depend on the managed file element to handle uploads.     $return = ManagedFile::valueCallback($element$input$form_state);

    // Ensure that all the required properties are returned even if empty.     $return += [
      'fids' => [],
      'display' => 1,
      'description' => '',
    ];

    return $return;
  }

  

class PasswordConfirmTest extends UnitTestCase {

  /** * @covers ::valueCallback * * @dataProvider providerTestValueCallback */
  public function testValueCallback($expected$element$input) {
    $form_state = $this->prophesize(FormStateInterface::class)->reveal();
    $this->assertSame($expected, PasswordConfirm::valueCallback($element$input$form_state));
  }

  /** * Data provider for testValueCallback(). */
  public function providerTestValueCallback() {
    $data = [];
    $data[] = [['pass1' => '', 'pass2' => ''][], NULL];
    $data[] = [['pass1' => '', 'pass2' => '']['#default_value' => ['pass2' => 'value']], NULL];
    $data[] = [['pass2' => 'value', 'pass1' => '']['#default_value' => ['pass2' => 'value']], FALSE];
    $data[] = [['pass1' => '123456', 'pass2' => 'qwerty'][]['pass1' => '123456', 'pass2' => 'qwerty']];
    

class TokenTest extends UnitTestCase {

  /** * @covers ::valueCallback * * @dataProvider providerTestValueCallback */
  public function testValueCallback($expected$input) {
    $element = [];
    $form_state = $this->prophesize(FormStateInterface::class)->reveal();
    $this->assertSame($expected, Token::valueCallback($element$input$form_state));
  }

  /** * Data provider for testValueCallback(). */
  public function providerTestValueCallback() {
    $data = [];
    $data[] = [NULL, FALSE];
    $data[] = [NULL, NULL];
    $data[] = ['', ['test']];
    $data[] = ['test', 'test'];
    

class MachineNameTest extends UnitTestCase {

  /** * @covers ::valueCallback * * @dataProvider providerTestValueCallback */
  public function testValueCallback($expected$input) {
    $element = [];
    $form_state = $this->prophesize(FormStateInterface::class)->reveal();
    $this->assertSame($expected, MachineName::valueCallback($element$input$form_state));
  }

  /** * Data provider for testValueCallback(). */
  public function providerTestValueCallback() {
    $data = [];
    $data[] = [NULL, FALSE];
    $data[] = [NULL, NULL];
    $data[] = ['', ['test']];
    $data[] = ['test', 'test'];
    

class TextareaTest extends UnitTestCase {

  /** * @covers ::valueCallback * * @dataProvider providerTestValueCallback */
  public function testValueCallback($expected$input) {
    $element = [];
    $form_state = $this->prophesize(FormStateInterface::class)->reveal();
    $this->assertSame($expected, Textarea::valueCallback($element$input$form_state));
  }

  /** * Data provider for testValueCallback(). */
  public function providerTestValueCallback() {
    $data = [];
    $data[] = [NULL, FALSE];
    $data[] = [NULL, NULL];
    $data[] = ['', ['test']];
    $data[] = ['test', 'test'];
    

class TextfieldTest extends UnitTestCase {

  /** * @covers ::valueCallback * * @dataProvider providerTestValueCallback */
  public function testValueCallback($expected$input) {
    $element = [];
    $form_state = $this->prophesize(FormStateInterface::class)->reveal();
    $this->assertSame($expected, Textfield::valueCallback($element$input$form_state));
  }

  /** * Data provider for testValueCallback(). */
  public function providerTestValueCallback() {
    $data = [];
    $data[] = [NULL, FALSE];
    $data[] = [NULL, NULL];
    $data[] = ['', ['test']];
    $data[] = ['test', 'test'];
    
Home | Imprint | This part of the site doesn't use cookies.