function InputTest::testLiterals

File

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

Class

InputTest
@group Recipe @covers \Drupal\Core\Recipe\InputConfigurator

Namespace

Drupal\KernelTests\Core\Recipe

Code

public function testLiterals() : void {
    $recipe = $this->createRecipe(<<<YAML
name: Literals as input
install:
  - config_test
input:
  capital:
    data_type: string
    description: Your favorite state capital.
    default:
      source: value
      value: Boston
  some_int:
    data_type: integer
    description: This is an integer and should be stored as an integer.
    default:
      source: value
      value: 1234
  some_bool:
    data_type: boolean
    description: This is a boolean and should be stored as a boolean.
    default:
      source: value
      value: false
  some_float:
    data_type: float
    description: Pi is a float, should be stored as a float.
    default:
      source: value
      value: 3.141
config:
  actions:
    config_test.types:
      simpleConfigUpdate:
        int: \${some_int}
        boolean: \${some_bool}
        float: \${some_float}
    system.site:
      simpleConfigUpdate:
        name: '\${capital} rocks!'
        slogan: int is \${some_int}, bool is \${some_bool} and float is \${some_float}
YAML
);
    // Mock a collector that only returns the default value.
    $collector = $this->createMock(InputCollectorInterface::class);
    $collector->expects($this->any())
        ->method('collectValue')
        ->withAnyParameters()
        ->willReturnArgument(2);
    $recipe->input
        ->collectAll($collector);
    RecipeRunner::processRecipe($recipe);
    $config = $this->config('config_test.types');
    $this->assertSame(1234, $config->get('int'));
    $this->assertFalse($config->get('boolean'));
    $this->assertSame(3.141, $config->get('float'));
    $config = $this->config('system.site');
    $this->assertSame("Boston rocks!", $config->get('name'));
    $this->assertSame('int is 1234, bool is  and float is 3.141', $config->get('slogan'));
}

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