Configuration
DrevOps\BehatSteps\Steps\Drupal\ConfigTrait - Source, Example, Helpers
Assert and set stored Drupal configuration values with automatic revert.
Set a configuration value for test setup and assert that a configuration object's key holds, or contains, an expected value. Nested keys are addressable with dotted notation (for examplepage.front).
2 families of assertions read the value differently:
- The default steps read the stored value, with module and
settings.phpoverrides left unapplied. This is symmetric with the set steps and is what most setup-and-assert scenarios need.- The
effectivesteps read the value with module andsettings.phpoverrides applied: the value the running site uses.
Values are compared by their stringified form, sotrue,42and JSON arrays written in a step match their typed configuration counterparts. Thecontainsteps match a substring for string values and membership for array values, searched recursively.
Configuration objects touched by the set steps are snapshotted on first write and restored after the scenario. An existing object is reset to its original data, and an object that did not exist is deleted.
Skip the revert with@behat-steps-skip:ConfigTrait.Scenario: Assert configured valuesGiven the config "mymodule.settings" with the key "api.endpoint" has the value "https://api.example.com"Then the config "mymodule.settings" with the key "api.endpoint" should have the value "https://api.example.com"And the config "system.site" with the key "name" should have the effective value "My overridden site"
Options
| Option | Type | Default | Tag | Description |
|---|---|---|---|---|
config.enabled | boolean | TRUE | @behat-steps-skip:ConfigTrait | Restore the configuration values a scenario changed once it finishes. |
Steps
@Given the config :name with the key :key has the value :value
Set a stored Drupal configuration value
Given the config "system.site" with the key "page.front" has the value "/node"
@Given the following config values exist:
Set multiple stored Drupal configuration values from a table
Given the following config values exist:
| name | key | value |
| system.site | name | My site |
| mymodule.settings | api.endpoint | https://api.example.com |
| mymodule.settings | roles | ["editor","reviewer"] |
@Then the config :name with the key :key should have the value :value
Assert that a stored configuration value equals an expected value
Then the config "system.site" with the key "name" should have the value "My site"
@Then the config :name with the key :key should not have the value :value
Assert that a stored configuration value does not equal a value
Then the config "system.site" with the key "name" should not have the value "Wrong"
@Then the config :name with the key :key should contain :value
Assert that a stored configuration value contains an expected value
Then the config "system.site" with the key "name" should contain "site"
@Then the config :name with the key :key should not contain :value
Assert that a stored configuration value does not contain a value
Then the config "system.site" with the key "name" should not contain "xyz"
@Then the config :name with the key :key should have the effective value :value
Assert that an effective configuration value equals an expected value
Then the config "system.site" with the key "name" should have the effective value "Overridden"
@Then the config :name with the key :key should not have the effective value :value
Assert that an effective configuration value does not equal a value
Then the config "system.site" with the key "name" should not have the effective value "Wrong"
@Then the config :name with the key :key should contain the effective value :value
Assert that an effective configuration value contains an expected value
Then the config "system.site" with the key "name" should contain the effective value "Over"
@Then the config :name with the key :key should not contain the effective value :value
Assert that an effective configuration value does not contain a value
Then the config "system.site" with the key "name" should not contain the effective value "xyz"