Skip to content

Commit

Permalink
Merge pull request #714 from ndw/send-mail2
Browse files Browse the repository at this point in the history
New and updated p:send-mail tests
  • Loading branch information
ndw authored May 30, 2024
2 parents 6439c98 + 6a71cbe commit e7fc1c2
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 14 deletions.
15 changes: 1 addition & 14 deletions test-suite/tests/nw-send-mail-001.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,7 @@
<!-- Check the Sendria log -->
<p:http-request href="http://localhost:1080/api/messages/" method="get"/>
<p:cast-content-type content-type="application/xml"/>
<p:validate-with-schematron>
<p:with-input port="schema">
<s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron">
<s:ns prefix="fn" uri="http://www.w3.org/2005/xpath-functions"/>
<s:pattern name="Root must be map">
<s:rule context="/fn:map">
<s:assert test="fn:string[@key='code'] = 'OK'">Code must be 'OK'</s:assert>
<s:assert test="fn:array[@key='data']/fn:map/fn:string[@key='subject']
= 'Plain text email'">The subject must be correct</s:assert>
</s:rule>
</s:pattern>
</s:schema>
</p:with-input>
</p:validate-with-schematron>

</p:declare-step>
</t:pipeline>
<t:schematron>
Expand Down
95 changes: 95 additions & 0 deletions test-suite/tests/nw-send-mail-002.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
expected="pass" features="send-mail">
<t:info>
<t:title>p:send-mail-002</t:title>
<t:revision-history>
<t:revision>
<t:date>2024-05-30</t:date>
<t:author>
<t:name>Norm Tovey-Walsh</t:name>
</t:author>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Test for the p:send-mail step.</p>
</t:description>
</t:revision>
</t:revision-history>
</t:info>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Test p:send-mail sending HTML mail. </p>
</t:description>
<t:pipeline>
<p:declare-step version="3.0" xmlns:p="http://www.w3.org/ns/xproc">
<p:output port="result" />

<!-- Clear the Sendria log -->
<p:http-request href="http://localhost:1080/api/messages/" method="delete">
<p:with-input>
<p:empty/>
</p:with-input>
</p:http-request>

<!-- Make sure that succeeded -->
<p:if test=".?code != 'OK'">
<p:error code="Q{http://example.com/}irrelevant"/>
</p:if>

<p:send-mail parameters="map{'host':'localhost', 'port':1025}"
auth="map{'username':'username','password':'password'}">
<p:with-input>
<p:inline>
<emx:Message
xmlns:emx='URN:ietf:params:email-xml:'
xmlns:rfc822='URN:ietf:params:rfc822:'>
<rfc822:from>
<emx:Address>
<emx:adrs>mailto:[email protected]</emx:adrs>
<emx:name>Example User</emx:name>
</emx:Address>
</rfc822:from>
<rfc822:to>
<emx:Address>
<emx:adrs>mailto:[email protected]</emx:adrs>
<emx:name>Another User</emx:name>
</emx:Address>
</rfc822:to>
<rfc822:subject>HTML Email</rfc822:subject>
<emx:content type='text/plain'>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello, World</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is an email message encoded in HTML. This is <em>evil</em>. Don’t do this.</p>
</body>
</html>
</emx:content>
</emx:Message>
</p:inline>
</p:with-input>
</p:send-mail>

<!-- Check the Sendria log -->
<p:http-request href="http://localhost:1080/api/messages/" method="get"/>
<p:http-request href="http://localhost:1080/api/messages/" method="get"/>
<p:http-request href="http://localhost:1080/api/messages/" method="get"/>
<p:cast-content-type content-type="application/xml"/>

</p:declare-step>
</t:pipeline>
<t:schematron>
<s:schema queryBinding="xslt2"
xmlns:s="http://purl.oclc.org/dsdl/schematron">
<s:ns prefix="fn" uri="http://www.w3.org/2005/xpath-functions"/>
<s:pattern name="Root must be map">
<s:rule context="/fn:map">
<s:assert test="fn:string[@key='code'] = 'OK'">Code must be 'OK'</s:assert>
<s:assert test="fn:array[@key='data']/fn:map/fn:string[@key='subject']
= 'HTML Email'">The subject must be correct</s:assert>
<s:assert test="fn:array[@key='data']/fn:map/fn:string[@key='type']
= 'text/html'">The content type must be HTML</s:assert>
</s:rule>
</s:pattern>
</s:schema>
</t:schematron>
</t:test>
98 changes: 98 additions & 0 deletions test-suite/tests/nw-send-mail-003.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
expected="pass" features="send-mail">
<t:info>
<t:title>p:send-mail-003</t:title>
<t:revision-history>
<t:revision>
<t:date>2024-05-30</t:date>
<t:author>
<t:name>Norm Tovey-Walsh</t:name>
</t:author>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Test for the p:send-mail step.</p>
</t:description>
</t:revision>
</t:revision-history>
</t:info>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Test p:send-mail sending multipart mail. </p>
</t:description>
<t:pipeline>
<p:declare-step version="3.0" xmlns:p="http://www.w3.org/ns/xproc">
<p:output port="result" />

<!-- Clear the Sendria log -->
<p:http-request href="http://localhost:1080/api/messages/" method="delete">
<p:with-input>
<p:empty/>
</p:with-input>
</p:http-request>

<!-- Make sure that succeeded -->
<p:if test=".?code != 'OK'">
<p:error code="Q{http://example.com/}irrelevant"/>
</p:if>

<p:send-mail parameters="map{'host':'localhost', 'port':1025}"
auth="map{'username':'username','password':'password'}">
<p:with-input>
<p:inline>
<emx:Message
xmlns:emx='URN:ietf:params:email-xml:'
xmlns:rfc822='URN:ietf:params:rfc822:'>
<rfc822:from>
<emx:Address>
<emx:adrs>mailto:[email protected]</emx:adrs>
<emx:name>Example User</emx:name>
</emx:Address>
</rfc822:from>
<rfc822:to>
<emx:Address>
<emx:adrs>mailto:[email protected]</emx:adrs>
<emx:name>Another User</emx:name>
</emx:Address>
</rfc822:to>
<rfc822:subject>Multi-part Email</rfc822:subject>
<emx:content type='text/plain'>
This is my text message.
</emx:content>
</emx:Message>
</p:inline>
<p:inline>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello, World</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my attachment.</p>
</body>
</html>
</p:inline>
</p:with-input>
</p:send-mail>

<!-- Check the Sendria log -->
<p:http-request href="http://localhost:1080/api/messages/" method="get"/>
<p:http-request href="http://localhost:1080/api/messages/" method="get"/>
<p:http-request href="http://localhost:1080/api/messages/" method="get"/>
<p:cast-content-type content-type="application/xml"/>

</p:declare-step>
</t:pipeline>
<t:schematron>
<s:schema queryBinding="xslt2"
xmlns:s="http://purl.oclc.org/dsdl/schematron">
<s:ns prefix="fn" uri="http://www.w3.org/2005/xpath-functions"/>
<s:pattern name="Root must be map">
<s:rule context="/fn:map">
<s:assert test="fn:string[@key='code'] = 'OK'">Code must be 'OK'</s:assert>
<s:assert test="fn:array[@key='data']/fn:map/fn:string[@key='subject']
= 'Multi-part Email'">The subject must be correct</s:assert>
<s:assert test="fn:array[@key='data']/fn:map/fn:string[@key='type']
= 'multipart/mixed'">The content type must be multipart/mixed</s:assert>
</s:rule>
</s:pattern>
</s:schema>
</t:schematron>
</t:test>

0 comments on commit e7fc1c2

Please sign in to comment.