From b9af475890d724b8a3214cf2d035013f356d116e Mon Sep 17 00:00:00 2001 From: Eileen Date: Tue, 18 Mar 2014 08:45:19 +0000 Subject: [PATCH] CRM-14355 - test auditing existing limit behaviour ---------------------------------------- * CRM-14355: make api treat limit = 0 as an unlimited request http://issues.civicrm.org/jira/browse/CRM-14355 --- .../phpunit/api/v3/SyntaxConformanceTest.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 84eceef7bb..8de7961999 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -110,6 +110,10 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { return static::entities(static::toBeSkipped_updatesingle(TRUE)); } + public static function entities_getlimit() { + return static::entities(static::toBeSkipped_getlimit()); + } + public static function entities_delete() { return static::entities(static::toBeSkipped_delete(TRUE)); } @@ -258,6 +262,28 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { return $entities; } + /* + * At this stage exclude the ones that don't pass & add them as we can troubleshoot them + */ + public static function toBeSkipped_getlimit() { + $entitiesWithout = array( + 'Case',//case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id) + 'Contact', // existing behaviour on NULL = rtn all + 'Contribution', //existing behaviour = fatal if 0 limit applied as offset of null is put in the query + 'EntityTag', // non-standard api - has inappropriate mandatory fields & doesn't implement limit + 'Event', // failed 'check that a 5 limit returns 5' - probably is_template field is wrong or something, or could be limit doesn't work right + 'Extension', // can't handle creating 25 + 'Group', // // existing behaviour on NULL = rtn all + 'MailingGroup', // no get call on MailingGroup + 'Note', // fails on 5 limit - probably a set up problem + 'Participant', //existing behaviour = fatal if 0 limit applied as null offset in sql + 'Pledge', //existing behaviour = fatal if 0 limit applied as null offset in sql + 'Setting', //a bit of a pseudoapi - keys by domain + + ); + return $entitiesWithout; + } + public function getKnownUnworkablesUpdateSingle($entity, $key){ // can't update values are values for which updates don't result in the value being changed $knownFailures = array( @@ -480,6 +506,63 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $this->assertEquals(1, count($result['values'])); } + /** + * Ensure that the "get" operation accepts limiting the #result records. + * + * TODO Consider making a separate entity list ("entities_getlimit") + * For the moment, the "entities_updatesingle" list should give a good + * sense for which entities support createTestObject + * + * @dataProvider entities_getlimit + * @param string $entity + */ + function testLimit($entityName) { + $cases = array(); // each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount) + $cases[] = array( + array('options' => array('limit' => NULL)), + 0, + 'check that a NULL limit returns 0', + ); + $cases[] = array( + array('options' => array('limit' => FALSE)), + 0, + 'check that a FALSE limit returns 0', + ); + $cases[] = array( + array('options' => array('limit' => 0)), + 0, + 'check that a 0 limit returns 0', + ); + $cases[] = array( + array('options' => array('limit' => 5)), + 5, + 'check that a 5 limit returns 5', + ); + $cases[] = array( + array(), + 25, + 'check that no limit returns 25', + ); + + $baoString = _civicrm_api3_get_DAO($entityName); + if (empty($baoString)) { + $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO"); + return; + } + + // make 30 test items -- 30 > 25 (the default limit) + for ($i = 0; $i < 30; $i++) { + CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); + } + + // each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount) + foreach ($cases as $case) { + $result = $this->callAPISuccess($entityName, 'get', $case[0]); + $this->assertEquals($case[1], $result['count'], $case[2]); + $this->assertEquals($case[1], count($result['values'])); + } + } + /** * Create two entities and make sure we can fetch them individually by ID (e.g. using "contact_id=>2" * or "group_id=>4") -- 2.25.1