Unverified Commit 7e79d8d3 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #3559632 Recipe input default value needs to be a string value

By: jurgenhaas
By: phenaproxima
By: godotislate
(cherry picked from commit 98172e7a)
parent 4b4e574e
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -105,6 +105,12 @@ public function collectValue(string $name, DataDefinitionInterface $definition,
    // input definitions should define constraints.
    unset($arguments['validator']);

    // \Symfony\Component\Console\Style\StyleInterface::ask expects the default
    // value to be a string or NULL. Therefore, let's cast it to a string if
    // necessary.
    if (isset($arguments['default']) && !is_string($arguments['default']) && $method === 'ask') {
      $arguments['default'] = (string) $arguments['default'];
    }
    return $this->io->$method(...$arguments);
  }

+23 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
use Drupal\Core\Recipe\InputConfigurator;
use Drupal\Core\Recipe\Recipe;
use Drupal\Core\Recipe\RecipeRunner;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\DataDefinitionInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait;
@@ -440,4 +441,26 @@ public function testFallbackValueForUndefinedEnvironmentVariable(): void {
    $recipe->input->collectAll($collector);
  }

  /**
   * Tests that the ask prompt for integer value doesn't fail with an error.
   */
  public function testAskPromptArgumentsInteger(): void {
    $input = $this->createMock(InputInterface::class);
    $io = $this->createMock(StyleInterface::class);
    $io->expects($this->once())
      ->method('ask')
      ->with('Who are you?', '123', NULL);

    $data_definition = DataDefinition::create('string')
      ->setSetting('prompt', [
        'method' => 'ask',
        'arguments' => [
          'question' => 'Who are you?',
        ],
      ]);

    (new ConsoleInputCollector($input, $io))
      ->collectValue('test.one', $data_definition, 123);
  }

}