From: Tim Otten Date: Tue, 23 Aug 2016 07:26:46 +0000 (-0700) Subject: CRM-18808, CRM-19154 - Add E2E_Extern_SoapTest X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8991c9d5c3056d4324fb2271ee1a22866900f98a;p=civicrm-core.git CRM-18808, CRM-19154 - Add E2E_Extern_SoapTest --- diff --git a/tests/phpunit/E2E/Extern/SoapTest.php b/tests/phpunit/E2E/Extern/SoapTest.php new file mode 100644 index 0000000000..3abc49e88f --- /dev/null +++ b/tests/phpunit/E2E/Extern/SoapTest.php @@ -0,0 +1,101 @@ +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, + ) + ); + } + +}