--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+ +--------------------------------------------------------------------+
+ | 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 and the CiviCRM Licensing Exception 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 |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * This api exposes CiviCRM OpenID records.
+ *
+ * @package CiviCRM_APIv3
+ */
+
+/**
+ * Add an OpenID for a contact.
+ *
+ * @param array $params
+ *
+ * @return array
+ */
+function civicrm_api3_openid_create($params) {
+ return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Adjust Metadata for Create action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $params
+ * Array of parameters determined by getfields.
+ */
+function _civicrm_api3_openid_create_spec(&$params) {
+ $params['contact_id']['api.required'] = 1;
+}
+
+/**
+ * Deletes an existing OpenID.
+ *
+ * @param array $params
+ *
+ * @return array
+ * API result Array
+ */
+function civicrm_api3_openid_delete($params) {
+ return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Retrieve one or more OpenID.
+ *
+ * @param array $params
+ * An associative array of name/value pairs.
+ *
+ * @return array
+ * details of found OpenID
+ */
+function civicrm_api3_openid_get($params) {
+ return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+ +--------------------------------------------------------------------+
+ | 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 and the CiviCRM Licensing Exception 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 |
+ +--------------------------------------------------------------------+
+ */
+
+require_once 'CiviTest/CiviUnitTestCase.php';
+
+
+/**
+ * Test APIv3 civicrm_openid_* functions
+ *
+ * @package CiviCRM_APIv3
+ * @subpackage API_Contact
+ */
+class api_v3_OpenIDTest extends CiviUnitTestCase {
+
+ protected $_apiversion = 3;
+ protected $params;
+ protected $id;
+ protected $_entity;
+
+ public $DBResetRequired = FALSE;
+
+ public function setUp() {
+ parent::setUp();
+ $this->useTransaction(TRUE);
+
+ $this->_entity = 'openID';
+ $this->_contactID = $this->organizationCreate();
+ $this->params = array(
+ 'contact_id' => $this->_contactID,
+ 'name' => 'My OpenID handle',
+ 'location_type_id' => 1,
+ );
+ }
+
+ public function testCreateOpenID() {
+ $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
+ $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
+ $this->getAndCheck($this->params, $result['id'], $this->_entity);
+ $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
+ }
+
+ public function testGetOpenID() {
+ $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
+ $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
+ $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
+ $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
+ $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
+ }
+
+ public function testDeleteOpenID() {
+ $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
+ $deleteParams = array('id' => $result['id']);
+ $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
+ }
+
+ public function testDeleteOpenIDInvalid() {
+ $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
+ $deleteParams = array('id' => 600);
+ $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams);
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $this->assertEquals(1, $checkDeleted['count'], 'In line ' . __LINE__);
+ }
+
+}