From 375cd7debbdd4157572402d860d7c3c9d8d16461 Mon Sep 17 00:00:00 2001 From: Andreas Schamberger Date: Sun, 15 Jan 2012 11:42:21 +0100 Subject: [PATCH 1/4] CS --- .../Tests/SoapClient/WsdlDownloaderTest.php | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tests/BeSimple/Tests/SoapClient/WsdlDownloaderTest.php b/tests/BeSimple/Tests/SoapClient/WsdlDownloaderTest.php index 14ac58a..198341d 100644 --- a/tests/BeSimple/Tests/SoapClient/WsdlDownloaderTest.php +++ b/tests/BeSimple/Tests/SoapClient/WsdlDownloaderTest.php @@ -24,11 +24,12 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase protected function startPhpWebserver() { - if ('Windows' == substr(php_uname('s'), 0, 7 )) { - $powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;"; + $dir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures'; + if ('Windows' == substr(php_uname('s'), 0, 7)) { + $powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".$dir."' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;"; $shellCommand = 'powershell -command "& {'.$powershellCommand.'}"'; } else { - $shellCommand = "nohup php -S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures &"; + $shellCommand = "nohup php -S localhost:8000 -t ".$dir." &"; } $output = array(); exec($shellCommand, $output); @@ -38,7 +39,7 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase protected function stopPhpWebserver() { if (!is_null($this->webserverProcessId)) { - if ('Windows' == substr(php_uname('s'), 0, 7 )) { + if ('Windows' == substr(php_uname('s'), 0, 7)) { exec('TASKKILL /F /PID ' . $this->webserverProcessId); } else { exec('kill ' . $this->webserverProcessId); @@ -57,7 +58,7 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase $cacheDir = ini_get('soap.wsdl_cache_dir'); if (!is_dir($cacheDir)) { $cacheDir = sys_get_temp_dir(); - $cacheDirForRegExp = preg_quote( $cacheDir ); + $cacheDirForRegExp = preg_quote($cacheDir); } $tests = array( @@ -82,7 +83,7 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase foreach ($tests as $name => $values) { $cacheFileName = $wd->download($values['source']); $result = file_get_contents($cacheFileName); - $this->assertRegExp($values['assertRegExp'],$result,$name); + $this->assertRegExp($values['assertRegExp'], $result, $name); unlink($cacheFileName); } @@ -129,7 +130,7 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase $cacheDir = ini_get('soap.wsdl_cache_dir'); if (!is_dir($cacheDir)) { $cacheDir = sys_get_temp_dir(); - $cacheDirForRegExp = preg_quote( $cacheDir ); + $cacheDirForRegExp = preg_quote($cacheDir); } $remoteUrlAbsolute = 'http://localhost:8000/wsdlinclude/wsdlinctest_absolute.xml'; @@ -162,10 +163,10 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase ); foreach ($tests as $name => $values) { - $wsdl = file_get_contents( $values['source'] ); - $method->invoke($wd, $wsdl, $values['cacheFile'],$values['remoteParentUrl']); + $wsdl = file_get_contents($values['source']); + $method->invoke($wd, $wsdl, $values['cacheFile'], $values['remoteParentUrl']); $result = file_get_contents($values['cacheFile']); - $this->assertRegExp($values['assertRegExp'],$result,$name); + $this->assertRegExp($values['assertRegExp'], $result, $name); unlink($values['cacheFile']); } @@ -186,7 +187,7 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase $cacheDir = ini_get('soap.wsdl_cache_dir'); if (!is_dir($cacheDir)) { $cacheDir = sys_get_temp_dir(); - $cacheDirForRegExp = preg_quote( $cacheDir ); + $cacheDirForRegExp = preg_quote($cacheDir); } $remoteUrlAbsolute = 'http://localhost:8000/xsdinclude/xsdinctest_absolute.xml'; @@ -219,10 +220,10 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase ); foreach ($tests as $name => $values) { - $wsdl = file_get_contents( $values['source'] ); - $method->invoke($wd, $wsdl, $values['cacheFile'],$values['remoteParentUrl']); + $wsdl = file_get_contents($values['source']); + $method->invoke($wd, $wsdl, $values['cacheFile'], $values['remoteParentUrl']); $result = file_get_contents($values['cacheFile']); - $this->assertRegExp($values['assertRegExp'],$result,$name); + $this->assertRegExp($values['assertRegExp'], $result, $name); unlink($values['cacheFile']); } From f0b596be99820082ed23c9402c28eb4de2b7fb75 Mon Sep 17 00:00:00 2001 From: Andreas Schamberger Date: Sun, 15 Jan 2012 11:44:05 +0100 Subject: [PATCH 2/4] CS --- tests/BeSimple/Tests/SoapClient/CurlTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/BeSimple/Tests/SoapClient/CurlTest.php b/tests/BeSimple/Tests/SoapClient/CurlTest.php index b940b2a..d669f4c 100644 --- a/tests/BeSimple/Tests/SoapClient/CurlTest.php +++ b/tests/BeSimple/Tests/SoapClient/CurlTest.php @@ -23,11 +23,12 @@ class CurlTest extends \PHPUnit_Framework_TestCase protected function startPhpWebserver() { - if ('Windows' == substr(php_uname('s'), 0, 7 )) { - $powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;"; + $dir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures'; + if ('Windows' == substr(php_uname('s'), 0, 7)) { + $powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".$dir."' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;"; $shellCommand = 'powershell -command "& {'.$powershellCommand.'}"'; } else { - $shellCommand = "nohup php -S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures &"; + $shellCommand = "nohup php -S localhost:8000 -t ".$dir." &"; } $output = array(); exec($shellCommand, $output); From 107a2904c1adc95298b061d19ac02da475baf6cf Mon Sep 17 00:00:00 2001 From: Andreas Schamberger Date: Sun, 29 Jan 2012 14:38:12 +0100 Subject: [PATCH 3/4] add XML mime filter --- src/BeSimple/SoapClient/SoapClient.php | 2 + src/BeSimple/SoapClient/XmlMimeFilter.php | 75 +++++++++++++++++++++++ tests/AxisInterop/MTOM.php | 27 +++++++- tests/AxisInterop/MTOM.wsdl | 4 +- tests/bootstrap.php | 2 +- 5 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 src/BeSimple/SoapClient/XmlMimeFilter.php diff --git a/src/BeSimple/SoapClient/SoapClient.php b/src/BeSimple/SoapClient/SoapClient.php index 90d8f1d..afa6515 100644 --- a/src/BeSimple/SoapClient/SoapClient.php +++ b/src/BeSimple/SoapClient/SoapClient.php @@ -277,6 +277,8 @@ class SoapClient extends \SoapClient $converter = new SwaTypeConverter(); $converter->setKernel($this->soapKernel); } elseif (Helper::ATTACHMENTS_TYPE_MTOM === $options['attachment_type']) { + $xmlMimeFilter = new XmlMimeFilter($options['attachment_type']); + $this->soapKernel->registerFilter($xmlMimeFilter); $converter = new MtomTypeConverter(); $converter->setKernel($this->soapKernel); } diff --git a/src/BeSimple/SoapClient/XmlMimeFilter.php b/src/BeSimple/SoapClient/XmlMimeFilter.php new file mode 100644 index 0000000..142a271 --- /dev/null +++ b/src/BeSimple/SoapClient/XmlMimeFilter.php @@ -0,0 +1,75 @@ + + * (c) Francis Besset + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapClient; + +use BeSimple\SoapCommon\FilterHelper; +use BeSimple\SoapCommon\Helper; +use BeSimple\SoapCommon\Mime\MultiPart as MimeMultiPart; +use BeSimple\SoapCommon\Mime\Parser as MimeParser; +use BeSimple\SoapCommon\Mime\Part as MimePart; +use BeSimple\SoapCommon\SoapRequest; +use BeSimple\SoapCommon\SoapRequestFilter; +use BeSimple\SoapCommon\SoapResponse; +use BeSimple\SoapCommon\SoapResponseFilter; + +/** + * XML MIME filter that fixes the namespace of xmime:contentType attribute. + * + * @author Andreas Schamberger + */ +class XmlMimeFilter implements SoapRequestFilter +{ + /** + * Reset all properties to default values. + */ + public function resetFilter() + { + } + + /** + * Modify the given request XML. + * + * @param \BeSimple\SoapCommon\SoapRequest $request SOAP request + * + * @return void + */ + public function filterRequest(SoapRequest $request) + { + // get \DOMDocument from SOAP request + $dom = $request->getContentDocument(); + + // create FilterHelper + $filterHelper = new FilterHelper($dom); + + // add the neccessary namespaces + $filterHelper->addNamespace(Helper::PFX_XMLMIME, Helper::NS_XMLMIME); + + // get xsd:base64binary elements + $xpath = new \DOMXPath($dom); + $xpath->registerNamespace('XOP', Helper::NS_XOP); + $query = '//XOP:Include/..'; + $nodes = $xpath->query($query); + + // exchange attributes + if ($nodes->length > 0) { + foreach ($nodes as $node) { + if ($node->hasAttribute('contentType')) { + $contentType = $node->getAttribute('contentType'); + $node->removeAttribute('contentType'); + $filterHelper->setAttribute($node, Helper::NS_XMLMIME, 'contentType', $contentType); + } + } + } + + } +} \ No newline at end of file diff --git a/tests/AxisInterop/MTOM.php b/tests/AxisInterop/MTOM.php index cbfe886..2579c1d 100644 --- a/tests/AxisInterop/MTOM.php +++ b/tests/AxisInterop/MTOM.php @@ -7,12 +7,32 @@ require '../bootstrap.php'; echo '
';
 
+class base64Binary
+{
+    public $_;
+    public $contentType;
+}
+
+class AttachmentType
+{
+    public $fileName;
+    public $binaryData;
+}
+
+class AttachmentRequest extends AttachmentType
+{
+}
+
 $options = array(
     'soap_version'    => SOAP_1_1,
     'features'        => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
     'trace'           => true, // enables use of the methods  SoapClient->__getLastRequest,  SoapClient->__getLastRequestHeaders,  SoapClient->__getLastResponse and  SoapClient->__getLastResponseHeaders
     'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
     'cache_wsdl'      => WSDL_CACHE_NONE,
+    'classmap'        => array(
+        'base64Binary'      => 'base64Binary',
+        'AttachmentRequest' => 'AttachmentRequest',
+    ),
 );
 
 /*
@@ -28,10 +48,13 @@ $sc = new BeSimpleSoapClient('MTOM.wsdl', $options);
 //var_dump($sc->__getTypes());
 
 try {
+    $b64 = new base64Binary();
+    $b64->_ = 'This is a test. :)';
+    $b64->contentType = 'text/plain';
 
-    $attachment = new stdClass();
+    $attachment = new AttachmentRequest();
     $attachment->fileName = 'test123.txt';
-    $attachment->binaryData = 'This is a test.';
+    $attachment->binaryData = $b64;
 
     var_dump($sc->attachment($attachment));
 
diff --git a/tests/AxisInterop/MTOM.wsdl b/tests/AxisInterop/MTOM.wsdl
index 178ee35..f0c9a6d 100644
--- a/tests/AxisInterop/MTOM.wsdl
+++ b/tests/AxisInterop/MTOM.wsdl
@@ -80,10 +80,10 @@
   
   
     
-      
+      
     
     
-      
+      
     
   
 
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index d2872c6..2fa215e 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -26,7 +26,7 @@ spl_autoload_register(function($class) {
             return true;
         }
     } elseif (0 === strpos($class, 'BeSimple\SoapCommon\\')) {
-        $path = __DIR__.'/../vendor/besimple-soapcommon/src/'.($class = strtr($class, '\\', '/')).'.php';
+        $path = __DIR__.'/../../BeSimpleSoapCommon/src/'.($class = strtr($class, '\\', '/')).'.php';
         if (file_exists($path) && is_readable($path)) {
             require_once $path;
 

From 3954d071121b6d1ea7f4717f188a991c6c33cb22 Mon Sep 17 00:00:00 2001
From: Andreas Schamberger 
Date: Sun, 29 Jan 2012 17:46:39 +0100
Subject: [PATCH 4/4] fixed broken bootstrap

---
 tests/bootstrap.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 2fa215e..d2872c6 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -26,7 +26,7 @@ spl_autoload_register(function($class) {
             return true;
         }
     } elseif (0 === strpos($class, 'BeSimple\SoapCommon\\')) {
-        $path = __DIR__.'/../../BeSimpleSoapCommon/src/'.($class = strtr($class, '\\', '/')).'.php';
+        $path = __DIR__.'/../vendor/besimple-soapcommon/src/'.($class = strtr($class, '\\', '/')).'.php';
         if (file_exists($path) && is_readable($path)) {
             require_once $path;