joomla/test-system

此包已被放弃,不再维护。未建议替代包。

使用 Codeception 对 Joomla CMS 系统进行测试

dev-4.0-dev 2020-10-05 21:37 UTC

This package is auto-updated.

Last update: 2020-11-05 21:53:38 UTC


README

注意 - 此存储库目前已被存档。

基于浏览器的 Joomla 系统测试(测试包)

摘要

此存储库旨在包含 Joomla 4 的基于浏览器的系统测试(codeception 测试)。

安装

对于 Linux

1. 打开一个会话并切换到本地 web 服务器的文档根目录。
$ cd /var/www/html/
/var/www/html$
2. 将当前 joomla 存储库克隆到您的 web 服务器根目录中
/var/www/html$ git clone git@github.com:joomla/joomla-cms.git
Clone into 'joomla-cms' ...
...

您是 GitHub 新手吗?这里您可以找到有关设置的信息:https://help.github.com/articles/set-up-git/ 如果您遇到错误,您可以尝试使用 git clone https://github.com/joomla/joomla-cms.git 而不是 git clone git@github.com:joomla/joomla-cms.git

3. 切换到 joomla-cms 目录并确保您处于 4.0-dev 分支

切换到目录

/var/www/html$ cd joomla-cms
/var/www/html/joomla-cms$

确保您处于正确的分支

/var/www/html/joomla-cms$ git branch
* staging
/var/www/html/joomla-cms$ git fetch origin 4.0-dev:4.0-dev
/var/www/html/joomla-cms$ git checkout 4.0-dev
/var/www/html/joomla-cms$ git branch
* 4.0-dev
  staging

4. 您的 joomla-cms 文件夹应包含以下文件
/var/www/html/joomla-cms$ ls
acceptance.suite.yml  cli                 Gemfile       jenkins-phpunit.xml  modules            RoboFile.php          web.config.txt
administrator         codeception.yml     htaccess.txt  karma.conf.js        package.json       robots.txt.dist
appveyor-phpunit.xml  components          images        language             phpunit.xml.dist   scss-lint.yml
build                 composer.json       includes      layouts              plugins            templates
build.js              composer.lock       index.php     libraries            README.md          tests
build.xml             dev                 installation  LICENSE.txt          README.txt         tmp
cache                 drone-package.json  Jenkinsfile   media                RoboFile.dist.ini  travisci-phpunit.xml

5. 可选:查看 composer.json 以获取您将通过 composer 安装的软件信息。
/var/www/html/joomla-cms$ cat composer.json

有关如何安装 composer 的更多信息,请参阅 如何安装 composer

6. 通过 composer 安装

/var/www/html/joomla-cms$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 63 installs, 0 updates, 0 removals
  - Installing behat/gherkin (v4.4.5): Downloading (100%)
  - Installing sebastian/recursion-context (3.0.0): Downloading (100%)
...
 - Installing joomla/test-system (dev-master ca3879f): Cloning ca3879f603
...
Generating optimized autoload files

现在您可以看到这个存储库在目录 /var/www/html/joomla-cms/libraries/vendor/joomla/test-system 中

7. 可选:准备数据库

如果您使用 MySQL 或 PostgreSQL 作为数据库,并且您的用户具有创建数据库的权限,则数据库将由 Joomla 安装程序自动创建。但最安全的方法是在运行 Joomla 的 web 安装程序之前创建数据库。

/var/www/html/joomla-cms$ mysql -u root -p

mysql> create database test_joomla;
Query OK, 1 row affected (0,00 sec)

mysql> quit;
Bye
8. 根据您的需求更新文件 acceptance.suite.yml。

重要的是以下选项

  • 在 JoomlaBrowser 和 Helper\Acceptance 部分中的 url
  • 数据库名称和
  • 数据库用户。
  • 数据库密码。
/var/www/html/joomla-cms$ cat acceptance.suite.yml

