Merge in 5.20
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentTokenTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class api_v3_PaymentTokenTest
14 * @group headless
15 */
16 class 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;
25 $this->useTransaction(TRUE);
26 parent::setUp();
27 $contactID = $this->individualCreate();
28 $this->params = [
29 'token' => "fancy-token-xxxx",
30 'contact_id' => $contactID,
31 'created_id' => $contactID,
32 'payment_processor_id' => $this->processorCreate(),
33 ];
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']);
42 $this->getAndCheck(array_merge($this->params, [$this->params]), $result['id'], 'payment_token', TRUE);
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));
55 $delete = ['id' => $entity['id']];
56 $result = $this->callAPIAndDocument('payment_token', 'delete', $delete, __FUNCTION__, __FILE__);
57
58 $checkDeleted = $this->callAPISuccess('payment_token', 'get', []);
59 $this->assertEquals(0, $checkDeleted['count']);
60 }
61
62 }