Skip to content

Commit 385045a

Browse files
committed
Initial XML support added
0 parents  commit 385045a

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
use Codeception\Util\Stub;
4+
use Codeception\Util\Soap as SoapUtil;
5+
6+
class SoapTest extends \PHPUnit_Framework_TestCase
7+
{
8+
9+
/**
10+
* @var \Codeception\Module\Soap
11+
*/
12+
protected $module = null;
13+
14+
protected $layout;
15+
16+
public function setUp() {
17+
$this->module = new \Codeception\Module\Soap();
18+
$this->module->_setConfig(array('schema' => 'http://www.w3.org/2001/xml.xsd', 'endpoint' => 'http://codeception.com/api/wsdl'));
19+
$this->layout = \Codeception\Configuration::dataDir().'/xml/layout.xml';
20+
$this->module->client = Stub::makeEmpty('\Behat\Mink\Driver\Goutte\Client');
21+
$this->module->_before(Stub::makeEmpty('\Codeception\TestCase\Cest'));
22+
}
23+
24+
public function testXmlIsBuilt() {
25+
$this->module->xmlRequest;
26+
$dom = new \DOMDocument();
27+
$dom->load($this->layout);
28+
$this->assertEqualXMLStructure($this->module->xmlRequest->documentElement, $dom->documentElement);
29+
$this->assertXmlStringEqualsXmlString($dom->saveXML(), $this->module->xmlRequest->saveXML());
30+
}
31+
32+
public function testBuildHeaders() {
33+
$this->module->haveSoapHeader('AuthHeader', array('username' => 'davert', 'password' => '123456'));
34+
$dom = new \DOMDocument();
35+
$dom->load($this->layout);
36+
$header = $dom->createElement('AuthHeader');
37+
$header->appendChild($dom->createElement('username','davert'));
38+
$header->appendChild($dom->createElement('password','123456'));
39+
$dom->documentElement->getElementsByTagName('Header')->item(0)->appendChild($header);
40+
$this->assertEqualXMLStructure($this->module->xmlRequest->documentElement, $dom->documentElement);
41+
}
42+
43+
public function testBuildRequest()
44+
{
45+
$this->module->sendSoapRequest('KillHumans', "<item><id>1</id><subitem>2</subitem></item>");
46+
$this->assertNotNull($this->module->xmlRequest);
47+
$dom = new \DOMDocument();
48+
$dom->load($this->layout);
49+
$body = $dom->createElement('item');
50+
$body->appendChild($dom->createElement('id',1));
51+
$body->appendChild($dom->createElement('subitem',2));
52+
$request = $dom->createElement('ns:KillHumans');
53+
$request->appendChild($body);
54+
$dom->documentElement->getElementsByTagName('Body')->item(0)->appendChild($request);
55+
$this->assertEqualXMLStructure($this->module->xmlRequest->documentElement, $dom->documentElement);
56+
}
57+
58+
public function testBuildRequestWithDomNode() {
59+
$dom = new \DOMDocument();
60+
$dom->load($this->layout);
61+
$body = $dom->createElement('item');
62+
$body->appendChild($dom->createElement('id',1));
63+
$body->appendChild($dom->createElement('subitem',2));
64+
$request = $dom->createElement('ns:KillHumans');
65+
$request->appendChild($body);
66+
$dom->documentElement->getElementsByTagName('Body')->item(0)->appendChild($request);
67+
68+
$this->module->sendSoapRequest('KillHumans', $body);
69+
$this->assertEqualXMLStructure($this->module->xmlRequest->documentElement, $dom->documentElement);
70+
}
71+
72+
public function testSeeXmlIncludes() {
73+
$dom = new DOMDocument();
74+
$this->module->xmlResponse = $dom;
75+
$dom->loadXML('<?xml version="1.0" encoding="UTF-8"?> <doc> <a a2="2" a1="1" >123</a> </doc>');
76+
$this->module->seeSoapResponseIncludes('<a a2="2" a1="1" >123</a>');
77+
}
78+
79+
public function testSeeXmlEquals() {
80+
$dom = new DOMDocument();
81+
$this->module->xmlResponse = $dom;
82+
$xml = '<?xml version="1.0" encoding="UTF-8"?> <doc> <a a2="2" a1="1" >123</a> </doc>';
83+
$dom->loadXML($xml);
84+
$this->module->seeSoapResponseEquals($xml);
85+
}
86+
87+
public function testSeeXmlIncludesWithBuilder() {
88+
$dom = new DOMDocument();
89+
$this->module->xmlResponse = $dom;
90+
$dom->loadXML('<?xml version="1.0" encoding="UTF-8"?>'."\n".' <doc><a a2="2" a1="1" >123</a></doc>');
91+
$xml = SoapUtil::request()->doc->a
92+
->attr('a2','2')
93+
->attr('a1','1')
94+
->val('123');
95+
$this->module->seeSoapResponseIncludes($xml);
96+
}
97+
98+
}

0 commit comments

Comments
 (0)