Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Questions tagged [testing]

Use it for questions about automated Drupal tests.

Filter by
Sorted by
Tagged with
0
votes
0answers
18 views

Behat and testing paragraphs

I'm using Drupal 8.7.6 and I have almost hundred Behat tests and everything works great. My problem is with more advanced tests which contains paragraphs. I started using ready contexts: https://...
0
votes
0answers
26 views

Kernel testing a function that calls render()

I have a kernel test that is testing the render array method for a table within a controller. In this method I have added a dropbutton for an actions column. For this to display correctly in the ...
0
votes
0answers
17 views

AlreadyInstalledException on running simpletest throught Docker and PhpStorm

Well, I struggle to run simpletest on my PhpStorm. I tried a lot of things but I'm unable to find what I did wrong. I followed thoses tutorial : Running PHPUnit Tests in PhpStorm with Docker ...
1
vote
0answers
24 views

Kernel Test: How can I get an overridden config value from settings.php

In my settings.php file i have a custom configuration that is changed on a per site basis, e.g. $config['brand_id'] = 1 I have a function that will fetch that value, and I am trying to setup a kernel ...
0
votes
0answers
11 views

WebDriverTestBase generated HTML output is missing required libraries

I have a failing functional JS test and it looks like required assets are not being attached to the page. The block I am testing has #attached set with the right information, as the implementation ...
0
votes
0answers
14 views

WebDriverTestBase can't place/see block configuration in an AJAX text

I am writing a functional test that checks the output of a page when a user has a specific cookie. Based on that cookie, I have a block powered by Ajax Block that injects block content personalized ...
0
votes
1answer
27 views

Where do I put configuration files for testing?

Hopefully, this will be a simple question. I am writing a kernel test for a class, called FooConfig, that reads from a configuration file. For the purpose of facilitating this test, I need a ...
0
votes
0answers
9 views

There is any way to mock Drupal\Core\Site\Settings class?

That class is declared as final, so no way to inherit it to create a custom mock. It doesn't implement an interface, so no way to create another class to replace it. To be able to create a mock with ...
3
votes
0answers
44 views

How to know which method is not covered by Unit test?

I want to finish the Unit test for a contrib module and I want to know if there is a way to know the methods that don't have tests, so this way, I can identify the tests I need to implement. Is there ...
0
votes
0answers
34 views

How does will() actually test anything?

I'm beginning to learn about writing tests for Drupal 8 via PHPUnit and am unclear on how the will() method actually serves to test anything. Given this code (derived from examples and tutorials on ...
0
votes
0answers
16 views

How to change where the sqlite database is generated when running tests?

When running tests, I have some .sqlite files and tmp files created in my project root while the test is running. This causes my IDE to go crazy. Is there a way to tell Drupal in phpunit.xml to store ...
1
vote
1answer
50 views

How to write test(s) with specific config to test custom access checks?

I have built a custom module that alters some of the User routes (view, edit, delete) to do 3 things: Forbid account editing, except a user who has 'administer users' permission Forbid account ...
0
votes
0answers
7 views

Simpletest with multiple users to simulate database race condition

There is a race condition in my Drupal module, that can be reproduced like this: User A loads a form User B loads a form User B submits their form User A submits their form Things go wrong at step 4....
0
votes
0answers
29 views

Behavior driven development with Docker

I have a drupal8 site running in docker environment. I want to make some bdd test with Behat. My behat.yml file looks like: default: suites: default: contexts: - FeatureContext ...
0
votes
0answers
24 views

How can I create a user with a term reference field in a Behat test when using the Drush Driver

My Behat test has the following Given statement. (field_regions is a taxonomy reference field) Given users: | name | mail | roles | field_regions | | Joe User | joe@...
1
vote
2answers
56 views

How to make PHPUnit test in a Module?

I'm not very much knowledgeable about making PHPUnit and Drupal testing setup. I am having problems regarding database calls. I tried to setup phpunit test. Inside my module/some_module. I ...
0
votes
0answers
32 views

Unit test for successful install/uninstall of a module

Since I can't find any reliable information despite of heavy googling, I am wondering what's the best practice of testing a successful (error-less) install/uninstall of a module.
-1
votes
1answer
45 views

