Questions tagged [testing]

Use it for questions about automated Drupal tests.

Filter by
Sorted by
Tagged with
0
votes
0answers
14 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
33 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
26 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
28 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 ...
-1
votes
0answers
15 views

Failing functional tests on drupalLogin()

I'm getting failures on any functional tests in Drupal 8 using the drupalLogin() function. The error message I get is the following. User tBQjiDPm successfully logged in. Failed asserting that ...
0
votes
0answers
17 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
41 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
73 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
47 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
40 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
64 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
173 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 ...
0
votes
0answers
26 views

PHPUnit version incompatible with PHP 7.0

I'm trying to run unit tests using PHPUnit in a CI/CD setup. The problem is that I'm getting the following error: PHPUnit testing framework version 6 or greater is required when running on PHP 7.0 ...
1
vote
1answer
53 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
72 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
27 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
39 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
211 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
247 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
185 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
31 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
214 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
59 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
477 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 - ...
3
votes
2answers
552 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 "...
0
votes
0answers
27 views

PHPUnit can't discover module in /profiles

As far as I know, the only way to do a Kernel Test is in a module. I would prefer to place my tests in another directory, but is OK for now. So in my Kernel Test, I try to install a custom module ...
2
votes
1answer
212 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
882 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
21 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
692 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
54 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
301 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
22 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
172 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
109 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
93 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
241 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 ...
1
vote
2answers
710 views

Functional test fails with PHPunit on local

Getting following error when running core functional test with PHPUnit: vendor/bin/phpunit -c core/phpunit.xml core/modules/user/tests/src/Functional/AccessRoleUITest.php There was 1 error: 1) ...
0
votes
0answers
44 views

Behat Errors after Upgrade to 8.5.3

We are currently upgrading a site from 8.4.8 to 8.5.3. After doing so and running our Behat tests the Behat tests seem to randomly fail on node create with an array_flip error: Warning: array_flip()...
1
vote
0answers
128 views

PHPUnit Test run Error with ConfigFactory

I'm running an error with the following test I wrote including some config. I don't know if my test is even properly written so any advice in improving that code is welcomed. Since my test is not ...
0
votes
1answer
85 views

How to test an exception have been logged instead of thrown?

I have the following code that throws catch an exption: public function deliverPrintable(array $entities, PrintEngineInterface $print_engine, $force_download = FALSE, $use_default_css = TRUE) { ...
1
vote
1answer
82 views

drupalLogin in functional JavaScript tests passes locally but fails on Drupal.org?

During functional JavaScript testing one can create and login a user by using the following code: $this->testUser = $this->drupalCreateUser(['permission']); $this->drupalLogin($this->...
2
votes
1answer
579 views

Running unit test only for my custom module

Is there any way I can run unit testing only for my modules? I know there is a way to run a specific unit test but I want to run unit test for all tests under certain directory (/modules/custom in my ...
0
votes
1answer
61 views

Should I run tests for the entire core and contributed modules, or only for the codes I wrote? [closed]

I am planning to integrate unit testing in CI/CD. I wonder what would be the good practice for running. Should I run tests for the entire core and contributed modules, or only for the codes I wrote?
0
votes
1answer
19 views

Externally Requesting Browser Test Created URL for Relaxed Replication

I am trying to write a browser test for for a workspace replication via relaxed web services using the multiversion, replication and relaxed modules. For this purpose I set up an external Drupal ...
0
votes
1answer
61 views

The test:run command is missing, but other commands work fine

I installed Drupal Console, put it on my path, ran drupal init, and successfully used Drupal Console to generate a module. Now I want to run tests with drupal test:run, but I get this error. [...
1
vote
1answer
390 views

Error running BrowserTest (Drupal\Core\Config\Schema\SchemaIncompleteException: No schema …)

I am working on a module Rate Limiter and trying to improve the deprecated SimpleTest with BrowserTest. While doing so, I get the following error. C:\Project\Sites\devdesktop\drupal8>.\vendor\bin\...
1
vote
1answer
80 views

Should I translate string inside a Unit test?

I have a Unit test where I need to print a string so I decide to use the t() function to translate it: $this->assertTrue(is_numeric($expected), t('Parameter is numeric.')); But the problem is ...