Merge pull request #16574 from civicrm/5.23
[civicrm-core.git] / tests / phpunit / E2E / Extern / SoapTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
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 */
21 public $url;
22
23 /**
24 * @var string
25 */
26 public $adminUser;
27
28 /**
29 * @var string
30 */
31 public $adminPass;
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);
66 $client->get_contact(mt_rand(), array());
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(
89 'location' => $this->url,
90 'uri' => 'urn:civicrm',
91 'trace' => 1,
92 ));
93 }
94
95 }