unit tests

This commit is contained in:
Andreas Schamberger 2011-10-31 11:55:14 +01:00
parent 4becca0208
commit e0049c906d
13 changed files with 569 additions and 26 deletions

4
.gitignore vendored
View File

@ -1 +1,5 @@
vendor vendor
/phpunit.xml
.buildpath
.project
.settings

View File

@ -80,6 +80,7 @@ class MultiPart extends PartHeader
/** /**
* Get string array with MIME headers for usage in HTTP header (with CURL). * Get string array with MIME headers for usage in HTTP header (with CURL).
* Only 'Content-Type' and 'Content-Description' headers are returned.
* *
* @return arrray(string) * @return arrray(string)
*/ */
@ -92,19 +93,7 @@ class MultiPart extends PartHeader
$headers = array(); $headers = array();
foreach ($this->headers as $fieldName => $value) { foreach ($this->headers as $fieldName => $value) {
if (in_array($fieldName, $allowed)) { if (in_array($fieldName, $allowed)) {
$fieldValue = ''; $fieldValue = $this->generateHeaderFieldValue($value);
if (is_array($value)) {
if (isset($value['@'])) {
$fieldValue .= $value['@'];
}
foreach ($value as $subName => $subValue) {
if ($subName != '@') {
$fieldValue .= '; ' . $subName . '="' . $subValue . '"';
}
}
} else {
$fieldValue .= $value;
}
// for http only ISO-8859-1 // for http only ISO-8859-1
$headers[] = $fieldName . ': '. iconv('utf-8', 'ISO-8859-1//TRANSLIT', $fieldValue); $headers[] = $fieldName . ': '. iconv('utf-8', 'ISO-8859-1//TRANSLIT', $fieldValue);
} }

View File

@ -92,6 +92,22 @@ abstract class PartHeader
); );
$headers = ''; $headers = '';
foreach ($this->headers as $fieldName => $value) { foreach ($this->headers as $fieldName => $value) {
$fieldValue = $this->generateHeaderFieldValue($value);
// do not use proper encoding as Apache Axis does not understand this
// $headers .= iconv_mime_encode($field_name, $field_value, $preferences) . "\r\n";
$headers .= $fieldName . ': ' . $fieldValue . "\r\n";
}
return $headers;
}
/**
* Generates a header field value from the given value paramater.
*
* @param array(string=>string)|string $value
* @return string
*/
protected function generateHeaderFieldValue($value)
{
$fieldValue = ''; $fieldValue = '';
if (is_array($value)) { if (is_array($value)) {
if (isset($value['@'])) { if (isset($value['@'])) {
@ -99,16 +115,28 @@ abstract class PartHeader
} }
foreach ($value as $subName => $subValue) { foreach ($value as $subName => $subValue) {
if ($subName != '@') { if ($subName != '@') {
$fieldValue .= '; ' . $subName . '=' . $subValue; $fieldValue .= '; ' . $subName . '=' . $this->quoteValueString($subValue);
} }
} }
} else { } else {
$fieldValue .= $value; $fieldValue .= $value;
} }
// do not use proper encoding as Apache Axis does not understand this return $fieldValue;
// $headers .= iconv_mime_encode($field_name, $field_value, $preferences) . "\r\n"; }
$headers .= $fieldName . ': ' . $fieldValue . "\r\n";
/**
* Quote string with '"' if it contains one of the special characters:
* "(" / ")" / "<" / ">" / "@" / "," / ";" / ":" / "\" / <"> / "/" / "[" / "]" / "?" / "="
*
* @param string $string
* @return string
*/
private function quoteValueString($string)
{
if (preg_match('~[()<>@,;:\\"/\[\]?=]~', $string)) {
return '"' . $string . '"';
} else {
return $string;
} }
return $headers;
} }
} }

View File

@ -0,0 +1,9 @@
<?php
namespace BeSimple\Tests\SoapCommon\Fixtures;
use BeSimple\SoapCommon\Mime\PartHeader;
class MimePartHeader extends PartHeader
{
}

View File

