pfaocle/codeception-module-drupal-user-registry

此包已被弃用且不再维护。作者建议使用ixis/codeception-module-drupal-user-registry包。

用于管理测试用户的Codeception模块。

v0.2.2 2016-03-17 09:41 UTC

README

用于管理测试用户的Codeception模块

Build Status Scrutinizer Code Quality Latest Stable Version Latest unstable version Total Downloads License

Drupal用户注册是一个用于在Codeception模块中管理Drupal站点测试用户的模块。它可以配置为在套件运行前后自动创建和删除用户。

它还允许在测试中使用以下语句

// Returns a DrupalTestUser object representing the test user available for
// this role.
$user = $I->getUserByRole($roleName);

// Returns a DrupalTestUser object representing the test user available for
// exactly these roles.
$user = $I->getUserByRole([$roleName1, $roleName2]);

// Returns a DrupalTestUser object representing the user, or false if no users
// were found. Note this will only return a user defined and managed by this
// module, it will not return information about arbitrary accounts on the site
// being tested.
$user = $I->getUser($userName);

// Returns an indexed array of configured roles, for example:
//   array(
//     0 => 'administrator',
//     1 => 'editor',
//     2 => ...
//   );
$roles = $I->getRoles();

// Returns a DrupalTestUser object representing the "root" user (account with
// uid 1), if credentials are configured:
$rootUser = $I->getRootUser();

// Also provided are a few utility methods that can be used in tests to
// store and retrieve a DrupalTestUser object representing the logged in user.
// Note these methods don't actually log a user in or out - that currently
// needs to be handled elsewhere.
$I->setLoggedInUser($I->getUserByRole('administrator'));
$I->getLoggedInUser();
$I->removeLoggedInUser();

Actor对象$I可用的所有方法均在此模块的公共API中定义。

DrupalTestUser类是对Drupal用户账户的非常简单的表示,可以用作在StepObject或PageObject中定义的登录过程的一部分。

此模块目前使用Drush和Drush别名来创建、删除用户账户并添加角色。请注意,在删除用户时使用了--delete-content选项,因此该用户账户创建的任何内容也将被删除。

安装

此模块可在Packagist上找到,可以使用Composer进行安装

{
    "require": {
        "codeception/codeception": "2.0.*",
        "ixis/codeception-module-drupal-user-registry": "~0.2.1"
    }
}

Drupal用户注册至少需要Codeception 2.0和PHP 5.4;请注意,版本0.2.2及以下版本仅与Codeception 2.0.*兼容。

示例套件配置

class_name: AcceptanceTester
modules:
    enabled:
        - PhpBrowser
        - AcceptanceHelper
        - DrupalUserRegistry
    config:
        PhpBrowser:
            url: 'https:///myapp/'
        DrupalUserRegistry:
            defaultPass: "foobar"
            users:
                administrator:
                    name: administrator
                    email: admin@example.com
                    pass: "foo%^&&"
                    roles: [ administrator, editor ]
                    root: true
                editor:
                    name: editor
                    email: editor@example.com
                    roles: [ editor, sub-editor ]
                "sub editor":
                    name: "sub editor"
                    email: "sub.editor@example.com"
                    roles: [ sub-editor ]
                authenticated:
                    name: authenticated
                    email: authenticated@example.com
                    roles: [ "authenticated user" ]
            create: true                 # Whether to create all defined test users at the start of the suite.
            delete: true                 # Whether to delete all defined test users at the end of the suite.
            drush-alias: '@mysite.local' # The Drush alias to use when managing users via DrushTestUserManager.

必需和可选配置

users的配置值是必需的。drush-alias目前是必需的,因为DrushTestUserManager是管理(创建/删除)用户的唯一类。

其他可选配置包括

  • createdelete如果没有设置,则假定它们的值为false
  • 可以使用defaultPass设置默认测试用户密码,以防您不想为每个用户添加密码。它仍然可以按用户进行覆盖。
  • 可以为任何用户(但只能有一个)添加root键以表示它是root用户(uid 1)。该用户应在数据库中已存在,将不会被创建。

故障排除

当与Codeception的--debug选项一起使用时,模块提供了更详细的输出。例如

$ vendor/bin/codecept run --debug

[Drupal User Registry] Creating test users.
  Trying to create test user 'test.administrator' on '@mysite.local'.
  drush -y '@mysite.local' user-information 'test.administrator'
Creating test user 'test.administrator' on '@mysite.local'.
  drush -y '@mysite.local' user-create 'test.administrator' --mail='test.administrator@example.com' --password='test123!'
  drush -y '@mysite.local' user-add-role 'administrator' --name='test.administrator'
  Trying to create test user 'test.editor' on '@mysite.local'.
  drush -y '@mysite.local' user-information 'test.editor'
Creating test user 'test.editor' on '@mysite.local'.
  drush -y '@mysite.local' user-create 'test.editor' --mail='test.editor@example.com' --password='test123!'
  drush -y '@mysite.local' user-add-role 'editor' --name='test.editor'
...
(Tests.)
...
  [Drupal User Registry] Deleting test users.
Deleting test user test.administrator on @mysite.local.
  drush -y '@mysite.local' user-cancel test.administrator --delete-content
Deleting test user test.editor on @mysite.local.
  drush -y '@mysite.local' user-cancel test.editor --delete-content
...

测试

此模块使用Codeception进行了一些单元和功能测试。目前仅在Travis构建中运行单元测试。

要运行单元测试

$ vendor/bin/codecept run unit

功能套件需要设置一个Drupal 7网站,数据库连接需要按照在 functional.suite.yml 中配置的进行开放连接 - 最佳做法是编辑 本地 环境的配置并运行

$ vendor/bin/codecept run functional --env=local

运行两个套件

$ vendor/bin/codecept run --env=local

贡献

本模块的代码使用 git-flow (AVH Edition) 进行管理。发布在 master 分支上,并应使用 语义版本控制 和格式 vx.y.z,例如 v1.2.3

请向 develop 分支提交拉取请求。

致谢

感谢 Andy Rigby 提供存储代码和灵感。

许可证

本项目采用 MIT 许可证(MIT)授权。