From eb87411fc8bfd9da0cc51381c12962c1e82fb427 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 30 Apr 2013 17:32:14 -0700 Subject: [PATCH] CiviSeleniumSettings - Add adminApiKey RestTest - Use adminApiKey. Comment out test-cases for deprecated/dead functionality. Simplify/patch remaining test-cases. --- .../CiviTest/CiviSeleniumSettings.php.txt | 3 +- tests/phpunit/WebTest/Utils/RestTest.php | 30 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviSeleniumSettings.php.txt b/tests/phpunit/CiviTest/CiviSeleniumSettings.php.txt index 23a5fc11f7..bc235174f1 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumSettings.php.txt +++ b/tests/phpunit/CiviTest/CiviSeleniumSettings.php.txt @@ -10,7 +10,6 @@ class CiviSeleniumSettings { var $sandboxPATH = ''; - var $username = 'demo'; var $password = 'demo'; @@ -19,6 +18,8 @@ class CiviSeleniumSettings { var $adminPassword = 'PASSWORD'; + var $adminApiKey = NULL; // civicrm_contact.api_key for admin + var $UFemail = 'noreply@civicrm.org'; /** diff --git a/tests/phpunit/WebTest/Utils/RestTest.php b/tests/phpunit/WebTest/Utils/RestTest.php index b483322fe4..e18382145e 100644 --- a/tests/phpunit/WebTest/Utils/RestTest.php +++ b/tests/phpunit/WebTest/Utils/RestTest.php @@ -46,6 +46,9 @@ class WebTest_Utils_RestTest extends CiviSeleniumTestCase { if (!property_exists($this->settings, 'siteKey') || empty($this->settings->siteKey)) { $this->markTestSkipped('CiviSeleniumSettings is missing siteKey'); } + if (!property_exists($this->settings, 'adminApiKey') || empty($this->settings->adminApiKey)) { + $this->markTestSkipped('CiviSeleniumSettings is missing adminApiKey'); + } } protected function tearDown() { @@ -60,8 +63,8 @@ class WebTest_Utils_RestTest extends CiviSeleniumTestCase { } } + /* function testValidLoginCMSUser() { - $this->_setUpAdminSessionIdAndApiKey(); $client = CRM_Utils_HttpClient::singleton(); $params = array( "q" => "civicrm/login", @@ -78,7 +81,6 @@ class WebTest_Utils_RestTest extends CiviSeleniumTestCase { } function testInvalidPasswordLogin() { - $this->_setUpAdminSessionIdAndApiKey(); $client = CRM_Utils_HttpClient::singleton(); $badPassword = $this->settings->adminPassword . "badpass"; $params = array( @@ -95,15 +97,15 @@ class WebTest_Utils_RestTest extends CiviSeleniumTestCase { $this->assertAPIErrorCode($result, 1); } - function testValidCallsiteKey() { + function testValidCallPHPSessionID() { $this->_setUpAdminSessionIdAndApiKey(); $client = CRM_Utils_HttpClient::singleton(); $params = array( "entity" => "Contact", "action" => "get", - "key" => $this->settings->siteKey, "json" => "1", - "api_key" => $this->api_key + "PHPSESSID" => $this->session_id, + "api_key" => $this->api_key, ); list($status, $data) = $client->post($this->url, $params); $this->assertEquals(CRM_Utils_HttpClient::STATUS_OK, $status); @@ -111,16 +113,16 @@ class WebTest_Utils_RestTest extends CiviSeleniumTestCase { $this->assertNotNull($result); $this->assertAPIErrorCode($result, 0); } + */ - function testValidCallPHPSessionID() { - $this->_setUpAdminSessionIdAndApiKey(); + function testValidCallAPIKey() { $client = CRM_Utils_HttpClient::singleton(); $params = array( "entity" => "Contact", "action" => "get", + "key" => $this->settings->siteKey, "json" => "1", - "PHPSESSID" => $this->session_id, - "api_key" => $this->api_key, + "api_key" => $this->settings->adminApiKey, ); list($status, $data) = $client->post($this->url, $params); $this->assertEquals(CRM_Utils_HttpClient::STATUS_OK, $status); @@ -130,14 +132,13 @@ class WebTest_Utils_RestTest extends CiviSeleniumTestCase { } function testInvalidAPIKey() { - $this->_setUpAdminSessionIdAndApiKey(); $client = CRM_Utils_HttpClient::singleton(); $params = array( "entity" => "Contact", "action" => "get", "key" => $this->settings->siteKey, "json" => "1", - "api_key" => "zzzzzzzzzzzzzzaaaaaaaaaaaaaaaaabadasdasd" + "api_key" => 'garbage_' . $this->settings->adminApiKey, ); list($status, $data) = $client->post($this->url, $params); $this->assertEquals(CRM_Utils_HttpClient::STATUS_OK, $status); @@ -147,7 +148,6 @@ class WebTest_Utils_RestTest extends CiviSeleniumTestCase { } function testNotCMSUser() { - $this->_setUpAdminSessionIdAndApiKey(); $client = CRM_Utils_HttpClient::singleton(); //Create contact with api_key $test_key = "testing1234"; @@ -173,6 +173,7 @@ class WebTest_Utils_RestTest extends CiviSeleniumTestCase { $this->assertAPIErrorCode($result, 1); } + /* protected function _setUpAdminSessionIdAndApiKey() { $client = CRM_Utils_HttpClient::singleton(); $params = array( @@ -188,8 +189,7 @@ class WebTest_Utils_RestTest extends CiviSeleniumTestCase { $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'); + $this->assertTrue(isset($this->api_key), 'Failed to find admin API key'); return $result; - } - + } // */ } -- 2.25.1