@ -0,0 +1,29 @@
HTTP/1.1 401 Authorization Required
Date: Fri, 12 Feb 2010 15:46:00 GMT
Server: Server
WWW-Authenticate: Basic realm="Realm"
Content-Length: 0
Cneonction: close
Content-Type: text/plain
HTTP/1.1 200 OK
Date: Fri, 12 Feb 2010 15:46:00 GMT
Server: Server
MIME-Version: 1.0
Cneonction: close
Transfer-Encoding: chunked
Content-Type: multipart/related; boundary="xxx-MIME-Boundary-xxx-0xa36cb38-0a36cb38-xxx-END-xxx"; type="text/xml"
--xxx-MIME-Boundary-xxx-0xa36cb38-0a36cb38-xxx-END-xxx
Content-Type: text/xml; charset="UTF-8"
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SE="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:doc href="cid:0x9d6ad00-0xa19ef48-0x9de7500-0xa4fae78-0xa382698" xmlns:ns1="http://myservice/schema/"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
--xxx-MIME-Boundary-xxx-0xa36cb38-0a36cb38-xxx-END-xxx
Content-ID: <0x9d6ad00-0xa19ef48-0x9de7500-0xa4fae78-0xa382698>
Content-Type: application/binary
<?xml version="1.0" encoding="UTF-8"?>
<XmlDocument><NoContent/></XmlDocument>
--xxx-MIME-Boundary-xxx-0xa36cb38-0a36cb38-xxx-END-xxx--

View File

@ -0,0 +1,13 @@
HTTP/1.1 200 OK
Date: Sat, 11 Sep 2010 12:52:57 GMT
Server: Simple-Server/1.1
Transfer-Encoding: chunked
Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_2DB7ABF3DC5BED7FA51284209577582; type="application/soap+xml"; start="<0.urn:uuid:2DB7ABF3DC5BED7FA51284209577583@apache.org>"; action="urn:getVersionResponse"
--MIMEBoundaryurn_uuid_2DB7ABF3DC5BED7FA51284209577582
Content-Type: application/soap+xml; charset=utf-8
Content-Transfer-Encoding: 8bit
Content-ID: <0.urn:uuid:2DB7ABF3DC5BED7FA51284209577583@apache.org>
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Action>urn:getVersionResponse</wsa:Action><wsa:RelatesTo>uuid:665aab53-4cef-4435-8934-4c10ed24fd42</wsa:RelatesTo></soapenv:Header><soapenv:Body><ns:getVersionResponse xmlns:ns="http://axisversion.sample"><ns:return>Hi - the Axis2 version is 1.5.1</ns:return></ns:getVersionResponse></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_2DB7ABF3DC5BED7FA51284209577582--

View File

@ -0,0 +1,22 @@
POST http://131.107.72.15/Mtom/svc/service.svc/Soap12MtomUTF8 HTTP/1.1
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7";start-info="application/soap+xml"
Host: 131.107.72.15
Content-Length: 1941
Expect: 100-continue
HTTP/1.1 100 Continue
--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://xmlsoap.org/echoBinaryAsString</a:Action><a:MessageID>urn:uuid:1bf061d6-d532-4b0c-930b-8b8202c38b8a</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://131.107.72.15/Mtom/svc/service.svc/Soap12MtomUTF8</a:To></s:Header><s:Body><EchoBinaryAsString xmlns="http://xmlsoap.org/Ping"><array><xop:Include href="cid:http%3A%2F%2Ftempuri.org%2F1%2F632618206527087310" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></array></EchoBinaryAsString></s:Body></s:Envelope>
--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7
Content-ID: <http://tempuri.org/1/632618206527087310>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream
H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d !
--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7--

View File

@ -0,0 +1,16 @@
--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://xmlsoap.org/echoBinaryAsString</a:Action><a:MessageID>urn:uuid:1bf061d6-d532-4b0c-930b-8b8202c38b8a</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://131.107.72.15/Mtom/svc/service.svc/Soap12MtomUTF8</a:To></s:Header><s:Body><EchoBinaryAsString xmlns="http://xmlsoap.org/Ping"><array><xop:Include href="cid:http%3A%2F%2Ftempuri.org%2F1%2F632618206527087310" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></array></EchoBinaryAsString></s:Body></s:Envelope>
--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7
Content-ID: <http://tempuri.org/1/632618206527087310>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream
H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d !
--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7--

View File

