fix year in headers
[civicrm-core.git] / tests / phpunit / E2E / Extern / SoapTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 */
31 class E2E_Extern_SoapTest extends CiviEndToEndTestCase {
32
33 /**
34 * @var string
35 */
36 var $url, $adminUser, $adminPass;
37
38 public function setUp() {
39 CRM_Core_Config::singleton(1, 1);
40
41 global $_CV;
42 $this->adminUser = $_CV['ADMIN_USER'];
43 $this->adminPass = $_CV['ADMIN_PASS'];
44 $this->url = CRM_Core_Resources::singleton()->getUrl('civicrm', 'extern/soap.php');
45
46 foreach (array('adminUser', 'adminPass', 'url') as $prop) {
47 if (empty($this->{$prop})) {
48 $this->markTestSkipped("Failed to lookup SOAP URL, user, or password. Have you configured `cv` for testing?");
49 }
50 }
51 }
52
53 /**
54 * Send a request with bad credentials.
55 *
56 * @expectedException SoapFault
57 */
58 public function testAuthenticationBadPassword() {
59 $client = $this->createClient();
60 $client->authenticate($this->adminUser, mt_rand());
61 }
62
63 /**
64 * Send a request with bad credentials.
65 *
66 * @expectedException SoapFault
67 */
68 public function testAuthenticationBadKey() {
69 $client = $this->createClient();
70 $key = $client->authenticate($this->adminUser, $this->adminPass);
71 $client->get_contact(mt_rand(), array());
72 }
73
74 /**
75 * A basic test for one SOAP function.
76 */
77 public function testGetContact() {
78 $client = $this->createClient();
79 $key = $client->authenticate($this->adminUser, $this->adminPass);
80 $contacts = $client->get_contact($key, array(
81 'contact_id' => 101,
82 'return.display_name' => 1,
83 ));
84 $this->assertEquals($contacts['is_error'], 0);
85 $this->assertEquals($contacts['count'], 1);
86 $this->assertEquals($contacts['values'][101]['contact_id'], 101);
87 }
88
89 /**
90 * @return \SoapClient
91 */
92 protected function createClient() {
93 return new SoapClient(NULL, array(
94 'location' => $this->url,
95 'uri' => 'urn:civicrm',
96 'trace' => 1,
97 )
98 );
99 }
100
101 }