Merge pull request #17641 from MegaphoneJon/core-1590
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentTokenTest.php
CommitLineData
607f4c2d
RT
1<?php
2/*
3 +--------------------------------------------------------------------+
7d61e75f
TO
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
607f4c2d
RT
10 */
11
607f4c2d
RT
12/**
13 * Class api_v3_PaymentTokenTest
acb109b7 14 * @group headless
607f4c2d
RT
15 */
16class api_v3_PaymentTokenTest extends CiviUnitTestCase {
17 protected $_apiversion;
18 protected $params;
19 protected $id;
20
21 public $DBResetRequired = FALSE;
22
23 public function setUp() {
24 $this->_apiversion = 3;
3265e6ae 25 $this->useTransaction(TRUE);
26 parent::setUp();
607f4c2d 27 $contactID = $this->individualCreate();
9099cab3 28 $this->params = [
607f4c2d
RT
29 'token' => "fancy-token-xxxx",
30 'contact_id' => $contactID,
31 'created_id' => $contactID,
8950ecdc 32 'payment_processor_id' => $this->processorCreate(),
9099cab3 33 ];
607f4c2d
RT
34 }
35
36 public function testCreatePaymentToken() {
37 $description = "Create a payment token - Note use of relative dates here:
38 @link http://www.php.net/manual/en/datetime.formats.relative.php.";
39 $result = $this->callAPIAndDocument('payment_token', 'create', $this->params, __FUNCTION__, __FILE__, $description);
40 $this->assertEquals(1, $result['count']);
41 $this->assertNotNull($result['values'][$result['id']]['id']);
9099cab3 42 $this->getAndCheck(array_merge($this->params, [$this->params]), $result['id'], 'payment_token', TRUE);
607f4c2d
RT
43 }
44
45 public function testGetPaymentToken() {
46 $result = $this->callAPISuccess('payment_token', 'create', $this->params);
47 $result = $this->callAPIAndDocument('payment_token', 'get', $this->params, __FUNCTION__, __FILE__);
48 $this->assertEquals(1, $result['count']);
49 $this->assertNotNull($result['values'][$result['id']]['id']);
50 }
51
52 public function testDeletePaymentToken() {
53 $this->callAPISuccess('payment_token', 'create', $this->params);
54 $entity = $this->callAPISuccess('payment_token', 'get', ($this->params));
9099cab3 55 $delete = ['id' => $entity['id']];
607f4c2d
RT
56 $result = $this->callAPIAndDocument('payment_token', 'delete', $delete, __FUNCTION__, __FILE__);
57
9099cab3 58 $checkDeleted = $this->callAPISuccess('payment_token', 'get', []);
607f4c2d
RT
59 $this->assertEquals(0, $checkDeleted['count']);
60 }
61
62}