@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Content-Length: 1166
Via: 1.1 RED-PRXY-03
Date: Fri, 09 Sep 2005 06:57:22 GMT
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:b71dc628-ec8f-4422-8a4a-992f041cb94c+id=46";start-info="application/soap+xml"
--uuid:b71dc628-ec8f-4422-8a4a-992f041cb94c+id=46
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing"><s:Header><a:Action s:mustUnderstand="1">*</a:Action><a:RelatesTo>urn:uuid:1bf061d6-d532-4b0c-930b-8b8202c38b8a</a:RelatesTo><a:To s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:To></s:Header><s:Body><EchoBinaryAsStringResponse xmlns="http://xmlsoap.org/Ping"><EchoBinaryAsStringResult>Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!</EchoBinaryAsStringResult></EchoBinaryAsStringResponse></s:Body></s:Envelope>
--uuid:b71dc628-ec8f-4422-8a4a-992f041cb94c+id=46--

View File

@ -0,0 +1,144 @@
<?php
/*
* This file is part of the BeSimpleSoapBundle.
*
* (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\Tests\SoapCommon\Soap;
use BeSimple\SoapCommon\Mime\MultiPart;
use BeSimple\SoapCommon\Mime\Part;
use BeSimple\SoapCommon\Mime\PartHeader;
class MultiPartTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$mp = new MultiPart();
$this->assertEquals('1.0', $mp->getHeader('MIME-Version'));
$this->assertEquals('multipart/related', $mp->getHeader('Content-Type'));
$this->assertEquals('text/xml', $mp->getHeader('Content-Type', 'type'));
$this->assertEquals('utf-8', $mp->getHeader('Content-Type', 'charset'));
$this->assertRegExp('~urn:uuid:.*~', $mp->getHeader('Content-Type', 'boundary'));
}
public function testGetMimeMessage()
{
$mp = new MultiPart();
/*
string(51) "
--urn:uuid:a81ca327-591e-4656-91a1-8f177ada95b0--"
*/
$this->assertEquals(51, strlen($mp->getMimeMessage()));
$p = new Part('test');
$mp->addPart($p, true);
/*
string(259) "
--urn:uuid:a81ca327-591e-4656-91a1-8f177ada95b0
Content-Type: application/octet-stream; charset=utf-8
Content-Transfer-Encoding: binary
Content-ID: <urn:uuid:a0ad4376-5b08-4471-9f6f-c29aee881e84>
test
--urn:uuid:a81ca327-591e-4656-91a1-8f177ada95b0--"
*/
$this->assertEquals(259, strlen($mp->getMimeMessage()));
}
public function testGetMimeMessageWithHeaders()
{
$mp = new MultiPart();
/*
string(189) "MIME-Version: 1.0
Content-Type: multipart/related; type="text/xml"; charset=utf-8; boundary="urn:uuid:231833e2-a23b-410a-862e-250524fc38f6"
--urn:uuid:231833e2-a23b-410a-862e-250524fc38f6--"
*/
$this->assertEquals(193, strlen($mp->getMimeMessage(true)));
$p = new Part('test');
$mp->addPart($p, true);
/*
string(452) "MIME-Version: 1.0
Content-Type: multipart/related; type="text/xml"; charset=utf-8; boundary="urn:uuid:231833e2-a23b-410a-862e-250524fc38f6"; start="<urn:uuid:9389c081-56f7-4f57-b66e-c81892c3d4db>"
--urn:uuid:231833e2-a23b-410a-862e-250524fc38f6
Content-Type: application/octet-stream; charset=utf-8
Content-Transfer-Encoding: binary
Content-ID: <urn:uuid:9389c081-56f7-4f57-b66e-c81892c3d4db>
test
--urn:uuid:231833e2-a23b-410a-862e-250524fc38f6--"
*/
$this->assertEquals(458, strlen($mp->getMimeMessage(true)));
}
public function testGetHeadersForHttp()
{
$mp = new MultiPart();
$result = array(
'Content-Type: multipart/related; type="text/xml"; charset=utf-8; boundary="' . $mp->getHeader('Content-Type', 'boundary') . '"',
);
$this->assertEquals($result, $mp->getHeadersForHttp());
$result = array(
'Content-Type: multipart/related; type="text/xml"; charset=utf-8; boundary="' . $mp->getHeader('Content-Type', 'boundary') . '"',
'Content-Description: test',
);
$mp->setHeader('Content-Description', 'test');
$this->assertEquals($result, $mp->getHeadersForHttp());
}
public function testAddGetPart()
{
$mp = new MultiPart();
$p = new Part('test');
$p->setHeader('Content-ID', 'mycontentid');
$mp->addPart($p);
$this->assertEquals($p, $mp->getPart('mycontentid'));
}
public function testAddGetPartWithMain()
{
$mp = new MultiPart();
$p = new Part('test');
$mp->addPart($p, true);
$this->assertEquals($p, $mp->getPart());
}
public function testGetParts()
{
$mp = new MultiPart();
$p1 = new Part('test');
$mp->addPart($p1, true);
$p2 = new Part('test');
$mp->addPart($p2);
$withoutMain = array(
trim($p2->getHeader('Content-ID'),'<>') => $p2,
);
$this->assertEquals($withoutMain, $mp->getParts());
$withMain = array(
trim($p1->getHeader('Content-ID'),'<>') => $p1,
trim($p2->getHeader('Content-ID'),'<>') => $p2,
);
$this->assertEquals($withMain, $mp->getParts(true));
}
}

