Questions tagged [testing]

Use it for questions about automated Drupal tests.

Filter by
Sorted by
Tagged with
0 votes
1 answer
52 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
2 votes
1 answer
52 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.7k
1 vote
2 answers
54 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
  • 166
0 votes
0 answers
76 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
130 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,165
0 votes
1 answer
259 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
0 answers
28 views

Can't Place Custom Block in BrowserTestBase

I'm trying to set up a test for my custom module. But I can't seem to place my custom block. I can place system blocks just fine. So I don't know if there's something special with a block I make in my ...
xpersonas's user avatar
  • 522
0 votes
1 answer
38 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
121 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
91 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
0 answers
79 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
65 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
35 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
  • 394
0 votes
0 answers
98 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
252 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
0 votes
0 answers
101 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
414 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
72 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.7k
1 vote
1 answer
23 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.7k
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
350 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
389 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
58 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,821
2 votes
2 answers
134 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,821
0 votes
1 answer
104 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
253 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
153 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,596
0 votes
0 answers
56 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
230 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
35 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
118 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
258 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,622
0 votes
0 answers
69 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
263 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
134 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
296 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
5 votes
2 answers
941 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,165
1 vote
2 answers
99 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,224
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
52 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
192 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
87 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.7k
2 votes
1 answer
163 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
150 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
0 votes
1 answer
39 views

Using attachFileToField in a Functional test doesn't allow entering the alt text for an image

In a Functional test, I am doing: $this->drupalGet('node/add/article'); $page->fillField('title[0][value]', 'Page 1 EN'); $page->pressButton('Add image'); // Using ...
joachim's user avatar
  • 846
1 vote
0 answers
86 views

Code coverage with Functional JS Tests

So I am trying to get the code coverage report to work with my functional JS tests. I have been looking everywhere and trying everything, but I just can not seem to get the report to work, even ...
Eric Bremner's user avatar
2 votes
2 answers
345 views

Basic kernel test fails with Type of Drupal\KernelTests\Core\Entity\EntityKernelTestBase::$modules must be array

Trying to port a Drupal 7 module to 9 with accompanying test and getting this error immediately when running it: PHP Fatal error: Type of Drupal\KernelTests\Core\Entity\EntityKernelTestBase::$modules ...
Kevin's user avatar
  • 27.7k
2 votes
2 answers
506 views

How do I access $this in a dataProvider method?

Is it possible to access $this in a PHPUnit BrowserTestBase data provider method to get access to properties defined in the testBase class? It seems that the sequence of processing during startup of ...
Jonathan1055's user avatar
3 votes
1 answer
1k views

How do I run PHPUnit tests?

Having just kind of gotten my head around Simpletest functional testing in Drupal 8.x, I've now started trying to use PHPUnit testing since Simpletest has been deprecated in Drupal 9.1.x. I started by ...
quant's user avatar
  • 546
1 vote
0 answers
346 views

Kernel test fails with 'Error: Call to undefined function drupal_valid_test_ua()'

My kernel tests are failing with: Error: Call to undefined function drupal_valid_test_ua() /Users/joachim/Sites/drupal-core-composer/repos/drupal/core/tests/Drupal/KernelTests/KernelTestBase.php:273 ...
joachim's user avatar
  • 846

1
2 3 4 5
10