class_name: AcceptanceTester
modules:
    enabled:
        - Asserts
        - JoomlaBrowser
        - Helper\Acceptance
    config:
        JoomlaBrowser:
            url: 'http://localhost/joomla-cms/test-install'     # the url that points to the joomla installation at /tests/system/joomla-cms
            browser: chrome
            window_size: 1280x1024
            username: 'admin'                      # UserName for the Administrator
            password: 'admin'                      # Password for the Administrator
            database host: 'localhost'             # place where the Application is Hosted #server Address
            database user: 'root'                  # MySQL Server user ID, usually root
            database password: 'YOURDBPASSWORD'    # MySQL Server password, usually empty or root
            database name: 'test_joomla'           # DB Name, at the Server
            database type: 'mysqli'                # type in lowercase one of the options: MySQL\MySQLi\PDO
            database prefix: 'jos_'                # DB Prefix for tables
            install sample data: 'no'              # Do you want to Download the Sample Data Along with Joomla Installation, then keep it Yes
            sample data: 'Default English (GB) Sample Data'    # Default Sample Data
            admin email: 'admin@mydomain.com'      # email Id of the Admin
            language: 'English (United Kingdom)'   # Language in which you want the Application to be Installed
        Helper\Acceptance:
            url: 'http://localhost/joomla-cms/test-install' # the url that points to the joomla installation at /tests/system/joomla-cms - we need it twice here
            MicrosoftEdgeInsiders: false             # set this to true, if you are on Windows Insiders

error_level: "E_ALL & ~E_STRICT & ~E_DEPRECATED"
9. 将文件 acceptance.suite.yml 复制到该仓库。

目前我们需要配置文件两次!

/var/www/html/joomla-cms$ cp acceptance.suite.yml ./libraries/vendor/joomla/test-system/src
10. (可选)创建并编辑文件 RoboFile.ini。
/var/www/html/joomla-cms$ cat RoboFile.ini
; If you want to setup your test website (document root) in a different folder, you can do that here.
; You can also set an absolute path, i.e. /path/to/my/cms/folder
cmsPath = test-install

; (Linux / Mac only) If you want to set a different owner for the CMS root folder, you can set it here.
localUser =
11. (可选)将项目所有者设置为您的用户。

通过递归遍历目录来更改文件的用户名/用户组。这是由“-R”选项实现的。

/var/www/html/joomla-cms$sudo chown -R username:usergroup /var/www/html/joomla-cms

运行 - 准备!运行第一次测试

对于 Linux

/var/www/html/joomla-cms$ libraries/vendor/bin/robo run:tests➜  Running tests
 [Filesystem\DeleteDir] Deleted test-install...
 [Filesystem\CopyDir] Copied from ./media to test-install/media
 [Filesystem\CopyDir] Copied from ./nbproject to test-install/nbproject
 [Filesystem\CopyDir] Copied from ./images to test-install/images
 [Filesystem\CopyDir] Copied from ./libraries to test-install/libraries
...

现在浏览器窗口打开,您可以在其中看到正在运行的测试。

如果您收到如下错误

/var/www/html/joomla-cms$ libraries/vendor/bin/robo run:tests
➜  Running tests
 [Filesystem\CopyDir] Copied from ./media to test-install/media
 [Filesystem\CopyDir] Copied from ./nbproject to test-install/nbproject
 [Filesystem\CopyDir] Copied from ./images to test-install/images
 [error]  Failed to copy "./libraries/vendor/consolidation/robo/scenarios/symfony2/tests" because file does not exist.

您需要删除两个文件

/var/www/html/joomla-cms$ rm ./libraries/vendor/consolidation/robo/scenarios/symfony2/tests
/var/www/html/joomla-cms$ rm ./libraries/vendor/consolidation/robo/scenarios/symfony4/tests

测试使用 Codeception 测试框架,如果您想了解更多关于测试中使用的技术的信息,请查看:[使用 Codeception 测试 Joomla 扩展](https://docs.joomla.org/Testing_Joomla_Extensions_with_Codeception)。