johnbillion/wordpress-behat-extension

此包已被 废弃 并不再维护。作者建议使用 paulgibbs/behat-wordpress-extension 包。

WordPress扩展用于Behat 3

0.1.5 2017-05-27 12:01 UTC

This package is auto-updated.

Last update: 2022-02-01 12:46:32 UTC


README

这是一个为WordPress插件和主题开发而设计的Behat 3.0扩展。您可以使用它来测试您的WordPress安装,或者仅测试您的插件/主题,而无需在正常的WordPress安装中安装它们(即独立安装)。此扩展允许您在上下文类中使用WordPress函数(如果您从Johnbillion\WordPressExtension\Context\WordPressContext扩展它)。

安装

  1. 为您的WordPress主题或插件添加composer开发依赖项

    {
        "require-dev" : {
            "johnbillion/wordpress-behat-extension": "~0.1",
            "johnpbloch/wordpress": "~4.0.0"
        }
    }
  2. 添加以下Behat配置文件

    default:
      suites:
        default:
          contexts:
            - Johnbillion\WordPressExtension\Context\WordPressContext
      extensions:
        Johnbillion\WordPressExtension:
          path: '%paths.base/vendor/wordpress'
    
        Behat\MinkExtension:
          base_url:    'http://localhost:8000'
          sessions:
            default:
              goutte: ~
    
  3. 安装供应商并初始化behat测试套件

    composer update
    vendor/bin/behat --init
  4. 启动您的开发Web服务器,并将其文档根指向供应商中的wordpress目录(无邮件功能)

    php -S localhost:8000 -t vendor/wordpress -d disable_functions=mail
  5. 编写一些Behat特性并测试它们

    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
    
    
  6. 运行测试

    vendor/bin/behat