Merge pull request #14133 from civicrm/5.13
[civicrm-core.git] / tests / phpunit / E2E / Extern / SoapTest.php
CommitLineData
8991c9d5
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
8991c9d5 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
8991c9d5
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27/**
28 * Verify that the SOAP bindings correctly parse and authenticate requests.
29 * @group e2e
30 */
31class E2E_Extern_SoapTest extends CiviEndToEndTestCase {
32
33 /**
34 * @var string
35 */
39b959db
SL
36 public $url;
37
38 /**
39 * @var string
40 */
41 public $adminUser;
42
43 /**
44 * @var string
45 */
46 public $adminPass;
8991c9d5
TO
47
48 public function setUp() {
49 CRM_Core_Config::singleton(1, 1);
50
51 global $_CV;
52 $this->adminUser = $_CV['ADMIN_USER'];
53 $this->adminPass = $_CV['ADMIN_PASS'];
54 $this->url = CRM_Core_Resources::singleton()->getUrl('civicrm', 'extern/soap.php');
55
56 foreach (array('adminUser', 'adminPass', 'url') as $prop) {
57 if (empty($this->{$prop})) {
58 $this->markTestSkipped("Failed to lookup SOAP URL, user, or password. Have you configured `cv` for testing?");
59 }
60 }
61 }
62
63 /**
64 * Send a request with bad credentials.
65 *
66 * @expectedException SoapFault
67 */
68 public function testAuthenticationBadPassword() {
69 $client = $this->createClient();
70 $client->authenticate($this->adminUser, mt_rand());
71 }
72
73 /**
74 * Send a request with bad credentials.
75 *
76 * @expectedException SoapFault
77 */
78 public function testAuthenticationBadKey() {
79 $client = $this->createClient();
80 $key = $client->authenticate($this->adminUser, $this->adminPass);
81 $client->get_contact(mt_rand(), array());
82 }
83
84 /**
85 * A basic test for one SOAP function.
86 */
87 public function testGetContact() {
88 $client = $this->createClient();
89 $key = $client->authenticate($this->adminUser, $this->adminPass);
90 $contacts = $client->get_contact($key, array(
91 'contact_id' => 101,
92 'return.display_name' => 1,
93 ));
94 $this->assertEquals($contacts['is_error'], 0);
95 $this->assertEquals($contacts['count'], 1);
96 $this->assertEquals($contacts['values'][101]['contact_id'], 101);
97 }
98
99 /**
100 * @return \SoapClient
101 */
102 protected function createClient() {
103 return new SoapClient(NULL, array(
39b959db
SL
104 'location' => $this->url,
105 'uri' => 'urn:civicrm',
106 'trace' => 1,
107 ));
8991c9d5
TO
108 }
109
110}