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
25 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 | ...
-1
votes
0answers
21 views

Testing content types on a site without having to create nodes

I have a bunch of Drupal sites on Drupal 8. My task is to test as a support admin of the site to check if the creation of nodes is possible. And if possible to actually create the nodes to prove it by ...
-1
votes
0answers
21 views

Nightwatch or Behat for simple CI

I'm looking to add simple automated testing to a Drupal 8 + Commerce site I develop locally on Lando, and have a staging and production server. The testing I need to do (at least at the get-go) is ...
0
votes
0answers
22 views

Error trying to run unit tests

Hi I am trying to run a unit test , ../../vendor/phpunit/phpunit/phpunit --group ban I get: PHP Fatal error: Class 'Drupal\Tests\schema_web_page\Functional\SchemaWebPageTest' not found in /opt/...
0
votes
0answers
22 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
33 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
68 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
13 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
23 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
30 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
24 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
23 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
126 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
117 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
64 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
30 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
65 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
48 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
358 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
263 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 ...
2
votes
1answer
118 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
540 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
17 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
584 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
28 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
202 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
20 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
107 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
0answers
78 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
19 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
78 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
111 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
126 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
498 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
37 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
82 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
44 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
36 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
36 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
64 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
57 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
437 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
58 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
41 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
268 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
67 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
148 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.', ...