Drupal

eiriksm.dev: Creating a Behat step definition with arguments over multiple lines

Planet Drupal - 21 February 2020 - 1:39pm

Here is a quick tip if you want to create a step definition that has an argument with multiple lines. A multiline string argument if you like.

I wanted to test that an email was sent, with a specific subject, to a specific person, and containing a specific body text.

My idea was to create a step definition that looked something like this:

Then an email has been sent to "user@example.com" with the subject "Subject example" and the body “one of the lines in the body plus this is the other line of the body, after an additional line break”

So basically my full file is now this:

@api @test-feature Feature: Test this feature Scenario: I can use this definition Then an email has been sent to "user@example.com" with the subject "Subject example" and the body “one of the lines in the body plus this is the other line of the body, after an additional line break”

My step definition looks like this:

/** * @Then /^an email has been sent to :email with the subject :subject and the body :body$/ */ public function anEmailHasBeenSentToWithTheSubjectAndTheBody($email, $subject, $body) { throw new PendingException(); }

Let’s try to run that.

$ ./vendor/bin/behat --tags=test-feature In Parser.php line 393: Expected Step, but got text: " plus this is the other line of the body, after an additional line break”" in file: tests/features/test.feature

Doing it that way simply does not work. You see, by default a line break in the Gherkin DSL has an actual meaning, so you can not do a line break in your argument, expecting it to just pass along everything up until the closing quote. What we actually want is to use a PyString. But how do we use them, and how do we define a step to receive them? Let’s start by converting our step definition to use the PyString multiline syntax:

@api @test-feature Feature: Test this feature Scenario: I can use this definition Then an email has been sent to "user@example.com" with the subject "Subject example" and the body """ one of the lines in the body plus this is the other line of the body, after an additional line break """

Now let’s try to run it:

$ ./vendor/bin/behat --tags=test-feature @api @test-feature Feature: Test this feature Scenario: I can use this definition # tests/features/test.feature:3 Then an email has been sent to "user@example.com" with the subject "Subject example" and the body """ one of the lines in the body plus this is the other line of the body, after an additional line break """ 1 scenario (1 undefined) 1 step (1 undefined) 0m0.45s (32.44Mb) >> default suite has undefined steps. Please choose the context to generate snippets:

A bit closer. Our output actually tells us that we have a missing step definition, and suggests how to define it. That’s better. Let’s try the suggestion from the output, now defining our step like this:

/** * @Then an email has been sent to :email with the subject :subject and the body */ public function anEmailHasBeenSentToWithTheSubjectAndTheBody2($email, $subject, PyStringNode $string) { throw new PendingException(); }

The difference here is that we do not add the variable name for the body in the annotation, and we specify that we want a PyStringNode type parameter last. This way behat will know (tm).

After running the behat command again, we can finally use the step definition. Let's have a look at how we can use the PyString class.

