• Development

    Using Data Providers in PHPUnit Tests

    This is the before code, where a single test is run, and each scenario I’m testing could be influenced by the previous scenario (not a good thing, unless that was my goal, which it was not).

    This is the after code, where three tests are run. Unfortunately this takes 3x longer to execute. The upside is that each scenario cannot affect the others and it’s perhaps more readable and easier to add additional scenarios.

     

  • Development

    Testing Cookie Modification in Laravel 8

    If there’s a better way to pass a cookie from one request to another, in a phpunit feature test in Laravel, please let me know! Here’s one way to handle it:

     

  • Development

    Setting Drupal 8 Node Properties with Behat

    The title of this post could also have been “Opening and Closing a Details Element with Behat” or “Clicking Any Element with Behat”.

    The Drupal 8 node add/edit screen has a number properties on the right side of the screen. I wanted to use Behat to click the “Provide a menu link” checkbox. On page load this MENU SETTINGS pane is closed like the others.

    Here’s an example:

    Node add/edit

    The “URL SETTINGS”, “MENU SETTINGS”, actually mask a <details>  element.

    The “MENU SETTINGS” markup looks like this:

    Menu settings markup

    I expected to be able to write a few lines of Behat like this:

    Unfortunately this results in the failure: element not interactable.

    So, I thought I may need to first click to open the MENU SETTINGS pane so that I can see the checkbox before I try to click it. I modified my code to look like this:

    Unfortunately this results in the failure: Link with id|title|alt|text “Menu settings” not found.

    I tried using the edit-menu  id, “MENU SETTINGS” in all caps, etc. but it always resulted in the same “Link with …”

    I realized the click step is only looking for links.

    Solution

    I added a new step definition to my features/bootstrap/FeatureContext.php file:

    I updated my Behat code and found success!