Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [testing]

Use it for questions about automated Drupal tests.

Filter by
Sorted by
Tagged with
2 votes
2 answers
162 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 ...
Patrick Kenny's user avatar
3 votes
1 answer
37 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, ...
Patrick Kenny's user avatar
0 votes
1 answer
32 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 ...
Patrick Kenny's user avatar
0 votes
0 answers
31 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 ...
Vanish's user avatar
  • 146
3 votes
1 answer
95 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, ...
Patrick Kenny's user avatar
0 votes
1 answer
129 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 ...
Paul's user avatar
  • 1,203
0 votes
0 answers
23 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 ...
spacecraft96's user avatar
0 votes
1 answer
148 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="...
Marwen Amri's user avatar
3 votes
1 answer
65 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 ...
Kevin's user avatar
  • 27.9k
1 vote
2 answers
72 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 ...
Vanish's user avatar
  • 146
0 votes
0 answers
102 views

Kernel Test: Error: Call to a member function get() on null

It's my first time with kernel tests. I'm working with this test: <?php namespace Drupal\Tests\info_irpf_calculator\Kernel; use Drupal\info_irpf_calculator\Model\IrpfUserData; use Drupal\...
Oskar Calvo's user avatar
0 votes
1 answer
215 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 ...
naomi's user avatar
  • 1,235
0 votes
1 answer
390 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'...
Bob Kline's user avatar
  • 187
0 votes
1 answer
43 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: ...
Bob Kline's user avatar
  • 187
0 votes
1 answer
158 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?
Bob Kline's user avatar
  • 187
0 votes
1 answer
107 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 ...
Bob Kline's user avatar
  • 187
5 votes
1 answer
109 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 ...
Monkeybrain's user avatar
1 vote
1 answer
83 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 ...
sk DYLAN's user avatar
0 votes
0 answers
37 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'] = [ '#...
Denis K's user avatar
  • 404
0 votes
0 answers
113 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 ...
Jaswin Singh's user avatar
2 votes
1 answer
355 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 ?
Bernhard Zürn's user avatar
1 vote
0 answers
113 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 ...
Free Radical's user avatar
  • 15.1k
2 votes
1 answer
516 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 ...
Rick's user avatar
  • 41
1 vote
1 answer
77 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 ...
Kevin's user avatar
  • 27.9k
1 vote
1 answer
25 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) ...
Kevin's user avatar
  • 27.9k
1 vote
1 answer
1k 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->...
Patrick Kenny's user avatar
3 votes
1 answer
422 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 ...
mullzk's user avatar
  • 65
0 votes
1 answer
487 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 ...
Patrick Kenny's user avatar
1 vote
1 answer
68 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 ...
sonfd's user avatar
  • 7,921
2 votes
2 answers
142 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 ...
sonfd's user avatar
  • 7,921
0 votes
1 answer
128 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 ...
FatGuyLaughing's user avatar
1 vote
1 answer
312 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. ...
FatGuyLaughing's user avatar
0 votes
1 answer
190 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 ...
Joseph's user avatar
  • 1,598
0 votes
0 answers
61 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 ...
Bernhard Zürn's user avatar
2 votes
0 answers
263 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 ...
Yakimkin Roman's user avatar
1 vote
0 answers
36 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 ...
Margarita's user avatar
0 votes
0 answers
132 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 ...
Bernhard Zürn's user avatar
1 vote
1 answer
295 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 ...
donquixote's user avatar
  • 3,642
0 votes
0 answers
76 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 ...
DeveloperWeeks's user avatar
0 votes
1 answer
360 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 ...
Mrweiner's user avatar
  • 1,921
3 votes
1 answer
169 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 ...
Jimmyb_1991's user avatar
1 vote
1 answer
363 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 ...
Carsten Agger's user avatar
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....
naomi's user avatar
  • 1,235
1 vote
2 answers
155 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 ...
liquidcms's user avatar
  • 1,278
1 vote
1 answer
1k views

PHPUNIT is running successfully on local but giving error on acquia-pipleine

When I am running the .vendor/bin/phpunit it is not giving any error. o/p: Testing . 1 / 1 (100%) Time: 00:00.014, Memory: 14.00 MB OK ...
Kuntal Das's user avatar
0 votes
1 answer
61 views

Mocking the response of XmlResponse::getResultCode not working

Following is the code that I'm using to mock the response of XmlResponse::getResultCode as Ok, but it isn't working, I'm not sure what exactly is going wrong here: $response = $this->...
Rishi Kulshreshtha's user avatar
1 vote
1 answer
258 views

Missing module error while running unit test

I am trying to run a unit test for one of my contributed modules in my local development environment. But it keeps throwing an error: $:/path/to/web$ sudo -u www-data -E phpunit -c core/phpunit.xml ...
Pratip Ghosh's user avatar
1 vote
0 answers
94 views

How to kernel test a custom formatter for an entity reference field type?

We have a custom field formatter for a string and an entity reference field type. While this works for testing the string field: $node = $this->createNode(['type' => 'page', 'field_id' => '...
Kevin's user avatar
  • 27.9k
2 votes
1 answer
184 views

How can I capture Watchdog output during a functional test?

I have a functional test that is failing, and I think that there could be some useful information in the database log, but unfortunately the test suite only runs in containers on GitLab CI so I don't ...
GuyPaddock's user avatar
1 vote
0 answers
154 views

In testing, how do I get an attribute using XPath?

In Drupal BrowserTestBase, I am trying to access an attribute value using XPath: $query = $this->xpath('//a[text() = "View"]/@data-drupal-link-system-path'); I can't figure out any way ...
Liam Morland's user avatar

1
2 3 4 5
10