_apiversion = 3; parent::setUp(); // Insert a row in civicrm_group creating option group // from_email_address group $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createXMLDataSet( dirname(__FILE__) . '/dataset/group_admins.xml' ) ); // Insert a row in civicrm_group creating option group // from_email_address group $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createXMLDataSet( dirname(__FILE__) . '/dataset/group_subscribers.xml' ) ); // Insert a row in civicrm_group creating option group // from_email_address group $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createXMLDataSet( dirname(__FILE__) . '/dataset/group_nesting.xml' ) ); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown() { // Truncate the tables $this->quickCleanup( array( 'civicrm_group', 'civicrm_group_nesting', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_join', 'civicrm_uf_match', ) ); } ///////////////// civicrm_group_nesting_get methods /** * Test civicrm_group_nesting_get. */ public function testGet() { $params = array( 'parent_group_id' => 1, 'child_group_id' => 2, ); $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__, __FILE__); // expected data loaded in setUp $expected = array( 1 => array( 'id' => 1, 'child_group_id' => 2, 'parent_group_id' => 1, ), ); $this->assertEquals($expected, $result['values']); } /** * Test civicrm_group_nesting_get with just one * param (child_group_id). */ public function testGetWithChildGroupId() { $params = array( 'child_group_id' => 4, ); $result = $this->callAPISuccess('group_nesting', 'get', $params); // expected data loaded in setUp $expected = array( 3 => array( 'id' => 3, 'child_group_id' => 4, 'parent_group_id' => 1, ), 4 => array( 'id' => 4, 'child_group_id' => 4, 'parent_group_id' => 2, ), ); $this->assertEquals($expected, $result['values']); } /** * Test civicrm_group_nesting_get with just one * param (parent_group_id). */ public function testGetWithParentGroupId() { $params = array( 'parent_group_id' => 1, ); $result = $this->callAPISuccess('group_nesting', 'get', $params); // expected data loaded in setUp $expected = array( 1 => array( 'id' => 1, 'child_group_id' => 2, 'parent_group_id' => 1, ), 2 => array( 'id' => 2, 'child_group_id' => 3, 'parent_group_id' => 1, ), 3 => array( 'id' => 3, 'child_group_id' => 4, 'parent_group_id' => 1, ), ); $this->assertEquals($expected, $result['values']); } /** * Test civicrm_group_nesting_get for no records results. * Success expected. (these tests are of marginal value as are in syntax conformance, * don't copy & paste */ public function testGetEmptyResults() { $params = array( 'parent_group_id' => 1, 'child_group_id' => 700, ); $this->callAPISuccess('group_nesting', 'get', $params); } ///////////////// civicrm_group_nesting_create methods /** * Test civicrm_group_nesting_create. */ public function testCreate() { // groups id=1 and id=2 loaded in setUp $params = array( 'parent_group_id' => 1, 'child_group_id' => 3, ); $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__, __FILE__); $this->callAPISuccessGetCount('GroupNesting', $params, 1); } /** * Test civicrm_group_nesting_remove. */ public function testDelete() { // groups id=1 and id=2 loaded in setUp $getparams = array( 'parent_group_id' => 1, 'child_group_id' => 2, ); $result = $this->callAPISuccess('group_nesting', 'get', $getparams); $params = array('id' => $result['id']); $this->callAPIAndDocument('group_nesting', 'delete', $params, __FUNCTION__, __FILE__); $this->assertEquals(0, $this->callAPISuccess('group_nesting', 'getcount', $getparams)); } /** * Test civicrm_group_nesting_remove with empty parameter array. * * Error expected. */ public function testDeleteWithEmptyParams() { $this->callAPIFailure('group_nesting', 'delete', array()); } }