Questions tagged [testing]

Use it for questions about automated Drupal tests.

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

How can I check for differences - Local vs Live

I have a fairly large D8 instance with a ton of content and our deployment process does not include automated testing at all. This means that for all of our changes, we literally go through all pages ...
-1
votes
0answers
25 views

“Button with id|name|label|value ”Log in“ not found”

Trying to run some functional JS tests, Anyone know what is up here? Runtime: PHP 7.1.33 Configuration: /app/phpunit.xml Testing Drupal\Tests\commerce_product\FunctionalJavascript\...
0
votes
0answers
20 views

Testing a function which save some configuration - error called set on null

I have a function which does 2-3 things, one of the activity is to save the configuration. function processProps($data) { $config = $this->configFactory->getEditable('mymodule.settings'); $...
0
votes
0answers
11 views

How does Drupal.org test bot work with indexs?

When I upload a patch to a module on d.o I get the following errors across all tests : 1) Drupal\Tests\commerce_pos_keypad\FunctionalJavascript\KeypadTest::testCommercePosForm Error: Call to a ...
0
votes
0answers
23 views

How can I get entity / entity id from current route in a test?

I'm writing a test using Drupal\Tests\BrowserTestBase I try create a node by posting it to the node add form, after I will be redirected to the view page of the new node. Now I want to save the node ...
0
votes
2answers
33 views

Is there a way to mock a procedural function from common.inc in a test without an external library?

I am trying to mock the render() function from common.inc in a test. I am aware that render() could be substituted with a renderer service, but in this specific case I can't/couldn't refactor the ...
2
votes
0answers
46 views

How do I mock a service when using BroswerTestBase? [duplicate]

I am trying to use BrowserTestBase to write a functional test for a Form. The form populates some form elements with data retrieved from an external site. The client for this external site is injected ...
2
votes
1answer
49 views

Mock a service while running a BrowserTest?

I am trying to test the output of a controller that returns some information in a given page. This controller has a custom http client injected into it. I want to create a BrowserTest that can ...
-2
votes
2answers
39 views

How to execute login feature on Chrome browser

Just using Behat with drupal 8 and facing problem with login behat script to run. Below are the my code : behat.yml default: suites: default: contexts: - FeatureContext - ...
0
votes
0answers
36 views

How to test a custom filter on existing view?

I programmatically created a new (custom) filter for the user's view (admin/people). Code for the filter: hook_field_views_data_alter() Plugin > views > filter class The filter works ...
2
votes
2answers
37 views

Unit Testing code that retrieves content

I have a method which calls another one to retrieve a specific node ID. If it can be found, it then retrieves the node. Is this the kind of functionality that can be tested in Drupal? Or even should ...
0
votes
0answers
30 views

Can I clone the current state of a site when running tests?

I would like to prove that a series of permissions defined from a module are applied to certain roles. I need to test it both on a Drupal installation done from scratch and on a Drupal installation ...
1
vote
0answers
43 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
25 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
35 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
16 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
30 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
13 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
45 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
35 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
19 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 ...
0
votes
1answer
53 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
8 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
36 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
41 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
98 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.
0
votes
1answer
79 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
22 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
109 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
42 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
175 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
124 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
64 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
136 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') ...
2
votes
1answer
418 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
79 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
236 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
35 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
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
378 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
442 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
328 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
38 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
525 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
67 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
698 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
956 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
312 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 ...