php - Behat - 日期的步骤定义?今天和 -/+ 天?

标签 php drupal behat

想知道是否有人可以帮助我,我正在使用 Behat 自动测试 drupal 站点。

我想以这种格式输入日期 - dd/mm/YYYY - 我可以手动输入这个,但是表单的一个变量是超过 30 天的日期。

在 Behat(我找不到)中是否有一种方法可以将今天的日期放在一个字段中,以及今天的日期 + 或 - X 天数?这似乎不是内置的,但我

最佳答案

我设法让它工作......将它添加到你的 FormContext 文件中 -

/**
 * Fills in specified field with date
 * Example: When I fill in "field_ID" with date "now"
 * Example: When I fill in "field_ID" with date "-7 days"
 * Example: When I fill in "field_ID" with date "+7 days"
 * Example: When I fill in "field_ID" with date "-/+0 weeks"
 * Example: When I fill in "field_ID" with date "-/+0 years"
 *
 * @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with date "(?P<value>(?:[^"]|\\")*)"$/
 */
public function fillDateField($field, $value)
{
    $newDate = strtotime("$value");

    $dateToSet = date("d/m/Y", $newDate);
    $this->getSession()->getPage()->fillField($field, $dateToSet);
}

关于php - Behat - 日期的步骤定义?今天和 -/+ 天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37969623/

相关文章:

ajax - 以编程方式使用 Drupal7 AJAX 优点

Drupal分类学

php - "When I fill the following fields"输入今天的日期?

php - 吃掉内存

php - 如何从 PHP myadim 数据库检索图像并在 android ListView 中显示?

php - 使用 mySQL 进程 ID 定位发出查询的 PHP 脚本

php - 无法使用 mysqli 发布数据

php - PDO::exec() 还是 PDO::query()?

drupal - 更改 Drupal 的主题并保留 Garland 作为管理主题?

测试 Symfony3 最佳实践