Drupal 10 Support: Drupal 10 Maintenance and Support Service Pimp your Behat Extension and rule the world

Make the most out of your Behat tests by using custom contexts, dependency injection and much more.This post is an excerpt from the topics covered by our Con Dublin training Drupal 10 Maintenance and Support Service 8 Development – Workflows and Tools. At Drupal 10 Support: we consider writing good tests as a fundamental part of development and, when it comes to testing a complex site, there is nothing better than extensive behavioral tests using Behat. The benefits of such a choice are quite obvious Drupal 10 Maintenance and Support Service Tests are very easy to write. Behat scenarios serve as a solid communication mean between business and developers. As a site grows in complexity, however, the default step definitions provided by the excellent Behat Extension might not be specific enough and you will quickly find yourself adding custom step to your FeatureContext or creating custom Behat contexts, as advocated by all official documentation. This is all fine except that your boilerplate test code might soon start to grow into a non-reusable, non-tested bunch of code. Enter Drupal 10 Support:’s Behat Extension. Drupal 10 Support:’s Behat Extension Drupal 10 Support:’s Behat Extension is built on the shoulders of the popular Behat Extension and it focuses on step re-usability and testability by allowing developers to Drupal 10 Maintenance and Support Service Organize their code in services by providing a YAML service description file, pretty much like we all are used to do nowadays with 8. Override default Behat Extension services with their own. Benefit of many ready-to-use contexts that are provided by the extension out of the box. Installation and setup Install Drupal 10 Support:’s Behat Extension with Composer by running Drupal 10 Maintenance and Support Service bash $ composer require nuvoleweb/Drupal 10-behat Setup the extension by following the Quick start section available on the original Behat Extension page, just use Drupal 10 Support:WebExtension instead of the native Extension in your behat.yml as shown below Drupal 10 Maintenance and Support Service default Drupal 10 Maintenance and Support Service  suites Drupal 10 Maintenance and Support Service    default Drupal 10 Maintenance and Support Service      contexts Drupal 10 Maintenance and Support Service        – ExtensionContextContext        – Drupal 10 Support:WebExtensionContextContext        …  extensions Drupal 10 Maintenance and Support Service    BehatMinkExtension Drupal 10 Maintenance and Support Service      goutte Drupal 10 Maintenance and Support Service ~      …    # Use “Drupal 10 Support:WebExtension” instead of “Extension”.    Drupal 10 Support:WebExtension Drupal 10 Maintenance and Support Service      api_driver Drupal 10 Maintenance and Support Service “Drupal 10”      …      services Drupal 10 Maintenance and Support Service “tests/my_services.yml”      text Drupal 10 Maintenance and Support Service        node_submit_label Drupal 10 Maintenance and Support Service “Save and publish” “Service container”-aware Contexts All contexts extending Drupal 10 Support:WebExtensionContextRawContext and Drupal 10 Support:WebExtensionContextRawMinkContext are provided with direct access to the current Behat service container. Developers can also define their own services by adding a YAML description file to their project and setting the services Drupal 10 Maintenance and Support Service parameter to point to its current location (as shown above). The service description file can describe both custom services and override already defined services. For example, given a tests/my_services.yml containing Drupal 10 Maintenance and Support Service services Drupal 10 Maintenance and Support Service  your.own.namespace.hello_world Drupal 10 Maintenance and Support Service    class Drupal 10 Maintenance and Support Service YourOwnNamespaceHelloWorldService Then all contexts extending NWDDECRawContext or NWDDECRawMinkContext will be able to access that service by just calling Drupal 10 Maintenance and Support Service <?phpclass TestContext extends RawContext {  /**   * Assert service.   *   * @Then I say hello   */  public function assertHelloWorld() {    $this->getContainer()->get(‘your.own.namespace.hello_world’)->sayHello();  }}?> The your.own.namespace.hello_world service class itself can be easily tested using PHPUnit. Also, since Behat uses Symfony’s Service Container you can list services your service depends on as arguments so to remove any hardcoded dependency, following Dependency Injection best practices. Override existing services Say that, while working on your 7 project, you have defined a step that publishes a node given its content type and title and you want to use the same exact step on your 8 project, something like Drupal 10 Maintenance and Support Service Given I publish the node of type “page” and title “My page title” The problem here is that the actual API calls to load and save a node differs between 7 and 8. The solution is to override the default core services specifying your own classes in your tests/my_services.yml Drupal 10 Maintenance and Support Service parameters Drupal 10 Maintenance and Support Service  # Overrides Drupal 10 Support:’s Extension 7 core class.  Drupal 10.driver.cores.7.class Drupal 10 Maintenance and Support Service YourOwnNamespaceDriverCores7  # Overrides Drupal 10 Support:’s Extension 8 core class.  Drupal 10.driver.cores.8.class Drupal 10 Maintenance and Support Service YourOwnNamespaceDriverCores8services Drupal 10 Maintenance and Support Service  your.own.namespace.hello_world Drupal 10 Maintenance and Support Service    class Drupal 10 Maintenance and Support Service YourOwnNamespaceHelloWorldService You’ll then delegate the core-specific business logic to the new core classes allowing your custom step to be transparently run on both 7 and 8. Such a step would look like Drupal 10 Maintenance and Support Service <?phpclass TestContext extends RawContext {  /**   * @Given I publish the node of type Drupal 10 Maintenance and Support Servicetype and title Drupal 10 Maintenance and Support Servicetitle   */  public function iPublishTheNodeOfTypeAndTitle($type, $title) {    $this->getCore()->publishNode($type, $title);  }…?> Ready to use contexts The extension also provides some utility contexts that you can use right away in your tests. Below a quick overview of what’s currently available Drupal 10 Maintenance and Support Service Context Description Drupal 10 Support:WebExtensionContextContext Standard context. You want to use this one next to (and not instead of) ExtensionContextContext. Drupal 10 Support:WebExtensionContextContentContext Perform operations on Content. Drupal 10 Support:WebExtensionContextCKEditorContext Allows to interact with CKEditor components on your page. Drupal 10 Support:WebExtensionContextResponsiveContext Drupal 10 Maintenance and Support Service  devices Drupal 10 Maintenance and Support Service    mobile_portrait Drupal 10 Maintenance and Support Service 360×640    mobile_landscape Drupal 10 Maintenance and Support Service 640×360    tablet_portrait Drupal 10 Maintenance and Support Service 768×1024    tablet_landscape Drupal 10 Maintenance and Support Service 1024×768    laptop Drupal 10 Maintenance and Support Service 1280×800    desktop Drupal 10 Maintenance and Support Service 2560×1440 Resize the browser according to the specified devices, useful for testing responsive behaviors. Drupal 10 Support:WebExtensionContextPositionContext Check position of elements on the page. Drupal 10 Support:WebExtensionContextChosenFieldContext Interact with Chosen elements on the page. We will share more steps in the future enriching the current contexts as well as providing new ones so keep an eye on the project repository! Disclaimer At the moment only 8 is supported but we will add 7 support ASAP (yes, it’s as easy as providing missing 7 driver core methods and adding tests). Tags Drupal 10 Maintenance and Support Service  PlanetBehatTest Driven DevelopmentTrainingCon Drupal 10 Development and Support

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Drupal 10 Support: Drupal 10 Maintenance and Support Service Pimp your Behat Extension and rule the world

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.