Questions tagged [testing]

Use it for questions about automated Drupal tests.

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

How to test hooks for custom module in PHPUnit kernel tests

I have a custom module file that has one hook: mymodule.module: function mymodule_node_presave(Drupal\Core\Entity\EntityInterface $node) { if (isset($node->original)) { $orig_node = $node-&...
0
votes
0answers
12 views

Why are doctrine annotations not loading for Drupal unit tests?

I’m trying to run the Drupal CMS unit tests. It is using doctrine/annotations:1.8.0. I am seeing many errors similar to: Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The ...
0
votes
0answers
30 views

Guzzle POST HTTPS requests return 403 Forbidden only when called inside PHPUnit tests

On one side I have a remote Drupal 8 (8.8.1) served via HTTPS which has the following endpoint: MODULENAME.get_notify: path: 'MODULENAME/get-notify' defaults: _controller: '\Drupal\MODULENAME\...
1
vote
1answer
18 views

Why can't you assert the response status in a FunctionalJavascript test?

If I do this in a FunctionalJavascript test: $assert_session->statusCodeEquals(200); I get: Behat\Mink\Exception\UnsupportedDriverActionException: Status code is not available from Drupal\...
1
vote
1answer
18 views

Use a custom install profile for Nightwatch tests?

How can you set a custom install profile to run a Nightwatch test in? I am not seeing it in the docs. The definition of the .drupalInstall() command has: commandAsWebserver( `php ./scripts/...
0
votes
1answer
35 views

Can't set a default theme in a FunctionalJavascript test with $defaultTheme class property

Trying multiple ways here to set a default theme to use in FunctionalJavascript tests and it is not working (I am watching them execute in VNC viewer). Bartik always shows. I also tried setting $...
1
vote
0answers
33 views

Why doesn't core pass unit tests out of the box?

I’m on Travis CI, trying to diagnose some issues. In the process I found many unit tests failing. I originally though my module was causing issues, but it turn out that core fails many unit tests all ...
2
votes
1answer
93 views

How can I mock a class during a functional request that is called from within a controller?

I am working on a custom module that from a controller calls Elastic search and returns a search result. I am trying to write a simple Functional Php Unit test just to make sure the results are ...
1
vote
2answers
68 views

How do I configure a Kernel test?

Currently I am able to run the Unit test from the below command C:\Acquia_dev_desktop\LocalInstance\drupal_new_lab\vendor\bin>phpunit -c ../../core/phpunit.xml.dist ../../modules/custom/lse_demo/...
0
votes
0answers
16 views

Testing log out Link with id|title|alt|text “Log out” not found

I would like to test the "Log out" link on a drupal 8 site with Behat. But i'm getting the error: Link with id|title|alt|text "Log out" not found. (Behat\Mink\Exception\ElementNotFoundException) ...
1
vote
2answers
32 views

How do I assert for a link's href AND link text in a functional test?

In a functional test, I can use WebAssert::linkByHrefExists() to check that a link with a specific href exists on the page. And I can use WebAssert::linkExists() to check that a link with a specific ...
1
vote
1answer
42 views

How to test an alter hook in your .module with ModuleHandler service?

I have setup a kernel test to test a function in my module: /** * Implements hook_link_alter(). */ function mymodule_link_alter(&$variables) { // ... code } In my test, I tried: $variables =...
0
votes
0answers
35 views

Behat config on multisite

I have a drupal8 multisite with no default site settings. So my folder structure looks like: sites/Asite/settings.php sites/Bsite/settings.php With a separate database connection in them and none in ...
0
votes
1answer
18 views

How to get a certain header on FunctionalJavascript tests

Since Drupal 9 is around the corner I'm working on puhsing some contrib modules (and a couple of my own) to be Drupal 9 ready. That involves on updating my tests to use replace deprecated code. ...
0
votes
0answers
30 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 ...
0
votes
1answer
94 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
22 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
26 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
48 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
54 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
62 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
39 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
52 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
32 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
52 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
17 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
31 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
16 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
46 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
23 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
67 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
42 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
46 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
162 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
100 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
24 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
148 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
43 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
204 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
137 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
75 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
165 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
504 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
2 3 4 5
8