jhedstrom / drupalextension

An integration layer between Behat, Mink Extension, and Drupal.
GNU General Public License v2.0
210 stars 192 forks source link

hook_entity_presave doesn't fire for node when saving in behat tests #485

Closed acha5066 closed 5 years ago

acha5066 commented 6 years ago

Issue

When saving a node manually my xdebug fires for the node entity inside hook_entity_presave. Notice $entity is of type Node.

screen shot 2018-04-18 at 9 51 59 am

When I run my behat test the hook fires but not for the node entity. Only for the user entity. $entity is of type User.

screen shot 2018-04-18 at 10 11 28 am

As a result my behat test fails because the presave hook can't act on the Node entity.

Versions

Drupal version: Drupal 8.5.1

behat composer.json

{
  "require": {
    "drupal/drupal-extension": "~3.0",
    "guzzlehttp/guzzle" : "^6.0@dev"
  },
  "config": {
    "bin-dir": "bin/"
  },
  "require-dev": {
    "bex/behat-screenshot": "^1.2",
    "dmore/behat-chrome-extension": "^1.1"
  }
}

Test

@api
Feature: Football Score Calculation
  In order to calculate the score in a football match accurately
  As a team manager
  I need to assign goals to players in the match.

  Background:
    Given I am logged in as a user with the "Administrator" role

  Scenario: Calculating the number of goals in a football match

    Given I am at "node/add/match"
    And for "title[0][value]" I enter "Dodgeball Championship"
    And I press the "Add new statistic entity" button
    And I wait for AJAX to finish
    And I select the first autocomplete option for "Peter La Fleur" on the "Player" field
    And I select the first autocomplete option for "Goal" on the "Match Event" field
    And I press the "Create statistic entity" button
    And I wait for AJAX to finish
    And I select the first autocomplete option for "Globo Gym" on the "Away Team" field
    And I select the first autocomplete option for "Average Joes" on the "Home Team" field
    And I press the "Save" button
    Then I should see the text "Home Team Score 1"
    And I should see the text "Away Team Score 0"

I repeat the same steps manually and everything works as expected.

jonathanjfshaw commented 5 years ago

Almost certainly this is because the node is not saving, because of something about the interaction between Mink and your form. This extension doesn't do anything that could influence whether a presave hook fires.