summaryrefslogtreecommitdiff
path: root/tests/unit/Soap/SoapTest.php
blob: 994c1175d12f9c0f5c56a0654db3e120727760dd (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
92
93
<?php

ini_set("soap.wsdl_cache_enabled",0);

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

/**
 * @package System.Soap
 */
class SoapTestCase extends PHPUnit_Framework_TestCase
{
	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->assertEquals(count($result), 1);
		$obj = $result->Contact;
		$this->assertEquals($obj->name, "me");
		$this->assertEquals($obj->id, 1);
		$this->assertEquals($obj->address->street, "sesamstreet");
		$this->assertNull($obj->address->nr);
		$this->assertNull($obj->address->zipcode);
		$this->assertEquals($obj->address->city, "sesamcity");
		$this->assertEquals($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->assertEquals($result, $expected);
	}

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

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