Score:1

How to build core test database?

us flag

Fifteen years writing Drupal code and yet I have never written unit tests. I have recently posted a couple core patches which require tests to be written for them - so good time to learn how to write PHPUnit tests.

I have a test environmnet set up and am able to successfully run core unit tests. I need to extend these tests which I can see is not very difficult; but I need to run against the "test db". I can see core Views test modules like views_test_config and views_test_data which have everything I need - but I cannot enable them (manually so I can verify what my test content is).

Is there a way to get a copy of the D9 default test database that is used for running core (kernel) tests against? Or, alternatively, some way to enable these modules?

Score:1
cn flag

I'm not sure if I understand your question correctly, but there is no "test db" as such other than what your test creates. The core test system installs a minimal Drupal site from scratch (the database URL for this can be set in the phpunit.xml file, a default template of which is in core/phpunit.xml.dist). This is independent of any existing sites, uses the "simpletest" installation profile and is created from scratch every time the test runs.

Your test's ::setUp() method then creates things like test users, content etc in this site.

If you extend the KernelTestBase or the BrowserTestBase class, you will see there is a class property named $requiredModules. If you set this to an array of module names, they will automatically be enabled as part of the setup process.

liquidcms avatar
us flag
Yes, thank you, but i know all this. I know if i add the views test modules to my #requireModules i can use this test data and config (which is what i need) in my tests. But, I want to "look" at that data with the existing test views to see what is there - so that I can write (and debug) my tests accordingly. But, I need a way to manually install those modules to see what it builds out for test data/config. Does this help?
liquidcms avatar
us flag
So yes, i suspected no core test db (although would be helpful), so perhaps worded my question wrong? What i really need is a way to enable the core test modules like views_test_data and views_test_config. Why i am not able to manually install these?
Score:0
us flag

To allow installing test modules you need to set this in your $settings.php:

$settings['extension_discovery_scan_tests'] = TRUE;

[EDIT] - this does allow seeing all the test modules and i can now enabled them - but the test data and view is still not run.. ughh!!

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.