<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
  <t:info>
    <t:title>pdf-form-002</t:title>
    <t:revision-history>
      <t:revision>
        <t:date>2026-06-12</t:date>
        <t:author>
          <t:name>Norm Tovey-Walsh</t:name>
        </t:author>
        <t:description xmlns="http://www.w3.org/1999/xhtml">
          <p>Created test.</p>
        </t:description>
      </t:revision>
    </t:revision-history>
  </t:info>
  <t:description xmlns="http://www.w3.org/1999/xhtml">
    <p>Tests that pdf-form works.</p>
  </t:description>
  <t:pipeline>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:cx="http://xmlcalabash.com/ns/extensions"
                name="main" version="3.0">
  <p:import href="https://xmlcalabash.com/ext/library/pdf-steps.xpl"/>
  <p:output port="result"/>

  <cx:pdf-form>
    <p:with-input port="source" href="../documents/libreoffice-form.pdf"/>
    <p:with-input port="data">
      <f:acro-form xmlns:f="http://xmlcalabash.com/ns/acro-form">
        <f:text name="Last Name" type="Tx">Wonderland</f:text>
        <f:radiobutton name="female" type="Btn">1</f:radiobutton>
        <f:checkbox name="gdpr" type="Btn">1</f:checkbox>
        <f:checkbox name="other" type="Btn">Off</f:checkbox>
        <f:combobox name="Nationality" type="Ch">
          <f:value>Unknown</f:value>
        </f:combobox>
      </f:acro-form>
    </p:with-input>
  </cx:pdf-form>

  <cx:pdf-info form-details="true"/>

</p:declare-step>
  </t:pipeline>
  <t:schematron>
    <s:schema queryBinding="xslt2"
              xmlns:s="http://purl.oclc.org/dsdl/schematron">
      <s:ns prefix="cx" uri="http://xmlcalabash.com/ns/extensions"/>
      <s:ns prefix="f" uri="http://xmlcalabash.com/ns/acro-form"/>

      <s:pattern>
        <s:rule context="/">
          <s:assert test="cx:pdf-info">Wrong document element></s:assert>
        </s:rule>
      </s:pattern>

      <s:pattern>
        <s:rule context="/cx:pdf-info">
          <s:assert test="exists(f:acro-form)">Form is missing</s:assert>
        </s:rule>
      </s:pattern>

      <s:pattern>
        <s:rule context="f:acro-form">
          <s:assert test="f:text[@name='First Name'] = 'Alice'">First name is incorrect</s:assert>
          <s:assert test="f:text[@name='Last Name'] = 'Wonderland'">Last name is incorrect</s:assert>
          <s:assert test="f:radiobutton[@name='female'] = '1'">Radio button is wrong</s:assert>
          <s:assert test="f:checkbox[@name='gdpr'] = 'Yes'">Check box is wrong</s:assert>
          <s:assert test="f:combobox/f:value = 'Unknown'">Combobox is wrong</s:assert>
        </s:rule>
      </s:pattern>

    </s:schema>
  </t:schematron>
</t:test>
