Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not process empty batches. #284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

idimopoulos
Copy link

Hi @jhedstrom
I have had a weird issue with one of my behat test so before anything, this can be fixed by filtering users anew at https://github.com/jhedstrom/drupalextension/blob/main/src/Drupal/DrupalExtension/Context/RawDrupalContext.php#L266 before we call for the process batch.

I managed to reproduce it in behat by simply creating a basic test

@api
Feature: Ensure user cancellation is not breaking behat.

  Scenario: User cancels the account
    Given users:
      | name | pass |
      | test | test |
    Given I delete the user "test"

What happens, is that the cleanUsers tries to clean users by calling user_cancel. In /core/modules/user/user.module:614 of Drupal, a check occurs for whether the user actually exists and just throws an error that we are trying to delete a user that does not exist.

However, in RawDrupalContext, the ::processCallback is called and the Drupal8 driver just does

public function processBatch() {
    $this->validateDrupalSite();
    $batch =& batch_get();
    $batch['progressive'] = FALSE;
    batch_process();
  }

Because the batch from batch_get is returned empty, the progressive key is added to an empty array and the process is called. Then the batch fails with an error Warning: Undefined array key "sets" in /var/www/html/web/core/includes/form.inc line 925 and the behat test partially succeeds.

As said above, this can be fixed here with this PR, or in RawDrupalContext from drupalextension or in both.

@idimopoulos
Copy link
Author

Please, note, as I forgot to mention, that the dummy step that I created "I delete the user 'test'", simply does a$user->delete() but it is a fake step that represents ANY way that a user can be deleted while the test is running. It can be through the UI by the user themselves (with email verification) - or by an admin, or by some cron operation, or by some spam mechanism, or by any way while the test is running and is outside the scope of the behat API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant