From 18eee50e98c8263474dbd1b53f204c36e6fb48d1 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 26 Jul 2013 17:14:04 +1200 Subject: [PATCH] CRM-13072 - removing version check from 'create' reveals the test is not ensuring what it should ensure, marking incomplete, also added other valuable tests - but marking as incomplete because not all api conform yet --- .../phpunit/api/v3/SyntaxConformanceTest.php | 123 +++++++++++++++--- 1 file changed, 105 insertions(+), 18 deletions(-) diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index d73afe2510..7f221c213e 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -36,7 +36,7 @@ require_once 'CiviTest/CiviUnitTestCase.php'; */ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { - protected $_apiversion; + protected $_apiversion = 3; /** * @var array e.g. $this->deletes['CRM_Contact_DAO_Contact'][] = $contactID; @@ -52,7 +52,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { Those that don't exist and that will never exist (eg an obsoleted Entity they need to be returned by the function toBeSkipped_{$action} (because it has to be a static method and therefore couldn't access a this->toBeSkipped) - */ function setUp() { + */ + function setUp() { parent::setUp(); $this->toBeImplemented['get'] = array('Profile', 'CustomValue', 'Constant', 'CustomSearch', 'Extension', 'ReportTemplate', 'System', 'Setting'); @@ -436,19 +437,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { return; } - $baoString = _civicrm_api3_get_DAO($entityName); - if (empty($baoString)) { - $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO"); - return; - } - - // create entities - $baoObj1 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); - $this->assertTrue(is_integer($baoObj1->id), 'check first id'); - $this->deletableTestObjects[$baoString][] = $baoObj1->id; - $baoObj2 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); - $this->assertTrue(is_integer($baoObj2->id), 'check second id'); - $this->deletableTestObjects[$baoString][] = $baoObj2->id; + $baos = $this->getMockableBAOObjects($entityName); + list($baoObj1, $baoObj2) = $baos; // fetch first by ID $result = civicrm_api($entityName, 'get', array( @@ -574,15 +564,35 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { * @dataProvider entities_create */ public function testEmptyParam_create($Entity) { + $this->markTestIncomplete("fixing this test to test the api functions fails on numberous tests + which will either create a completely blank entity (batch, participant status) or + have a damn good crack at it (e.g mailing job). Marking this as incomplete beats false success"); + // + return; if (in_array($Entity, $this->toBeImplemented['create'])) { // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented"); return; } - $result = civicrm_api($Entity, 'Create', array()); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure($Entity, 'Create', array()); $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']); } + /** + * @dataProvider entities_create + * + * Check that create doesn't work with an invalid + */ + public function testInvalidID_create($Entity) { + // turn test off for noew + $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO"); + return; + if (in_array($Entity, $this->toBeImplemented['create'])) { + // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented"); + return; + } + $result = $this->callAPIFailure($Entity, 'Create', array('id' => 999)); + } + /** * @dataProvider entities */ @@ -780,7 +790,19 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']); } - + /** + * @dataProvider entities_delete + */ + public function testInvalidID_delete($Entity) { + // turn test off for noew + $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO"); + return; + if (in_array($Entity, $this->toBeImplemented['delete'])) { + // $this->markTestIncomplete("civicrm_api3_{$Entity}_delete to be implemented"); + return; + } + $result = $this->callAPIFailure($Entity, 'Delete', array('id' => 999)); + } /** * @dataProvider entities */ @@ -790,6 +812,71 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $this->assertEquals("Input variable `params` is not an array", $result['error_message']); } + /** + * Create two entities and make sure delete action only deletes one! + * + * @dataProvider entities_delete + * + * limitations include the problem with avoiding loops when creating test objects - + * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through + * Currency - only seems to support US + */ + public function testByID_delete($entityName) { + // turn test off for noew + $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO"); + return; + + if (in_array($entityName, self::toBeSkipped_automock(TRUE))) { + // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented"); + return; + } + $startCount = $this->callAPISuccess($entityName, 'getcount', array()); + $createcount = 2; + $baos = $this->getMockableBAOObjects($entityName, $createcount); + list($baoObj1, $baoObj2) = $baos; + + // make sure exactly 2 exist + $result = $this->callAPISuccess($entityName, 'getcount', array(), + $createcount + $startCount + ); + + $this->callAPISuccess($entityName, 'delete', array('id' => $baoObj2->id)); + //make sure 1 less exists now + $result = $this->callAPISuccess($entityName, 'getcount', array(), + ($createcount + $startCount) -1 + ); + + //make sure id #1 exists + $result = $this->callAPISuccess($entityName, 'getcount', array('id' => $baoObj1->id), + 1 + ); + //make sure id #2 desn't exist + $result = $this->callAPISuccess($entityName, 'getcount', array('id' => $baoObj2->id), + 0 + ); + } + +/** + * @param entityName + */private function getMockableBAOObjects($entityName, $count = 2) { + $baoString = _civicrm_api3_get_DAO($entityName); + if (empty($baoString)) { + $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO"); + return; + } + $baos = array(); + while($i < $count) { + // create entities + $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); + $this->assertTrue(is_integer($baoObj->id), 'check first id'); + $this->deletableTestObjects[$baoString][] = $baoObj->id; + $baos[] = $baoObj; + $i ++; + } + return $baos; + } + + /** * Verify that HTML metacharacters provided as inputs appear consistently * as outputs. -- 2.25.1