summaryrefslogtreecommitdiff
path: root/tests/simple_unit/Soap/SoapTestCase.php
blob: 78a6875b36fe0cbb1a5423484b18841ca00454b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php

ini_set("soap.wsdl_cache_enabled",0);

require_once(dirname(__FILE__).'/ContactManager.php');

class SoapTestCase extends UnitTestCase
{
	function getWsdlUri()
	{
		$script = str_replace('unit.php', 'ws.php',$_SERVER['SCRIPT_NAME']);
		return "http://".$_SERVER['HTTP_HOST'].$script.'?soap=contacts.wsdl';
	}

	function getClient()
	{
		return new SoapClient($this->getWsdlUri());
	}

	function testContactArray()
	{
		$result = $this->getClient()->getContacts();
		$this->assertEqual(count($result), 1);
		$obj = $result[0];
		$this->assertEqual($obj->name, "me");
		$this->assertEqual($obj->id, 1);
		$this->assertEqual($obj->address->street, "sesamstreet");
		$this->assertNull($obj->address->nr);
		$this->assertNull($obj->address->zipcode);
		$this->assertEqual($obj->address->city, "sesamcity");
		$this->assertEqual($obj->email, "me@you.com");
	}

	function testGetContactThrowsException()
	{
		try
		{
			$result = $this->getClient()->getContact(1);	
			$this->fail();
		}
		catch (SoapFault $f)
		{
			$this->pass();
		}
	}

	function testGetNewContact()
	{
		$obj = $this->getClient()->newContact();
		$this->assertNull($obj->name);
		$this->assertNull($obj->id);
		$this->assertNull($obj->address);
		$this->assertNull($obj->email);
	}

	function testSaveContactReturnsTrue()
	{
		$c = new Contact;
		$result = $this->getClient()->saveContact($c);
		$this->assertTrue($result);
	}

	function getMixedArray()
	{
		$result = $this->getClient()>getList();
		$expected = array(array(1,2), array("12", 1.2));
		$this->assertEqual($result, $expected);
	}

	function testEmptyArray()
	{
		$result = $this->getClient()->getEmptyArray();
		$this->assertTrue(is_array($result));
		$this->assertEqual(count($result), 0);
	}

	function testUnknownFunctionThrowsException()
	{
		try
		{
			$this->getClient()->test();
			$this->fail();
		}
		catch (SoapFault $f)
		{
			$this->pass();
		}
	}
}

?>