如何断言动态输出

时间:2016-01-07 10:56:51

标签: regex dynamic output behat

我正在开发一个与本地付款互动的图书馆。提供商服务器。

基本上,我首先希望它生成隐藏<form> s的<input>,而不包含<form>标记。

为此,我有一个功能文件,我在其中指定了以下内容:

# GeneratePaymentFormData.feature
Feature: GeneratePaymentFormData
  In order to display a payment button with the corresponding `<form>` and `<input>`s to the user
  As a developer
  I need to be able to supply specific input parameters to my library and have it returning a whole bunch of hidden `<input>` tags with specific values.

  Scenario: Send POST request to estcard.ee
    Given Parameter "private_key_file" is "private.key"
    And Parameter "merchant_id" is "11223344"
    And Parameter "feedback_url" is "http://localhost/myapp/callback.php"
    And Parameter "amount" is "0.19"
    And Parameter "currency" is "EUR"

    When I click on Pay
    Then the output should be
      """
      <input type="hidden" name="action" value="gaf"><br>
      <input type="hidden" name="ver" value="004"><br>
      <input type="hidden" name="id" value="11223344"><br>
      <input type="hidden" name="ecuno" value="201601149511"><br>
      <input type="hidden" name="eamount" value="000000000019"><br>
      <input type="hidden" name="cur" value="EUR"><br>
      <input type="hidden" name="datetime" value="20160107121111"><br>
      <input type="hidden" name="charEncoding" value="UTF-8"><br>
      <input type="hidden" name="feedBackUrl" value="http://localhost/myapp/callback.php"><br>
      <input type="hidden" name="delivery" value="S"><br>
      <input type="hidden" name="mac" value="a9502a893e014072788551a4d7420e9a67ed63782cc9aa7b4b0d4f7b402472dd725fe585f6ba537f3994e259c7b9070a24e1af06a1f87aab0d4f90826925599f6f74d5fb2ce8f79f881ef8face1af6d1913b7e020065a10e6195070f191b71fed49619547bf07e6fc762481e0b307eab0b4775fdb4c1af0cadf260eb6ba0df5c"><br>

      """

问题是库必须输出动态数据。例如,ecuno字段是从当前日期和时间生成的,后跟随机数。字段 mac 是所有值(包括具有随机值的值)的串联字符串,使用sha1进行散列,然后使用openssl_sign()进行签名,然后转换为十六进制。

如果输入参数全部相同,每次更改某些部分时,如何测试我的库的输出是否符合预期?我想我必须在验证输出时使用正则表达式,但究竟是怎么做的?

0 个答案:

没有答案