From b025fef896d5a0acf139c6835218ec3ac7aec5cc Mon Sep 17 00:00:00 2001 From: ggargani Date: Thu, 15 Sep 2016 23:06:32 +0200 Subject: [PATCH] Pcp api Get, Create, Delete method added Test included --- api/v3/Pcp.php | 89 ++++++++++++++++++++++ tests/phpunit/api/v3/PcpTest.php | 125 +++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 api/v3/Pcp.php create mode 100644 tests/phpunit/api/v3/PcpTest.php diff --git a/api/v3/Pcp.php b/api/v3/Pcp.php new file mode 100644 index 0000000000..28d056c460 --- /dev/null +++ b/api/v3/Pcp.php @@ -0,0 +1,89 @@ +params = array ('title' => "Pcp title", + // 'status_id' => 0, + 'contact_id' => 1, 'page_id' => 1, 'pcp_block_id' => 1); + /* + * echo "===================================================\n"; + * $dao=_civicrm_api3_get_DAO('PCP'); + * echo $dato,"\n"; + * $d = new $dao(); + * echo "---------------------------------------------------\n"; + * print_r($d->fields()); + * echo "===================================================\n"; + * die(); + */ + 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 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']); + $result = $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); + $result = $this->callAPISuccess('Pcp', 'create', $this->params); + $result = $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__, + __FILE__, $description, $subfile); + $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', array ())); + } +} \ No newline at end of file -- 2.25.1