stephenharris / wordpress-behat-extension

WordPress扩展,用于Behat 3


README

这是一个为WordPress插件和主题开发提供的Behat 3.0扩展。

该扩展允许您在包含StephenHarris\WordPressBehatExtension\Context\WordPressContext(或创建并包含其子类,即您的FeatureContext)的情况下,在您的上下文类中使用WordPress函数。

它还提供了其他上下文

版本: 0.4.0 . 此项目遵循SemVer

历史

此存储库最初是

的一个分支

的一个分支

  1. 安装

    {
        "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/stephenharris/WordPressBehatExtension.git"
            }
        ],
        "require-dev" : {
            "stephenharris/wordpress-behat-extension": "~0.3",
            "behat/mink-goutte-driver": "~1.1",
            "behat/mink-selenium2-driver": "~1.3.1",
            "johnpbloch/wordpress": "~4.6.1"
        }
    }

    (有关“快速入门”指南,请参阅食谱)。

  2. 将以下Behat配置文件添加到您的WordPress主题或插件的composer开发要求中

  • 您不必通过composer安装WordPress。但是您需要以下WordPress安装路径。另外,您不必使用Goutte和Selenium2驱动程序,但这些是最常见的。

  • 添加以下Behat配置文件。您将需要

  • WordPress安装的路径(此处假设为vendor/wordpress,相对于您的项目根目录)。

  • WordPress安装的数据库、数据库用户名和密码(此处假设为wordress_testroot''

    default:
      suites:
        default:
          contexts:
            - FeatureContext
            - \StephenHarris\WordPressBehatExtension\Context\WordPressContext
            - \StephenHarris\WordPressBehatExtension\Context\Plugins\WordPressPluginContext
            # and any other contexts you need, please see the documentation
      extensions:
        StephenHarris\WordPressBehatExtension:
          path: '%paths.base%/vendor/wordpress'
          connection:
            host: 'localhost'
            db: 'wordpress_test'
            username: 'root'
            password: ''
          mail:
            directory: '/tmp/mail'
        Behat\MinkExtension:
          base_url:    'https://:8000'
          goutte: ~
          selenium2: ~

    WordPress安装的URL(在此示例中,我们将使用PHP的内置服务器)

  1. 用于存储已“发送”电子邮件的临时目录

    composer update
    # You will need to ensure a WordPress install is available, with database credentials that
    # mach the configuration file above
    vendor/bin/behat --init
  2. 请注意包含的StephenHarris\WordPressBehatExtension\Context\WordPressContext上下文。这将导致WordPress被加载,并在您的上下文类中提供所有其函数。您还可以包含其他上下文

    Feature: Manage plugins
        In order to manage plugins
        As an admin
        I need to enable and disable plugins
    
        Background:
            Given I have a vanilla wordpress installation
                | name          | email                   | username | password |
                | BDD WordPress | your@email.com          | admin    | test     |
            And I am logged in as "admin" with password "test"
    
        Scenario: Enable the dolly plugin
            Given there are plugins
                | plugin    | status  |
                | hello.php | enabled |
            When I go to "/wp-admin/"
            Then I should see a "#dolly" element
    
        Scenario: Disable the dolly plugin
            Given there are plugins
                | plugin    | status   |
                | hello.php | disabled |
            When I go to "/wp-admin/"
            Then I should not see a "#dolly" element
    
    
  3. 安装供应商并初始化behat测试套件

在您的项目的features目录中编写一些behat功能,并定义任何步骤。该WordPressContext上下文将在您的上下文类中提供所有WordPress函数(但有更好的方法)。


php -S localhost:8000 -t vendor/wordpress -d disable_functions=mail
```

```bash
vendor/bin/behat
```

运行测试

在我们的示例中,由于我们使用PHP的内置Web服务器,因此需要启动它,以便behat可以访问我们的网站。

文档

请参阅文档

目标

本项目的目标是提供一组上下文类,以便于测试WordPress的核心功能。然后可以在此基础上构建以测试您网站/插件/主题特定的功能。

许可

WordPressBehatExtension是开源的,并按照MIT许可证发布。有关更多信息,请参阅LICENSE文件。

健康警告

该扩展将三个 mu-plugins 安装到您的安装中(它假设安装路径为 {site-path}/wp-content/mu-plugins)。这些插件执行以下操作:

  • wp-mail.php - 覆盖 wp_mail() 函数以本地存储电子邮件
  • wp-install.php - 覆盖 wp_install_defaults() 以防止创建任何默认内容,除了 '未分类' 类别。
  • move-admin-bar-to-back.php - 解决 #1 的问题,防止元素在 Selenium 后面被管理菜单栏隐藏。

变更日志

变更日志可以在 CHANGELOG.md 中找到。

如何帮助

该项目需要很多关爱 :)。您可以通过以下任何一种方式来帮助:

  • 开启一个问题来请求上下文 / 步骤定义
  • 提交一个 PR 以添加上下文 / 步骤定义
  • 提交一个 PR 以添加或改进文档
  • 开启一个问题,您有疑问或发现任何错误
  • 只需在使用此扩展进行开发 / 测试工作流程时提供反馈