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

Kar*_*arl 2 php drupal behat

不知道有人可以帮助我,我正在使用Behat自动测试drupal网站..

我想以格式输入日期 - dd/mm/YYYY - 我可以手动输入,但表格的变量是30天以上的日期.

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

Kar*_*arl 6

我设法让这个工作...添加到你的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);
}
Run Code Online (Sandbox Code Playgroud)