tmf/wordpress-extension

Behat 3的WordPress扩展

v0.1.1 2015-11-21 22:18 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:25:29 UTC


README

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

安装

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

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

    default:
      suites:
        default:
          contexts:
            - Tmf\WordPressExtension\Context\WordPressContext
      extensions:
        Tmf\WordPressExtension:
          path: '%paths.base/vendor/wordpress'
    
        Behat\MinkExtension:
          base_url:    'https://:8000'
          sessions:
            default:
              goutte: ~
    
  3. 安装依赖项并初始化behat测试套件

    composer update
    vendor/bin/behat --init
  4. 启动您的开发Web服务器,并将其文档根目录指向 vendors 中的 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