How to run tests in my contrib module?

I'm writing a contrib module but I can't find the documentation to run the tests - unit and functional. I know that I'm supposed to use PhpUnit, but I can't find examples of PhpUnit configuration ...
0
votes
0answers
18 views

Using Geocoder in a Functional Test

I am writing my first test in Drupal 8's API and for some reason, I am unable to geocode. When I run my code in a controller, it works fine, but when using a test, $addressCollection evaluates to ...
1
vote
1answer
71 views

Test class could not be found, namespace/autodiscovery issue?

I've got the following tests written for /core/modules/migrate_drupal_ui/src/Controller/MigrateController.php with a new test file /core/modules/migrate_drupal_ui/tests/src/Functional/...
1
vote
1answer
41 views

Running functional tests on a non-English site

When creating functional tests (extending BrowserTestBase) for a D8 site, how would I go about changing the default language of the site being temporarily created by BrowserTestBase? I'm trying to ...
1
vote
0answers
125 views

Running functional / browser tests in Docker + Traefik + TLS

Disclaimer: I am new to Drupal/PHP testing. I am getting connectivity issues when running functional tests on my local Drupal 8 environment. My environment consists of a couple of services that I'm ...
1
vote
1answer
86 views

Behat @javascript test can not login user - incorrect username or password message

I am running: Drupal 7 Behat 3.5.0 Selenium 3.5.0 Chrome Driver 73.x Using this test: Feature: User Profile Background: Given users: | name | status | roles | | incomplete | 1 | ...
0
votes
1answer
48 views

Unit test a plugin

I want to add a small unit test to a migrate plugin for a migration I am building. I looked for some examples but did not find much for unit tests of a plugin. I want to run some assertions when the ...
0
votes
1answer
92 views

How do I mock the “file_system” service?

How do I mock the file_system service in PHPUnit? The issue is being reproduced when \Drupal::service('file_system') is executing in the test suite environment. If \Drupal::service('file_system') ...
1
vote
1answer
297 views

Behat test fails, unable to find Username field using @javascript

My Behat test fails as soon as I add @javascript Error: Form field with id|name|label|value|placeholder "Username" not found. When I remove @javascript, test is passed without any error. Given I ...
1
vote
1answer
70 views

How can I get the full content of a PHPUnit test truncated response?

I'm writing a Functional test (extending BrowserTestBase) for a Drupal REST resource. My resource works fine in real life, but the test (running with --verbose and --debug options) throws a server ...
0
votes
1answer
150 views

How to Unit Test Entity Reference Field Value

I have been tasked with writing a Unit Test for a method where I pass in a Node object, modify an Entity Reference field value, and then return a Node object. Since this is a Unit test, I am unsure ...
1
vote
1answer
34 views

Reindex Search API indexes for Behat testing

I tried to use index the newly created contents to be able to test a page, but the problem is most of the times the tests fails, because the indexing process not finished yet until the contents starts ...
0
votes
0answers
45 views

PHPUnit Test to load a page with CSRF Token gives 403

I try to load a page in a BrowserTestBase unit test. The route for that page has a _csrf_token: 'TRUE' setting. The drupalGet() in the Test fails with 403 - forbidden. When I remove the CSRF setting ...
0
votes
0answers
25 views

How can I run functional tests from a custom module to test one specific mult-site instance?

I have tried to do a simple test of a module located on a sub site (Drupal multisite), but when the test looks for the module to activate it, it can not be found, if I move the module from the sub ...
0
votes
3answers
288 views

LoadTest fail due to “chmod(): Operation not permitted”

I downloaded and installed a new Drupal 8 site via Composer. I generated a new module using Drupal Console. I tried running a phpUnit functional test of the newly generated module, and it keeps ...
0
votes
1answer
347 views

How can I mock a service? [closed]

