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