4 * Class CRM_Core_BAO_OpenIDTest
7 class CRM_Core_BAO_OpenIDTest
extends CiviUnitTestCase
{
8 public function tearDown() {
9 // If we truncate only contact, then stale domain and openid records will be left.
10 // If we truncate none of these tables, then contactDelete() will incrementally
12 //$tablesToTruncate = array('civicrm_domain', 'civicrm_contact', 'civicrm_openid');
13 //$this->quickCleanup($tablesToTruncate);
16 public function setUp() {
21 * Add() method (create and update modes)
23 public function testAdd() {
24 $contactId = $this->individualCreate();
25 $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId);
27 $openIdURL = "http://test-username.civicrm.org/";
29 'contact_id' => $contactId,
30 'location_type_id' => 1,
31 'openid' => $openIdURL,
35 $openObject = CRM_Core_BAO_OpenID
::add($params);
37 $openId = $openObject->id
;
39 $this->assertDBNotNull('CRM_Core_DAO_OpenID', $openIdURL, 'id', 'openid',
40 'Database check for created OpenID.'
43 // Now call add() to modify an existing open-id record
47 'contact_id' => $contactId,
48 'openid' => $openIdURL,
50 'allowed_to_login' => 1,
53 CRM_Core_BAO_OpenID
::add($params);
55 $allowedToLogin = $this->assertDBNotNull('CRM_Core_DAO_OpenID', $openId, 'allowed_to_login', 'id',
56 'Database check on updated OpenID record.'
58 $this->assertEquals($allowedToLogin, 1, 'Verify allowed_to_login value is 1.');
60 $this->contactDelete($contactId);
61 $this->assertDBRowNotExist('CRM_Contact_DAO_Contact', $contactId);
65 * IfAllowedToLogin() method (set and reset allowed_to_login)
67 public function testIfAllowedToLogin() {
68 $contactId = $this->individualCreate();
69 $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId);
70 $openIdURL = "http://test-username.civicrm.org/";
73 'contact_id' => $contactId,
74 'location_type_id' => 1,
75 'openid' => $openIdURL,
79 $openObject = CRM_Core_BAO_OpenID
::add($params);
81 $openId = $openObject->id
;
82 $this->assertDBNotNull('CRM_Core_DAO_OpenID', $openIdURL, 'id', 'openid',
83 'Database check for created OpenID.'
86 $allowedToLogin = CRM_Core_BAO_OpenID
::isAllowedToLogin($openIdURL);
87 $this->assertEquals($allowedToLogin, FALSE, 'Verify allowed_to_login value is 0.');
89 // Now call add() to modify an existing open-id record
93 'contact_id' => $contactId,
94 'openid' => $openIdURL,
96 'allowed_to_login' => 1,
99 CRM_Core_BAO_OpenID
::add($params);
101 $allowedToLogin = CRM_Core_BAO_OpenID
::isAllowedToLogin($openIdURL);
103 $this->assertEquals($allowedToLogin, TRUE, 'Verify allowed_to_login value is 1.');
104 $this->contactDelete($contactId);
105 //domain contact doesn't really get deleted //
106 $this->assertDBRowNotExist('CRM_Contact_DAO_Contact', $contactId);
110 * AllOpenIDs() method - get all OpenIDs for the given contact
112 public function testAllOpenIDs() {
113 $contactId = $this->individualCreate();
114 $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId);
116 // create first openid
117 $openIdURLOne = "http://test-one-username.civicrm.org/";
119 'contact_id' => $contactId,
120 'location_type_id' => 1,
121 'openid' => $openIdURLOne,
123 'allowed_to_login' => 1,
126 $openObjectOne = CRM_Core_BAO_OpenID
::add($params);
128 $openIdOne = $openObjectOne->id
;
129 $this->assertDBNotNull('CRM_Core_DAO_OpenID', $openIdURLOne, 'id', 'openid',
130 'Database check for created OpenID.'
133 // create second openid
134 $openIdURLTwo = "http://test-two-username.civicrm.org/";
136 'contact_id' => $contactId,
137 'location_type_id' => 1,
138 'openid' => $openIdURLTwo,
141 $openObjectTwo = CRM_Core_BAO_OpenID
::add($params);
142 $openIdTwo = $openObjectTwo->id
;
144 $this->assertDBNotNull('CRM_Core_DAO_OpenID', $openIdURLTwo, 'id', 'openid',
145 'Database check for created OpenID.'
148 // obtain all openids for the contact
149 $openIds = CRM_Core_BAO_OpenID
::allOpenIDs($contactId);
151 // check number of openids for the contact
152 $this->assertEquals(2, count($openIds), 'Checking number of returned open-ids.');
154 // check first openid values
155 $this->assertEquals($openIdURLOne, $openIds[$openIdOne]['openid'],
156 'Confirm first openid value.'
158 $this->assertEquals(1, $openIds[$openIdOne]['is_primary'], 'Confirm is_primary field value.');
159 $this->assertEquals(1, $openIds[$openIdOne]['allowed_to_login'], 'Confirm allowed_to_login field value.');
161 // check second openid values
162 $this->assertEquals($openIdURLTwo, $openIds[$openIdTwo]['openid'],
163 'Confirm second openid value.'
165 $this->assertEquals(0, $openIds[$openIdTwo]['is_primary'], 'Confirm is_primary field value for second openid.');
166 $this->assertEquals(0, $openIds[$openIdTwo]['allowed_to_login'], 'Confirm allowed_to_login field value for second openid.');
168 $this->contactDelete($contactId);
169 $this->assertDBRowNotExist('CRM_Contact_DAO_Contact', $contactId);