View File

@ -0,0 +1,153 @@
<?php
/*
* This file is part of the BeSimpleSoapBundle.
*
* (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\Tests\SoapCommon\Soap;
use BeSimple\SoapCommon\Mime\MultiPart;
use BeSimple\SoapCommon\Mime\Parser;
use BeSimple\SoapCommon\Mime\Part;
use BeSimple\SoapCommon\Mime\PartHeader;
class ParserTest extends \PHPUnit_Framework_TestCase
{
public function testParserRequestWsi()
{
$filename = dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures/WS-I-MTOM-request.txt';
$mimeMessage = file_get_contents($filename);
$mp = Parser::parseMimeMessage($mimeMessage);
$this->assertsForWsiMtomRequest($mp);
}
public function testParserResponseAmazon()
{
$filename = dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures/SwA-response-amazon.txt';
$mimeMessage = file_get_contents($filename);
$mp = Parser::parseMimeMessage($mimeMessage);
$this->assertEquals('Fri, 12 Feb 2010 15:46:00 GMT', $mp->getHeader('Date'));
$this->assertEquals('Server', $mp->getHeader('Server'));
$this->assertEquals('1.0', $mp->getHeader('MIME-Version'));
$this->assertEquals('close', $mp->getHeader('Cneonction'));
$this->assertEquals('chunked', $mp->getHeader('Transfer-Encoding'));
$this->assertEquals('multipart/related', $mp->getHeader('Content-Type'));
$this->assertEquals('text/xml', $mp->getHeader('Content-Type', 'type'));
$this->assertEquals('utf-8', $mp->getHeader('Content-Type', 'charset'));
$this->assertEquals('xxx-MIME-Boundary-xxx-0xa36cb38-0a36cb38-xxx-END-xxx', $mp->getHeader('Content-Type', 'boundary'));
$p1 = $mp->getPart();
$this->assertEquals('text/xml', $p1->getHeader('Content-Type'));
$this->assertEquals('UTF-8', $p1->getHeader('Content-Type', 'charset'));
$this->assertEquals(389, strlen($p1->getContent()));
$p2 = $mp->getPart('0x9d6ad00-0xa19ef48-0x9de7500-0xa4fae78-0xa382698');
$this->assertEquals('binary', $p2->getHeader('Content-Transfer-Encoding'));
$this->assertEquals('application/binary', $p2->getHeader('Content-Type'));
$this->assertEquals(81, strlen($p2->getContent()));
}
public function testParserResponseAxis()
{
$filename = dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures/SwA-response-axis.txt';
$mimeMessage = file_get_contents($filename);
$mp = Parser::parseMimeMessage($mimeMessage);
$this->assertEquals('Sat, 11 Sep 2010 12:52:57 GMT', $mp->getHeader('Date'));
$this->assertEquals('Simple-Server/1.1', $mp->getHeader('Server'));
$this->assertEquals('1.0', $mp->getHeader('MIME-Version'));
$this->assertEquals('chunked', $mp->getHeader('Transfer-Encoding'));
$this->assertEquals('multipart/related', $mp->getHeader('Content-Type'));
$this->assertEquals('application/soap+xml', $mp->getHeader('Content-Type', 'type'));
$this->assertEquals('utf-8', $mp->getHeader('Content-Type', 'charset'));
$this->assertEquals('<0.urn:uuid:2DB7ABF3DC5BED7FA51284209577583@apache.org>', $mp->getHeader('Content-Type', 'start'));
$this->assertEquals('urn:getVersionResponse', $mp->getHeader('Content-Type', 'action'));
$this->assertEquals('MIMEBoundaryurn_uuid_2DB7ABF3DC5BED7FA51284209577582', $mp->getHeader('Content-Type', 'boundary'));
$p1 = $mp->getPart('0.urn:uuid:2DB7ABF3DC5BED7FA51284209577583@apache.org');
$this->assertEquals('8bit', $p1->getHeader('Content-Transfer-Encoding'));
$this->assertEquals('application/soap+xml', $p1->getHeader('Content-Type'));
$this->assertEquals('utf-8', $p1->getHeader('Content-Type', 'charset'));
$this->assertEquals(499, strlen($p1->getContent()));
}
public function testParserResponseWsi()
{
$filename = dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures/WS-I-MTOM-response.txt';
$mimeMessage = file_get_contents($filename);
$mp = Parser::parseMimeMessage($mimeMessage);
$this->assertEquals('Keep-Alive', $mp->getHeader('Proxy-Connection'));
$this->assertEquals('Keep-Alive', $mp->getHeader('Connection'));
$this->assertEquals('1166', $mp->getHeader('Content-Length'));
$this->assertEquals('1.1 RED-PRXY-03', $mp->getHeader('Via'));
$this->assertEquals('Fri, 09 Sep 2005 06:57:22 GMT', $mp->getHeader('Date'));
$this->assertEquals('multipart/related', $mp->getHeader('Content-Type'));
$this->assertEquals('application/xop+xml', $mp->getHeader('Content-Type', 'type'));
$this->assertEquals('utf-8', $mp->getHeader('Content-Type', 'charset'));
$this->assertEquals('<http://tempuri.org/0>', $mp->getHeader('Content-Type', 'start'));
$this->assertEquals('application/soap+xml', $mp->getHeader('Content-Type', 'start-info'));
$this->assertEquals('uuid:b71dc628-ec8f-4422-8a4a-992f041cb94c+id=46', $mp->getHeader('Content-Type', 'boundary'));
$p1 = $mp->getPart('http://tempuri.org/0');
$this->assertEquals('8bit', $p1->getHeader('Content-Transfer-Encoding'));
$this->assertEquals('application/xop+xml', $p1->getHeader('Content-Type'));
$this->assertEquals('utf-8', $p1->getHeader('Content-Type', 'charset'));
$this->assertEquals('application/soap+xml', $p1->getHeader('Content-Type', 'type'));
$this->assertEquals(910, strlen($p1->getContent()));
}
public function testParserWithHeaderArray()
{
$filename = dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures/WS-I-MTOM-request_noheader.txt';
$mimeMessage = file_get_contents($filename);
$headers = array(
'Content-Type' => 'multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7";start-info="application/soap+xml"',
'Content-Length' => 1941,
'Host' => '131.107.72.15',
'Expect' => '100-continue',
);
$mp = Parser::parseMimeMessage($mimeMessage, $headers);
$this->assertsForWsiMtomRequest($mp);
}
/*
* used in:
* - testParserWithHeaderArray
* - testParserRequestWsi
*/
private function assertsForWsiMtomRequest(MultiPart $mp)
{
$this->assertEquals('multipart/related', $mp->getHeader('Content-Type'));
$this->assertEquals('application/xop+xml', $mp->getHeader('Content-Type', 'type'));
$this->assertEquals('utf-8', $mp->getHeader('Content-Type', 'charset'));
$this->assertEquals('<http://tempuri.org/0>', $mp->getHeader('Content-Type', 'start'));
$this->assertEquals('application/soap+xml', $mp->getHeader('Content-Type', 'start-info'));
$this->assertEquals('uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7', $mp->getHeader('Content-Type', 'boundary'));
$this->assertEquals('1941', $mp->getHeader('Content-Length'));
$this->assertEquals('131.107.72.15', $mp->getHeader('Host'));
$this->assertEquals('100-continue', $mp->getHeader('Expect'));
$p1 = $mp->getPart('http://tempuri.org/0');
$this->assertEquals('8bit', $p1->getHeader('Content-Transfer-Encoding'));
$this->assertEquals('application/xop+xml', $p1->getHeader('Content-Type'));
$this->assertEquals('utf-8', $p1->getHeader('Content-Type', 'charset'));
$this->assertEquals('application/soap+xml', $p1->getHeader('Content-Type', 'type'));
$this->assertEquals(737, strlen($p1->getContent()));
$p2 = $mp->getPart('http://tempuri.org/1/632618206527087310');
$this->assertEquals('binary', $p2->getHeader('Content-Transfer-Encoding'));
$this->assertEquals('application/octet-stream', $p2->getHeader('Content-Type'));
$this->assertEquals(769, strlen($p2->getContent()));
}
}