i have this code: /** * Defines a wrapper target around a paragraph bundle's target field. * * @FeedsTarget( * id = "feeds_para_mapper_temp_target", * field_types = { * "...
0
votes
1answer
245 views

PHPUnit Testing when a custom class contains drupal calls and references other classes

Ok, I am brand new to TDD within the Drupal environment but we have been asked to try write tests where possible for our custom and/or utility/support modules. I've managed to write some simple ...
0
votes
1answer
34 views

Memcache interfering with Simpletest

Adding some tests to an older Drupal 7 site and a few of the tests check for the presence or lack thereof of custom cache items. Having this in settings.php seems to interfere with Simpletest using ...
2
votes
3answers
409 views

How to test a code where the config is involved as parameter?

I'm new to OOP concepts, also PHPUnit Testing is new for me. I want to get the configuration in my testcase. XYZFormResult.php namespace Drupal\xyz\XYZFormResult; use Drupal\Core\Config\...
0
votes
1answer
61 views

How do I hook before the user is created in Behat tests?

I have a Behat test where I have a Given user step, and I want to alter some fields (token replacements). Which Behat hook should I use? I know that for Given content, the Behat hook would be @...
1
vote
1answer
583 views

error with phpunit execution: how to set PHP Test class path in phpunit.xml?

I installed the conditional_fields module: the tree is the following: root project - phpunit.xml - web - modules - conditional_fields - tests - src - ...
5
votes
2answers
749 views

SymfonyTestsListener does not exist on PHP Unit Test

When I try to run a unit test I get an error that SymfonyTestsListener does not exist. Am I running this correctly? ../../vendor/bin/phpunit -c phpunit.xml ../modules/custom/my_module/ Class "...
2
votes
1answer
272 views

How do I test a paragraph bundle entity reference with Behat?

I am learning Behat with Drupal 8 and I'm stuck on trying to test a paragraph bundle (field_related_content) which has a title and description field, the title is an entity reference field to content ...
4
votes
2answers
1k views

How to mock a node field value for phpunit?

I'm working on a project where we need to have code coverage using phpunit. I have a method that includes this code: $node = \Drupal::entityTypeManager()->getStorage('node')->load($node_id); ...
0
votes
0answers
22 views

How to hit an endpoint (menu route) with the session intact

I'm trying to hit an endpoint which shows different data when logged in/out. I am trying to write a unit test, but can't seem to figure out how to hit the end point with user context. How can I do ...
1
vote
1answer
732 views

How to shadow a core function used in two different tests files?

I have two tests files with tests that need to shadow the t() function in the Node Revision Delete project, one test file is placed in: tests/src/Unit/Utility/TimeTest.php And the other in: tests/...
0
votes
1answer
61 views

Kernel base test for media view displays is failing with: LogicException: Missing bundle entity, entity type media_type, entity id image

I am trying to test media view displays via a test, which is based on the KernelTestBase class. I have also tried to inherit from Drupal\Tests\media\Kernel\MediaKernelTestBase, but got the same error ...
0
votes
1answer
401 views

PHPUnit Checking file exists failing

I'm using a Kernel test in Drupal to add a new instance of my custom entity. In the postSave() method of my entity, I generate a PDF using TCPDF. In the browser, this all works well and I can see the ...
1
vote
1answer
25 views

Test a settings form that displays a queue

I'm trying to write a test on a settings form. The module uses a queue, and the settings form displays the items in the queue like so: When I extend the test class from WebTestBase I get: Drupal\...
2
votes
2answers
229 views

how to exclude PHPUnit based functional tests from runnning?

I am trying to run only unit test for my custom module. ./vendor/bin/phpunit -c ./web/core ./web/modules/custom/testing_example --testsuite=unit . But I keep getting the following error: There ...
2
votes
1answer
139 views

Mink failing to run JavascriptTestBase tests

I suspect this is more a config issue than anything but struggling to run JavascriptTestBase tests. The error I'm getting is as below: wodby@php.container:/var/www/html $ ./bin/phpunit -v -c ./web/...
2
votes
1answer
98 views

How do I troubleshoot unit tests using xdebug?

I have xdebug in a Vagrant box, based on VDD, set up and working correctly. Breakpoints trigger phpstorm and mostly works just fine. But when I enable the testing module and try to run a single test ...
5
votes
1answer
340 views

Inject service(s) into Drupal unit test?

I am writing a unit test upfront for a service that does not exist yet. Let's just say it is called ResponseFormatter. I want to start adding unit tests for what I expect this service to do. How do I ...