From ef9cbdb75771b2a9ac9836b623a7688e33481724 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 1 Apr 2015 20:11:09 -0700 Subject: [PATCH] CRM-11889 - CiviSeleniumTestCase - Use browser session for rest_civicrm_api. Add webtestGetLoggedInContact & assertAPISuccess. --- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 65 +++++++++++++++---- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index 6bd435c871..c2379df5af 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -315,13 +315,13 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } $result = civicrm_api($entity, $action, $params); - $this->assertTrue(!civicrm_error($result), 'Civicrm api error.'); + $this->assertAPISuccess($result); return $result; } /** - * Call the API on the remote server. - * Experimental - currently only works if permissions on remote site allow anon user to access ajax api + * Call the API on the remote server using the AJAX endpoint. + * * @see CRM-11889 * @param $entity * @param $action @@ -332,17 +332,28 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $params += array( 'version' => 3, ); - $url = "{$this->settings->sandboxURL}/{$this->sboxPath}civicrm/ajax/rest?entity=$entity&action=$action&json=" . json_encode($params); - $request = array( - 'http' => array( - 'method' => 'POST', - // Naughty sidestep of civi's security checks - 'header' => "X-Requested-With: XMLHttpRequest", - ), + static $reqId = 0; + $reqId++; + + $jsCmd = ' + setTimeout(function(){ + CRM.api3("@entity", "@action", @params).then(function(a){ + cj("