Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [testing]

Use it for questions about automated Drupal tests.

1
vote
1answer
37 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
40 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
47 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
32 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
33 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
50 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
101 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
22 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
38 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
50 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
34 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
164 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 ...
1
vote
1answer
178 views

How can I mock a service?

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
123 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
121 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
54 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
424 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
401 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
145 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
733 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
18 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
635 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
40 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
255 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
21 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
137 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
91 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/...
0
votes
0answers
26 views

Unit testing submodule with factory class

Let's say I have factory class A and a object class B. A has a static method to create an instance of some other object in my main module while B directly calls that method in A and uses the object ...
3
votes
1answer
83 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 ...
0
votes
0answers
122 views

How to navigate to an external URL (Drupal mobile site) in Behat / Selenium?

I need to write a Behat test such that when I click on a link whose href is the URL to the mobile version of the same site, I should be able to navigate to it seamlessly. <a href="https://m.e....
5
votes
1answer
177 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
1answer
584 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
42 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
103 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
69 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
68 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
515 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
59 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
53 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
332 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
74 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 ...
1
vote
1answer
174 views

Concatenating translatable strings is not allowed, use placeholders instead and only one string literal

The following code: $report .= '<p>' . t('<strong>%percentage</strong> of <strong><em>'.$node_type_get_types[$type]->name.'</em></strong> completed.', ...
0
votes
1answer
21 views

Hide/Remove core simpleTests in Drupal 7

I would like to remove the core tests that show up when I activate the Testing (simpletest) module. I have created my own tests for custom modules and I would like those to be the only testing options ...
1
vote
1answer
170 views

How to create a test configuration that can called in a test class?

I am attempting to write a unit test by extending UnitTestCase. Below is how my code works, but I need a way to create a test (or mock) configuration that can be used to satisfy the testing. How can ...
1
vote
2answers
309 views

Behat, Selenium and Chromedriver CI errors

I am working on a Behat setup with Selenium and Chromedriver for running Behat tests for a Drupal 7 setup. I am getting: exception ‘WebDriver\Exception\UnknownError’ with message 'Timed out waiting ...