function InputTest::testPromptArgumentsAreForwarded

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Recipe/InputTest.php \Drupal\KernelTests\Core\Recipe\InputTest::testPromptArgumentsAreForwarded()

Tests prompt arguments are forwarded.

@legacy-covers \Drupal\Core\Recipe\ConsoleInputCollector::collectValue

File

core/tests/Drupal/KernelTests/Core/Recipe/InputTest.php, line 118

Class

InputTest
Tests Input.

Namespace

Drupal\KernelTests\Core\Recipe

Code

public function testPromptArgumentsAreForwarded() : void {
  $io = $this->createMock(StyleInterface::class);
  $io->expects($this->once())
    ->method('ask')
    ->with('What is the capital of Assyria?', "I don't know that!")
    ->willReturn('<scream>');
  $recipe = $this->createRecipe(<<<YAML
  name: 'Collecting prompt input'
  input:
    capital:
      data_type: string
      description: The capital of a long-defunct country.
      prompt:
        method: ask
        arguments:
          question: What is the capital of Assyria?
          # This argument should be discarded.
          validator: 'test_validator'
      default:
        source: value
        value: "I don't know that!"
  YAML);
  $collector = new ConsoleInputCollector($this->createMock(InputInterface::class), $io);
  $recipe->input
    ->collectAll($collector);
  $this->assertSame([
    'capital' => '<scream>',
  ], $recipe->input
    ->getValues());
}

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