CRM-18808, CRM-19154 - Add E2E_Extern_SoapTest
authorTim Otten <totten@civicrm.org>
Tue, 23 Aug 2016 07:26:46 +0000 (00:26 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 23 Aug 2016 21:07:09 +0000 (14:07 -0700)
tests/phpunit/E2E/Extern/SoapTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/E2E/Extern/SoapTest.php b/tests/phpunit/E2E/Extern/SoapTest.php
new file mode 100644 (file)
index 0000000..3abc49e
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License along with this program; if not, contact CiviCRM LLC       |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * Verify that the SOAP bindings correctly parse and authenticate requests.
+ * @group e2e
+ */
+class E2E_Extern_SoapTest extends CiviEndToEndTestCase {
+
+  /**
+   * @var string
+   */
+  var $url, $adminUser, $adminPass;
+
+  public function setUp() {
+    CRM_Core_Config::singleton(1, 1);
+
+    global $_CV;
+    $this->adminUser = $_CV['ADMIN_USER'];
+    $this->adminPass = $_CV['ADMIN_PASS'];
+    $this->url = CRM_Core_Resources::singleton()->getUrl('civicrm', 'extern/soap.php');
+
+    foreach (array('adminUser', 'adminPass', 'url') as $prop) {
+      if (empty($this->{$prop})) {
+        $this->markTestSkipped("Failed to lookup SOAP URL, user, or password. Have you configured `cv` for testing?");
+      }
+    }
+  }
+
+  /**
+   * Send a request with bad credentials.
+   *
+   * @expectedException SoapFault
+   */
+  public function testAuthenticationBadPassword() {
+    $client = $this->createClient();
+    $client->authenticate($this->adminUser, mt_rand());
+  }
+
+  /**
+   * Send a request with bad credentials.
+   *
+   * @expectedException SoapFault
+   */
+  public function testAuthenticationBadKey() {
+    $client = $this->createClient();
+    $key = $client->authenticate($this->adminUser, $this->adminPass);
+    $client->get_contact(mt_rand(), array());
+  }
+
+  /**
+   * A basic test for one SOAP function.
+   */
+  public function testGetContact() {
+    $client = $this->createClient();
+    $key = $client->authenticate($this->adminUser, $this->adminPass);
+    $contacts = $client->get_contact($key, array(
+      'contact_id' => 101,
+      'return.display_name' => 1,
+    ));
+    $this->assertEquals($contacts['is_error'], 0);
+    $this->assertEquals($contacts['count'], 1);
+    $this->assertEquals($contacts['values'][101]['contact_id'], 101);
+  }
+
+  /**
+   * @return \SoapClient
+   */
+  protected function createClient() {
+    return new SoapClient(NULL, array(
+        'location' => $this->url,
+        'uri' => 'urn:civicrm',
+        'trace' => 1,
+      )
+    );
+  }
+
+}