Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
0eea664b | 2 | |
6a488035 | 3 | require_once 'CiviTest/Contact.php'; |
aba1cd8b EM |
4 | |
5 | /** | |
6 | * Class CRM_Core_BAO_OpenIDTest | |
acb109b7 | 7 | * @group headless |
aba1cd8b | 8 | */ |
6a488035 | 9 | class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { |
00be9182 | 10 | public function tearDown() { |
6a488035 TO |
11 | // If we truncate only contact, then stale domain and openid records will be left. |
12 | // If we truncate none of these tables, then contactDelete() will incrementally | |
13 | // clean correctly. | |
14 | //$tablesToTruncate = array('civicrm_domain', 'civicrm_contact', 'civicrm_openid'); | |
15 | //$this->quickCleanup($tablesToTruncate); | |
16 | } | |
17 | ||
00be9182 | 18 | public function setUp() { |
6a488035 TO |
19 | parent::setUp(); |
20 | } | |
21 | ||
22 | /** | |
100fef9d | 23 | * Add() method (create and update modes) |
6a488035 | 24 | */ |
00be9182 | 25 | public function testAdd() { |
6a488035 TO |
26 | $contactId = Contact::createIndividual(); |
27 | $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId); | |
28 | ||
29 | $openIdURL = "http://test-username.civicrm.org/"; | |
30 | $params = array( | |
31 | 'contact_id' => $contactId, | |
32 | 'location_type_id' => 1, | |
33 | 'openid' => $openIdURL, | |
34 | 'is_primary' => 1, | |
35 | ); | |
36 | ||
37 | $openObject = CRM_Core_BAO_OpenID::add($params); | |
38 | ||
39 | $openId = $openObject->id; | |
40 | ||
41 | $this->assertDBNotNull('CRM_Core_DAO_OpenID', $openIdURL, 'id', 'openid', | |
42 | 'Database check for created OpenID.' | |
43 | ); | |
44 | ||
45 | // Now call add() to modify an existing open-id record | |
46 | ||
47 | $params = array( | |
48 | 'id' => $openId, | |
49 | 'contact_id' => $contactId, | |
50 | 'openid' => $openIdURL, | |
51 | 'is_bulkmail' => 1, | |
52 | 'allowed_to_login' => 1, | |
53 | ); | |
54 | ||
55 | CRM_Core_BAO_OpenID::add($params); | |
56 | ||
57 | $allowedToLogin = $this->assertDBNotNull('CRM_Core_DAO_OpenID', $openId, 'allowed_to_login', 'id', | |
58 | 'Database check on updated OpenID record.' | |
59 | ); | |
60 | $this->assertEquals($allowedToLogin, 1, 'Verify allowed_to_login value is 1.'); | |
61 | ||
62 | $this->contactDelete($contactId); | |
63 | $this->assertDBRowNotExist('CRM_Contact_DAO_Contact', $contactId); | |
64 | } | |
65 | ||
66 | /** | |
100fef9d | 67 | * IfAllowedToLogin() method (set and reset allowed_to_login) |
6a488035 | 68 | */ |
00be9182 | 69 | public function testIfAllowedToLogin() { |
6a488035 TO |
70 | $contactId = Contact::createIndividual(); |
71 | $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId); | |
72 | $openIdURL = "http://test-username.civicrm.org/"; | |
73 | ||
74 | $params = array( | |
75 | 'contact_id' => $contactId, | |
76 | 'location_type_id' => 1, | |
77 | 'openid' => $openIdURL, | |
78 | 'is_primary' => 1, | |
79 | ); | |
80 | ||
81 | $openObject = CRM_Core_BAO_OpenID::add($params); | |
82 | ||
83 | $openId = $openObject->id; | |
84 | $this->assertDBNotNull('CRM_Core_DAO_OpenID', $openIdURL, 'id', 'openid', | |
85 | 'Database check for created OpenID.' | |
86 | ); | |
87 | ||
88 | $allowedToLogin = CRM_Core_BAO_OpenID::isAllowedToLogin($openIdURL); | |
89 | $this->assertEquals($allowedToLogin, FALSE, 'Verify allowed_to_login value is 0.'); | |
90 | ||
91 | // Now call add() to modify an existing open-id record | |
92 | ||
93 | $params = array( | |
94 | 'id' => $openId, | |
95 | 'contact_id' => $contactId, | |
96 | 'openid' => $openIdURL, | |
97 | 'is_bulkmail' => 1, | |
98 | 'allowed_to_login' => 1, | |
99 | ); | |
100 | ||
101 | CRM_Core_BAO_OpenID::add($params); | |
102 | ||
103 | $allowedToLogin = CRM_Core_BAO_OpenID::isAllowedToLogin($openIdURL); | |
104 | ||
105 | $this->assertEquals($allowedToLogin, TRUE, 'Verify allowed_to_login value is 1.'); | |
106 | $this->contactDelete($contactId); | |
107 | //domain contact doesn't really get deleted // | |
108 | $this->assertDBRowNotExist('CRM_Contact_DAO_Contact', $contactId); | |
109 | } | |
110 | ||
111 | /** | |
100fef9d | 112 | * AllOpenIDs() method - get all OpenIDs for the given contact |
6a488035 | 113 | */ |
00be9182 | 114 | public function testAllOpenIDs() { |
6a488035 TO |
115 | $contactId = Contact::createIndividual(); |
116 | $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId); | |
117 | ||
118 | // create first openid | |
119 | $openIdURLOne = "http://test-one-username.civicrm.org/"; | |
120 | $params = array( | |
121 | 'contact_id' => $contactId, | |
122 | 'location_type_id' => 1, | |
123 | 'openid' => $openIdURLOne, | |
124 | 'is_primary' => 1, | |
125 | 'allowed_to_login' => 1, | |
126 | ); | |
127 | ||
128 | $openObjectOne = CRM_Core_BAO_OpenID::add($params); | |
129 | ||
130 | $openIdOne = $openObjectOne->id; | |
131 | $this->assertDBNotNull('CRM_Core_DAO_OpenID', $openIdURLOne, 'id', 'openid', | |
132 | 'Database check for created OpenID.' | |
133 | ); | |
134 | ||
135 | // create second openid | |
136 | $openIdURLTwo = "http://test-two-username.civicrm.org/"; | |
137 | $params = array( | |
138 | 'contact_id' => $contactId, | |
139 | 'location_type_id' => 1, | |
140 | 'openid' => $openIdURLTwo, | |
141 | ); | |
142 | ||
143 | $openObjectTwo = CRM_Core_BAO_OpenID::add($params); | |
144 | $openIdTwo = $openObjectTwo->id; | |
145 | ||
146 | $this->assertDBNotNull('CRM_Core_DAO_OpenID', $openIdURLTwo, 'id', 'openid', | |
147 | 'Database check for created OpenID.' | |
148 | ); | |
149 | ||
150 | // obtain all openids for the contact | |
151 | $openIds = CRM_Core_BAO_OpenID::allOpenIDs($contactId); | |
152 | ||
153 | // check number of openids for the contact | |
154 | $this->assertEquals(2, count($openIds), 'Checking number of returned open-ids.'); | |
155 | ||
156 | // check first openid values | |
157 | $this->assertEquals($openIdURLOne, $openIds[$openIdOne]['openid'], | |
158 | 'Confirm first openid value.' | |
159 | ); | |
160 | $this->assertEquals(1, $openIds[$openIdOne]['is_primary'], 'Confirm is_primary field value.'); | |
161 | $this->assertEquals(1, $openIds[$openIdOne]['allowed_to_login'], 'Confirm allowed_to_login field value.'); | |
162 | ||
163 | // check second openid values | |
164 | $this->assertEquals($openIdURLTwo, $openIds[$openIdTwo]['openid'], | |
165 | 'Confirm second openid value.' | |
166 | ); | |
167 | $this->assertEquals(0, $openIds[$openIdTwo]['is_primary'], 'Confirm is_primary field value for second openid.'); | |
168 | $this->assertEquals(0, $openIds[$openIdTwo]['allowed_to_login'], 'Confirm allowed_to_login field value for second openid.'); | |
169 | ||
170 | //Contact::delete($contactId); | |
171 | $this->contactDelete($contactId); | |
172 | $this->assertDBRowNotExist('CRM_Contact_DAO_Contact', $contactId); | |
173 | } | |
96025800 | 174 | |
6a488035 | 175 | } |