View File

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the BeSimpleSoapBundle.
*
* (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\Tests\SoapCommon\Soap;
use BeSimple\SoapCommon\Mime\PartHeader;
use BeSimple\Tests\SoapCommon\Fixtures\MimePartHeader;
class PartHeaderTest extends \PHPUnit_Framework_TestCase
{
public function testSetGetHeader()
{
$ph = new MimePartHeader();
$ph->setHeader('Content-Type', 'text/xml');
$this->assertEquals('text/xml', $ph->getHeader('Content-Type'));
}
public function testSetGetHeaderSubvalue()
{
$ph = new MimePartHeader();
$ph->setHeader('Content-Type', 'utf-8', 'charset');
$this->assertEquals(null, $ph->getHeader('Content-Type', 'charset'));
$ph->setHeader('Content-Type', 'text/xml');
$ph->setHeader('Content-Type', 'charset', 'utf-8');
$this->assertEquals('utf-8', $ph->getHeader('Content-Type', 'charset'));
}
public function testGenerateHeaders()
{
$ph = new MimePartHeader();
$class = new \ReflectionClass($ph);
$method = $class->getMethod('generateHeaders');
$method->setAccessible(true);
$this->assertEquals('', $method->invoke($ph));
$ph->setHeader('Content-Type', 'text/xml');
$this->assertEquals("Content-Type: text/xml\r\n", $method->invoke($ph));
$ph->setHeader('Content-Type', 'charset', 'utf-8');
$this->assertEquals("Content-Type: text/xml; charset=utf-8\r\n", $method->invoke($ph));
$ph->setHeader('Content-Type', 'type', 'text/xml');
$this->assertEquals("Content-Type: text/xml; charset=utf-8; type=\"text/xml\"\r\n", $method->invoke($ph));
}
}

View File

@ -0,0 +1,62 @@
<?php
/*
* This file is part of the BeSimpleSoapBundle.
*
* (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\Tests\SoapCommon\Soap;
use BeSimple\SoapCommon\Mime\Part;
use BeSimple\SoapCommon\Mime\PartHeader;
class PartTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$p = new Part('<xml1/>', 'text/xml', 'utf-8', Part::ENCODING_BINARY, 'urn:myuniqueresource');
$this->assertEquals('<xml1/>', $p->getContent());
$this->assertEquals('text/xml', $p->getHeader('Content-Type'));
$this->assertEquals('utf-8', $p->getHeader('Content-Type', 'charset'));
$this->assertEquals(Part::ENCODING_BINARY, $p->getHeader('Content-Transfer-Encoding'));
$this->assertEquals('<urn:myuniqueresource>', $p->getHeader('Content-ID'));
}
public function testDefaultConstructor()
{
$p = new Part();
$this->assertNull($p->getContent());
$this->assertEquals('application/octet-stream', $p->getHeader('Content-Type'));
$this->assertEquals('utf-8', $p->getHeader('Content-Type', 'charset'));
$this->assertEquals(Part::ENCODING_BINARY, $p->getHeader('Content-Transfer-Encoding'));
$this->assertRegExp('~<urn:uuid:.*>~', $p->getHeader('Content-ID'));
}
public function testSetContent()
{
$p = new Part();
$p->setContent('<xml1/>');
$this->assertEquals('<xml1/>', $p->getContent());
}
public function testGetMessagePart()
{
$p = new Part('<xml1/>', 'text/xml', 'utf-8', Part::ENCODING_BINARY, 'urn:myuniqueresource');
$messagePart = "Content-Type: text/xml; charset=utf-8\r\n" .
"Content-Transfer-Encoding: binary\r\n" .
"Content-ID: <urn:myuniqueresource>\r\n" .
"\r\n".
"<xml1/>";
$this->assertEquals($messagePart, $p->getMessagePart());
}
}