params = array( 'title' => "Pcp title", 'contact_id' => 1, 'page_id' => 1, 'pcp_block_id' => 1); parent::setUp(); } /** * Test create function succeeds. */ public function testCreatePcp() { $result = $this->callAPIAndDocument('Pcp', 'create', $this->params, __FUNCTION__, __FILE__); $this->getAndCheck($this->params, $result['id'], $this->entity); } /** * Test disable a PCP succeeds. */ public function testDisablePcp() { $result = civicrm_api3('Pcp', 'create', $this->params); civicrm_api3('Pcp', 'create', array('id' => $result['id'], 'is_active' => 0)); $this->getAndCheck($this->params + array('is_active' => 0), $result['id'], $this->entity); } /** * Test get function succeeds. * * This is actually largely tested in the get * action on create. Add extra checks for any 'special' return values or * behaviours */ public function testGetPcp() { $this->createTestEntity(); $result = $this->callAPIAndDocument('Pcp', 'get', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); } /** * Check the delete function succeeds. */ public function testDeletePcp() { $entity = $this->createTestEntity(); $checkCreated = $this->callAPISuccess($this->entity, 'get', array('id' => $entity['id'])); $this->assertEquals(1, $checkCreated['count']); $this->callAPIAndDocument('Pcp', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__); $checkDeleted = $this->callAPISuccess($this->entity, 'get', array('id' => $entity['id'])); $this->assertEquals(0, $checkDeleted['count']); } /** * Test & document chained delete pattern. * * Note that explanation of the pattern * is best put in the $description variable as it will then be displayed in the * test generated examples. (these are to be found in the api/examples folder). */ public function testGetPcpChainDelete() { $description = "Demonstrates get + delete in the same call."; $subfile = 'ChainedGetDelete'; $params = array('title' => "Pcp title", 'api.Pcp.delete' => 1); $this->callAPISuccess('Pcp', 'create', $this->params); $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', array())); } }