Commit | Line | Data |
---|---|---|
8991c9d5 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
8991c9d5 | 5 | | | |
7d61e75f TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
8991c9d5 TO |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * Verify that the SOAP bindings correctly parse and authenticate requests. | |
14 | * @group e2e | |
15 | */ | |
16 | class E2E_Extern_SoapTest extends CiviEndToEndTestCase { | |
17 | ||
18 | /** | |
19 | * @var string | |
20 | */ | |
39b959db SL |
21 | public $url; |
22 | ||
23 | /** | |
24 | * @var string | |
25 | */ | |
26 | public $adminUser; | |
27 | ||
28 | /** | |
29 | * @var string | |
30 | */ | |
31 | public $adminPass; | |
8991c9d5 TO |
32 | |
33 | public function setUp() { | |
34 | CRM_Core_Config::singleton(1, 1); | |
35 | ||
36 | global $_CV; | |
37 | $this->adminUser = $_CV['ADMIN_USER']; | |
38 | $this->adminPass = $_CV['ADMIN_PASS']; | |
39 | $this->url = CRM_Core_Resources::singleton()->getUrl('civicrm', 'extern/soap.php'); | |
40 | ||
41 | foreach (array('adminUser', 'adminPass', 'url') as $prop) { | |
42 | if (empty($this->{$prop})) { | |
43 | $this->markTestSkipped("Failed to lookup SOAP URL, user, or password. Have you configured `cv` for testing?"); | |
44 | } | |
45 | } | |
46 | } | |
47 | ||
48 | /** | |
49 | * Send a request with bad credentials. | |
50 | * | |
51 | * @expectedException SoapFault | |
52 | */ | |
53 | public function testAuthenticationBadPassword() { | |
54 | $client = $this->createClient(); | |
55 | $client->authenticate($this->adminUser, mt_rand()); | |
56 | } | |
57 | ||
58 | /** | |
59 | * Send a request with bad credentials. | |
60 | * | |
61 | * @expectedException SoapFault | |
62 | */ | |
63 | public function testAuthenticationBadKey() { | |
64 | $client = $this->createClient(); | |
65 | $key = $client->authenticate($this->adminUser, $this->adminPass); | |
affcc9d2 | 66 | $client->get_contact(mt_rand(), []); |
8991c9d5 TO |
67 | } |
68 | ||
69 | /** | |
70 | * A basic test for one SOAP function. | |
71 | */ | |
72 | public function testGetContact() { | |
73 | $client = $this->createClient(); | |
74 | $key = $client->authenticate($this->adminUser, $this->adminPass); | |
75 | $contacts = $client->get_contact($key, array( | |
76 | 'contact_id' => 101, | |
77 | 'return.display_name' => 1, | |
78 | )); | |
79 | $this->assertEquals($contacts['is_error'], 0); | |
80 | $this->assertEquals($contacts['count'], 1); | |
81 | $this->assertEquals($contacts['values'][101]['contact_id'], 101); | |
82 | } | |
83 | ||
84 | /** | |
85 | * @return \SoapClient | |
86 | */ | |
87 | protected function createClient() { | |
88 | return new SoapClient(NULL, array( | |
39b959db SL |
89 | 'location' => $this->url, |
90 | 'uri' => 'urn:civicrm', | |
91 | 'trace' => 1, | |
92 | )); | |
8991c9d5 TO |
93 | } |
94 | ||
95 | } |