/** * @Then an email has been sent to :email with the subject :subject and the body */ public function anEmailHasBeenSentToWithTheSubjectAndTheBody2($email, $subject, PyStringNode $string) { // This is just an example. $mails = $this->getEmailsSomehow(); // This is now the important part, you get the raw string from the PyStringNode class. $body_string = $string->getRaw(); foreach ($mails as $item) { // Still just an example, but you probably get the point? if ($item['to'] == $mail && $item['subject'] == $subject && strpos($item['body'], $body_string) !== FALSE) { return; } } throw new \Exception('The mail was not found'); }

And that about wraps it up. Writing tests are fun, right? As a bonus, here is an animated gif called "Testing".

Categories: Drupal

Hook 42: Hook 42 is Headed to Minneapolis for DrupalCon 2020

Planet Drupal - 21 February 2020 - 12:51pm
Hook 42 is Headed to Minneapolis for DrupalCon 2020 Lindsey Gemmill Fri, 02/21/2020 - 20:51
Categories: Drupal

DrupalCon News: Announcing the Sessions for DrupalCon Minneapolis

Planet Drupal - 21 February 2020 - 9:34am

The accepted sessions for the next DrupalCon are now posted—and what an impressive lineup!

Curated content for the 45-minute sessions is packed with compelling insight, information, and your chance to learn the latest in Drupal. As you look at a session online (such as the one shown below), note its right-hand box with its designated track, tags that further explain its content, the experience level it’s geared toward, and a special button to add it to your DrupalCon schedule! 
 

Categories: Drupal

CKEditor Bootstrap Table

New Drupal Modules - 21 February 2020 - 8:07am
Categories: Drupal

JSON:API Views

New Drupal Modules - 21 February 2020 - 5:30am

Creates JSON:API Resource routes for Views.

Entities resulting from a view query will be available at /jsonapi/views/{view_id}/{display}.

This endpoint should respect any exposed filter parameters configured for a display.

Categories: Drupal

BirdSeed

New Drupal Modules - 21 February 2020 - 12:00am

Adds the BirdSeed script to your Drupal website.

Features:

1. Add BirdSeed script to specific pages
2. Add BirdSeed script to specific roles
3. Provides hook_birdseed_access_alter to add custom visibility conditions

Categories: Drupal

Ixis.co.uk - Thoughts: Can Drupal be used for mobile apps?

Planet Drupal - 21 February 2020 - 12:00am
Any website being developed these days is built on top of a responsive framework allowing pages to adapt and re-layout content based on the size of the viewing device.  Perfect for mobile and tablet devices alongside traditional desktop screens.  So why are mobile apps still chased after by people? What’s wrong with their responsive website?
Categories: Drupal

Advanced Drupal Audit Tool

New Drupal Modules - 20 February 2020 - 10:05pm
Categories: Drupal

Responsive Layout Builder

New Drupal Modules - 20 February 2020 - 8:09pm

Drupal 8 replacement for Responsive Panel Panes module.

This module helps to configure breakpoints per blocks in layout builder to control displaying of blocks in various screen sizes.

Categories: Drupal

Page Attributes

New Drupal Modules - 20 February 2020 - 5:58pm

Page Attributes is a simple module that allow you to customize a body class or an article class.

It will add a new area at the Advanced section of an add/new node page, and at the view page, you will have the informed classes.

Categories: Drupal

Amazee Labs: Our Next Webinar: Advanced BDD with Cypress

Planet Drupal - 20 February 2020 - 8:58am
Join us on March 19th for an Amazee Labs Webinar about Advanced BDD with Cypress. 
Categories: Drupal

Azure Blob File System

New Drupal Modules - 20 February 2020 - 8:53am

README TO COME SOON! PROMISE!

Categories: Drupal

JivoChat

New Drupal Modules - 20 February 2020 - 7:13am

This project is a drupal 8,9 porting of: jivosite_widget

JivoChat livechat is simple and elegant communication solution for your e-commerce site. It resembles Facebook chat window that is quite familiar nowadays. Also chat window always stays on top of your web site and does not blink and reload upon navigation. It will not get buried under dozens of opened browser windows and provide smooth user experience. If nobody is online visitor will see offline email form.

Categories: Drupal

thesavvyfew.com: How to customize the language switcher in Drupal 8

Planet Drupal - 20 February 2020 - 6:18am

As a creative digital agency based in Amsterdam, we’ve gotten used to having two languages of conduct: Dutch and English. We switch back and forth without even noticing and have learned to read, write and conduct business in both languages effortlessly. Our clients are…

Read more
Categories: Drupal

CTI Digital: CTI goes to Drupal Camp London 2020

Planet Drupal - 20 February 2020 - 5:54am

Drupal Camp London is a 3-day celebration of the users, designers, developers and advocates of Drupal and its community! Attracting 500 people from across Europe, after Drupalcon, it’s one of the biggest events in the Drupal Calendar. As such, we're pleased to sponsor such an event for the 6th time!

Categories: Drupal

Best selling products

New Drupal Modules - 20 February 2020 - 5:35am

"Best selling products" main feature of this module is the possibility to build and display "the best sales" block with products in your shop pages.

Categories: Drupal

Node auto term for entity reference field [SATE]

New Drupal Modules - 20 February 2020 - 2:11am

WHAT DO
-------
Parse text field (field type = text_with_summary) into entity reference taxonomy term field
(field type = entity_reference)
on event create and update entity.

SETTING
-------
field type entity_reference
admin/structure/types/manage/{bundle}/fields/{type}.{bundle}.{field_name}

Sponsored by http://oldlexicons.ru/

Categories: Drupal

Droptica: Drupal Agency Experts Heading To DrupalCamp London 2020

Planet Drupal - 20 February 2020 - 1:24am
DrupalCamp London is a great event for all Drupal agencies. It is a conference that brings together hundreds of Drupal experts from around the world. It's a great opportunity to meet people who use, develop, design and support the Drupal platform. Therefore, as usually we will be there this year as well. Droptica is a sponsor of DrupalCamp London 2020 We are proud to sponsor and participate in this year's DrupalCamp London. The event will take place on March 13-15, 2020 in London.
Categories: Drupal

File Upload Options

New Drupal Modules - 19 February 2020 - 1:37pm

Specify what should happen when uploaded files have the same name as files already uploaded. Configured per field, the options are are grouped by entity type.

To use, install and go to Admin -> Config -> Media -> File Upload Options to configure.

Also supports file uploads via REST which use FileUploadResource.

Only file fields are supported at this stage.

Categories: Drupal

Nonprofit Drupal posts: February Drupal for Nonprofits Chat -- Pantheon, NTC Planning

Planet Drupal - 19 February 2020 - 1:24pm

Our normally scheduled call to chat about all things Drupal and nonprofits will happen TOMORROW, Thursday, February 20, at 1pm ET / 10am PT. (Convert to your local time zone.)

This month, in addition to our usual free-for-all, we'll be talking about hosting on Pantheon. There has been a lot of discussion in the community and on the Drupal Slack #nonprofits channel about some of the pricing changes they have implemented. If you would like to discuss and contribute to the conversation, please join us.

We will also have an update on our community's plans for the upcoming Nonprofit Technology Conference (20NTC).

All nonprofit Drupal devs and users, regardless of experience level, are always welcome on this call.

Feel free to share your thoughts and discussion points ahead of time in our collaborative Google doc: https://nten.org/drupal/notes

This free call is sponsored by NTEN.org but open to everyone.

REMINDER: New call-in information -- we're on Zoom now!

  • Join the call: https://zoom.us/j/308614035
    • Meeting ID: 308 614 035
    • One tap mobile
      • +16699006833,,308614035# US (San Jose)
      • +16465588656,,308614035# US (New York)
    • Dial by your location
      • +1 669 900 6833 US (San Jose)
      • +1 646 558 8656 US (New York)
  • Follow along on Google Docs: https://nten.org/drupal/notes
  • Follow along on Twitter: #npdrupal

View notes of previous months' calls.

Categories: Drupal

Pages

Subscribe to As If Productions aggregator - Drupal