if (!property_exists($this->settings, 'siteKey') || empty($this->settings->siteKey)) {
$this->markTestSkipped('CiviSeleniumSettings is missing siteKey');
}
-
- $client = CRM_Utils_HttpClient::singleton();
- $params = array(
- "q" => "civicrm/login",
- "key" => $this->settings->siteKey,
- "json" => "1",
- "name" => $this->settings->adminUsername,
- "pass" => $this->settings->adminPassword
- );
- list($status, $data) = $client->post($this->url, $params);
- $this->assertEquals(CRM_Utils_HttpClient::STATUS_OK, $status);
- $result = json_decode($data, TRUE);
- $this->assertAPIErrorCode($result, 0);
- $this->api_key = $result["api_key"];
- $this->session_id = $result["PHPSESSID"];
- if (!isset($this->api_key)) {
- $this->markTestSkipped('Admin does not have an associated API key');
- }
}
protected function tearDown() {
}
function testValidLoginCMSUser() {
+ $this->_setUpAdminSessionIdAndApiKey();
$client = CRM_Utils_HttpClient::singleton();
$params = array(
"q" => "civicrm/login",
}
function testInvalidPasswordLogin() {
+ $this->_setUpAdminSessionIdAndApiKey();
$client = CRM_Utils_HttpClient::singleton();
$badPassword = $this->settings->adminPassword . "badpass";
$params = array(
}
function testValidCallsiteKey() {
+ $this->_setUpAdminSessionIdAndApiKey();
$client = CRM_Utils_HttpClient::singleton();
$params = array(
"entity" => "Contact",
}
function testValidCallPHPSessionID() {
+ $this->_setUpAdminSessionIdAndApiKey();
$client = CRM_Utils_HttpClient::singleton();
$params = array(
"entity" => "Contact",
}
function testInvalidAPIKey() {
+ $this->_setUpAdminSessionIdAndApiKey();
$client = CRM_Utils_HttpClient::singleton();
$params = array(
"entity" => "Contact",
}
function testNotCMSUser() {
+ $this->_setUpAdminSessionIdAndApiKey();
$client = CRM_Utils_HttpClient::singleton();
//Create contact with api_key
$test_key = "testing1234";
$this->assertAPIErrorCode($result, 1);
}
+ protected function _setUpAdminSessionIdAndApiKey() {
+ $client = CRM_Utils_HttpClient::singleton();
+ $params = array(
+ "q" => "civicrm/login",
+ "key" => $this->settings->siteKey,
+ "json" => "1",
+ "name" => $this->settings->adminUsername,
+ "pass" => $this->settings->adminPassword
+ );
+ list($status, $data) = $client->post($this->url, $params);
+ $this->assertEquals(CRM_Utils_HttpClient::STATUS_OK, $status);
+ $result = json_decode($data, TRUE);
+ $this->assertAPIErrorCode($result, 0);
+ $this->api_key = $result["api_key"];
+ $this->session_id = $result["PHPSESSID"];
+ $this->asserTrue(isset($this->api_key), 'Failed to find admin API key');
+ return $result;
+ }
+
}