Stack Exchange Network

Stack Exchange network consists of 174 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
15 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
0answers
24 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
23 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
14 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
22 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
78 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
83 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
41 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
25 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 ...
1
vote
2answers
47 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
37 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 @...
0
votes
1answer
159 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
129 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
24 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 ...
1
vote
0answers
88 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 ...
3
votes
2answers
332 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
14 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
533 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
20 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
132 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
17 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\...
1
vote
1answer
74 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 ...
1
vote
0answers
62 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
18 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 ...
2
votes
1answer
67 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
84 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....
4
votes
1answer
88 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
381 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
33 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()...
0
votes
0answers
69 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
29 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) { ...
0
votes
0answers
35 views

confused with unit testing in Drupal 8

Basically unit testing means giving input and expected output from the function. But in Drupal 8 phpunit has different types of testing unit testing kernel testing functional testing In my ...
0
votes
0answers
30 views

how to add environment specific SIMPLETEST_BASE_URL and SIMPLETEST_DB to phph-unit.xml

I am implementing php-unit testing in my project. In my local instance I am adding SIMPLETEST_BASE_URL and SIMPLETEST_DB values statically. If I push that code to production then its difficult ...
0
votes
0answers
24 views

How I can unit-test hooks implemantions in Drupal 8? [duplicate]

How I can unit-test hooks implemantions in Drupal 8? I am using 1. hook_theme_suggestions_page_alter 2. hook_token_info 3. hook_entiy_presave 4. hook_tokens 5. hook_form_alter 6. ...
0
votes
0answers
41 views

how to unit test for the functionality written in.theme file in Drupal 8? [duplicate]

I want to write phpunit testing the functionality written in.theme file. Is it possible in Drupal 8. If possible how we can achieve this? few logic written in twigs also. but custom theme is not ...
1
vote
1answer
54 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->...
1
vote
1answer
344 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
56 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
18 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
33 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
205 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
59 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
121 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
14 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
110 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
239 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 ...
0
votes
1answer
111 views

How to unit test hook_form_alter implementation code in custom module

How to unit test hook_form_alter implementation code in custom module?
0
votes
1answer
122 views

Configuration variable inside a hook take always the default value in a PHPUnit test

I'm trying to create a Functional test for the dev version of the No Autocomplete module to test that if the configuration is set then an autocomplete attribute=off will be added to the password edit ...
1
vote
2answers
486 views

Call to undefined function t() in an Unit test

I'm trying to test a method from the dev version of the Allow a content type only once (Only One) module that have a t() call inside: <?php namespace Drupal\onlyone\Utility; class ...
2
votes
1answer
51 views

Why does in Drupal 8 there are two different namespaces for test cases?

In Drupal 8 core modules tests are under two different namespaces which maps to two different directories under the module. \Drupal\Tests\<mymodule>\<TestSuiteType> => <mymodule>/...