Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 751 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you import config sync files in a Drupal 8 functional test?

#1
I would like to know how to import config sync files in my functional tests for modules I am testing. For instance, I have some custom content types I would like to test against, and there are a number of files in config/sync that pertain to the node modules that defines the custom content type.

class ArticleControllerTest extends BrowserTestBase {
protected static $modules = ['node', 'dist_source'];
}

At the top of my test I define the modules which do succesfully import, but it doesn't include the config sync settings so none of my custom content types are present. How can I import these into my test environment?
Reply

#2
At the beginning of testing for Drupal 8, I had the same question. After reading some documents and tutorials, I tried and know several methods:

### `$this->configImporter()` helps import the configurations from sync to active

`$this->configImporter()` exits in `Drupal\Tests\ConfigTestTrait`. And the trait has been used in some based test classes, like `BrowserTestBase`.

However, the method doesn't work for me. Because, I used thunder installation profile. The default content exists after the profile installation was completed. Once the `$this->configImporter()` starts to import sync configurations, it encounters errors that some entity types fail to be updated, because the entities already exists.

### Create a testing profile

*(Haven't tried)*

If the Drupal site installed by standard profile, you may try to put the sync configurations into a testing profile. And [Install Profile Generator][1] module may helps you create the testing profile. There is a related issue [#2788777][2] with config and profile

### Put the configurations which depend on module into `config/install` or `config/optional`

*(Work for me)*

Contributed modules always put the config into `config/install` and `config/optional`. Once the module is installed, the configurations will also write into database or active storage. [Documentation - Include default configuration in your Drupal 8 module][3]

When developing configurations in module, [Configuration development][4] helps export the config into `config/install` of the developed module.

If anyone has the same experience, look forward to share with us.

[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

Reply

#3
I do it in my testing base class (`extends BrowserTestBase`) in `setUp()` like this:

// import config from sync
$config_path = '/home/rainer/src/asdent/config/sync';
$config_source = new FileStorage($config_path);
\Drupal::service('config.installer')->installOptionalConfig($config_source);

works great.

It's just like a `drush cim sync`

And provides the production config to my end-2-end automated phpunit tests in gitlab CI.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through