Questions tagged [testing]
Use it for questions about automated Drupal tests.
464 questions
0
votes
0
answers
28
views
Is there a way to use the dev versions of other Drupal modules in GitLab CI but stable as the install dependency?
I maintain a couple of contrib modules that are pretty closely linked.
When a user runs composer require drupal/mymodule_with_dependencies, I want them to get stable dependencies for all of the ...
0
votes
1
answer
27
views
How do I test an entity reference dropdown select field in functional tests?
Does anyone have any example or reference to test entity reference dropdown select field in functional tests?
I am trying to test a entity reference dropdown select(Taxonomy Field) field in Node ...
0
votes
1
answer
16
views
How do I test a file field in functional tests
Does anyone have any example or reference to test file field in functional tests?
I am trying to test a file upload field in Taxonomy Entity.
My Field Definition is what in the attached image below.
...
0
votes
0
answers
62
views
How can I set up a site from config or from clean database dump for PHPUnit?
Does anyone have any suggestions or examples on how to set up a Drupal Site from config or from clean database dump (say mysite_dump.sql.gz) for PHPUnit tests?
I don't want to run tests against a ...
1
vote
1
answer
31
views
Kernel module install test failure: FieldException: Field 'uid' on entity type 'file' references a target entity type 'user' which does not exist
I'm trying to add a really simple module install/uninstall test:
<?php
namespace Drupal\Tests\jsonapi_include\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Test installation and ...
1
vote
1
answer
37
views
Unittest for display extender fails at install SchemaIncompleteException: No schema for views.settings
i am trying to write a functional test for my module that ships a views display extender but it already fails at installing my module.
in my module.install file i have these lines that will add my ...
0
votes
1
answer
64
views
How to use GitLab CI to test submodules that have different dependencies than the parent module?
I have created a contrib module that adds an entity type.
I then created a submodule that adds a JSON-RPC endpoint to enable creating entities of the parent module using JSON-RPC.
This submodule ...
2
votes
2
answers
404
views
How do I enable a PHP extension on GitLab CI?
I'm trying to use Drupal.org's GitLab CI to test a module that has a dependency on a package that requires PHP's ext-sodium to be installed:
No composer.lock file present. Updating dependencies to ...
3
votes
1
answer
49
views
How do I write a test for a specific server (nginx) for Drupal.org?
I'm trying to write a test for Only show the error “Public files directory Not fully protected” for Apache servers. This is a bug that only appears if running Drupal on nginx, not Apache.
Normally, ...
0
votes
1
answer
82
views
Contrib module phpstan on Gitlab CI: How to make dependency modules available?
I have a module Decoupled Passkeys that adds JSON-RPC module endpoints, so it depends on JSON-RPC.
When I run tests with a custom phpstan.neon, I'm getting a lot of errors because phpstan cannot find ...
0
votes
0
answers
35
views
Functional test of A11y features
Who has any experience with testing A11y features? I need to test focus and tabulation via keyboard.
How it works now in the browser:
Go via the tab key to link "Show more"
Press enter
Some ...
3
votes
1
answer
213
views
How do I set the PHP version for a contrib module with GitLab CI?
I'm trying to set up testing using the GitLab template for contrib modules.
In the module's composer.json, PHP 8.2 is required, and since the CI is currently defaulting to 8.1, the install fails.
So, ...
1
vote
1
answer
341
views
PhpUnit 9.6.16 with Drupal 10.2 unable to write to output directory: How to fix that error?
I have multiple sites running Drupal 10.1.7, all are using custom modules with appropriate functional tests. The tests are running fine.
Now, I wanted to update the sites to Drupal 10.2.2. This update ...
0
votes
0
answers
44
views
Kernel and functional testing with an MSSQL database
I am new to testing custom modules. My custom modules create and update custom nodes. From my reading, I need to use Kernel or Functional tests to test these operations. My Drupal 9 installation is ...
0
votes
1
answer
414
views
Configuring dynamic PHPUnit environment variables
Current State:
I'm currently working on running PHPUnit Browser tests in Drupal, and I've successfully configured my phpunit.xml file with these environment variables:
<env name="...
3
votes
1
answer
91
views
Drupal unable to login and logout several accounts in a single functional test
I am trying to run some functional tests in DDEV that check functions of protected routes. I can log in the first couple of users fine, but after that drupaLogin() fails to generate a logged in ...
1
vote
2
answers
124
views
functional test: Schema errors but Schema is correct
I have a settings form in my custom module and functional test of this form.
I added new field to form
$form['unblockable_roles'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Users ...
0
votes
1
answer
375
views
Kernel test throws errors: field not found, and Base table or view not found:
Here's the class I want to test:
class Thing {
public function foo() {
return \Drupal::entityQuery('node')->condition('body', 'blah')->execute();
}
}
And the test:
class ...
0
votes
1
answer
563
views
Mink unable to connect to chromedriver
I need help from someone who knows about testing web pages with Javascript in Docker containers. I have browser-based testing working and now I have scenarios which don't work without Javascript, so I'...
0
votes
1
answer
51
views
Browser test reports assertion success as an error
I am running a Functional test in a class derived from BrowserTestBase. Line 105 of the test method has this assertion:
$this->assertSession()->linkExists('10000003');
The test output says:
...
0
votes
1
answer
195
views
How to get web server error logging output from phpunit functional tests?
The 500 errors generated during phpunit tests aren't showing up in the Apache error logs. Where are those errors logged?
0
votes
1
answer
141
views
phpunit can't find node permissions
We have a Functional test class derived from BrowserTestBase which is passing, but the output includes a deprecation notice.
Adding non-existent permissions to a role is deprecated in drupal:9.3.0 ...
5
votes
1
answer
140
views
How do I import a sync config file into my Kernel unit test?
How do I import a sync config file into my Kernel unit test ?
Specifically, I have some REST resources in files
config/sync/rest.resource.foo.yml,config/sync/rest.resource.bar.yml
At present, when I ...
1
vote
1
answer
89
views
How can I use Url::fromRoute() in a test?
If I crate the class for test like:
class ReturnHandlerTest extends OrderKernelTestBase {
protected static $modules = [
'commerce_payment',
'commerce_payment_example',
];
protected ...
0
votes
0
answers
39
views
How do I test managed files upload through configuration?
I have a configuration form in Drupal9 which extend ConfigFormBase that I need to pass through Behat test.
To simplify the form, I have only one managed_file fields.
$form['card_logo_fid'] = [
'#...
0
votes
0
answers
127
views
Nightwatch not executing in Acquia pipeline
I'm trying to execute the Nightwatch test on Acquia pipeline for every PR raised
I have created a custom BLT command that executes the test cases of Nightwatch. it is executing fine locally but it ...
2
votes
1
answer
461
views
Testing Drush Commands
How to test custom implemented Drush Commands ? Are there any Open Source Examples for Drush Commands with Unit Tests or something like that ?
1
vote
0
answers
151
views
How do I update the database prior to running a PHPUnit Kernel test?
I've set up the a PHPUnit test environment and configured SIMPLETEST_DB. I have also created the following function to update a value in this database. This public function lives outside the test ...
2
votes
1
answer
618
views
How to enable a module on a ResourceTest?
I'm running a functional test that extends the ResourceTestBase however it is throwing the following error:
ServiceNotFoundException: The service "cache_tags.invalidator.checksum" has a ...
1
vote
1
answer
87
views
Debugging hook_node_access in failing test
Related to this question, I have a functional test asserting that hook_node_access is doing what it should for different users.
While I can access edit and delete routes, I add an additional check for ...
1
vote
1
answer
41
views
Easy way to add Functional or Kernel tests to a View?
I have an administrative View that has a couple access checks based on current user. I would like to add an automated test to the view.
Since I only need to check the result count (no specific field) ...
1
vote
1
answer
2k
views
How to avoid "Access to an undefined property" with text field format in PHPStan?
I have a text field that I am setting inside an entity bundle.
protected function doSomethingAwesome(string $value): void {
$this->set('field_text', $value);
$this->field_text->...
3
votes
1
answer
515
views
Faster phpunit-bootstraping for single Unit-Tests
My team and I started on Drupal some months ago. As we began creating our own modules, I also wanted to test them, but was very annoyed by the Performance of the tests - or better: of the Performance ...
0
votes
1
answer
607
views
How do I test a CKEditor 5 text format field with Behat/Mink?
Drupal 10 is switching from CKEditor 4 to 5.
So, I installed the experimental CKEditor 5 module and am attempting to update my Behat tests to use CKEditor 5.
I am using an @javascript test in Behat on ...
1
vote
1
answer
79
views
How can I load a migration in a KernelTest?
I'm trying to test a migration with a KernelTest, but I'm running into an issue when I try to load the migration plugin.
My migration is defined in my_module/migrations/my_migration.yml. In my ...
2
votes
2
answers
146
views
Where can I find the Annotation(s) for test classes? [closed]
I've seen lots of examples of tests like:
/**
* My test description.
*
* @group mymodule
*/
class MyModuleTest extends KernelTestBase { }
I know what @group mymodule is and how that annotation ...
0
votes
1
answer
138
views
I can't debug a functional test for a custom module
I am trying to debug the functional tests for my custom module.
When I run the debugger, it doesn't hit the breakpoint I've set on the first line of the test method. However, when I debug a functional ...
1
vote
1
answer
385
views
Functional Testing - Schema Incomplete Exception missing schema
I am working on my first functional test for a custom module. Each time I run the functional test I get errors dealing with configuration schema issues. However, I'm confused by the error message.
...
0
votes
1
answer
244
views
Running tests for a module without requiring a full site installation
I'm building a custom module (for use on multiple projects) with code that relies on stuff from Drupal core and third party modules (e.g. extending classes, implementing interfaces, annotating as ...
0
votes
0
answers
63
views
Mock user with fields to use in a functional test
How is it possible to mock a user with some simple text fields (for example, First name and Last name) in a functional test (which extends BrowserTestBase) without creating the configuration for this ...
2
votes
0
answers
282
views
How to create functional tests for testing REST requests that the site has? [closed]
I'm trying to understand how to create tests for REST Endpoint that a custom module creates.
I managed to create a Unit Test for the Get method of the Rest-resource and now I want to create a ...
1
vote
0
answers
52
views
How can I identify if my code needs a Unit test a Kernel test or a browser test? [closed]
In my project we extend base classes. BlockBase, ControllerBase, FormBase, FormatterBase and so on to build blocks, Fieldformatters, forms ...
We already have automated tests (functional) using a ...
0
votes
0
answers
141
views
Functional test for emails (subject and title)
Question: How can a Drupal Functional Test (extenting BrowserTestBase) check for a certain Mail-Subject and Mail-Body defined in hook_mail in a custom module ?
Context:
I have a custom module which ...
1
vote
1
answer
347
views
Autoload helper classes in tests/src/ for phpunit in contrib module
I am working on a contrib module with phpunit tests.
Currently there is no composer.json or phpunit.xml or installation routine in the module itself, instead one has to run the functional and browser ...
0
votes
0
answers
77
views
CKEditor hides from my testing tool
I am building an automated testing tool for the drupal site that I maintain. The site has migrated to D9 and functions normally for a human user. When my python scripts pull up selenium/Chrome ...
0
votes
1
answer
481
views
Debugging functional tests with phpunit just hang unless I toggle "stop/start listenting for php debug connections"
Trying to get tests up and running by following https://www.previousnext.com.au/blog/running-and-debugging-phpunit-tests-phpstorm-ddev-and-xdebug. Seems to work, except having an issue with functional ...
3
votes
1
answer
206
views
Can you install exported site config as part of a kernel test?
I am using the Configuration Sync module to export config specific to my site out into a config directory that lives outside my main Drupal directory.
When writing kernel tests I know that you can use ...
1
vote
1
answer
426
views
How do I mock \Drupal::httpClient()?
I'm unit testing a utility library (of our own making) that makes calls to an external REST API with \Drupal::httpClient()
So, I have a library class with static functions:
class myUtils {
public ...
6
votes
2
answers
1k
views
PHPUnit throws error: \Drupal\Tests\DocumentElement class not found
I have added some phpunit tests to my custom module. When trying to run them in I get this error: Class '\Drupal\Tests\DocumentElement' not found I have copied core/phpunit.xml.dist to core/phpunit....
1
vote
2
answers
228
views
How to build core test database?
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 ...