implement TwingleForm.create
it's meant to get used to alter the 'page' url of a TwingleProject
This commit is contained in:
parent
208d058f3f
commit
ff5cb16c67
2 changed files with 112 additions and 0 deletions
59
api/v3/TwingleForm/Create.php
Normal file
59
api/v3/TwingleForm/Create.php
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwingleForm.Create API specification (optional)
|
||||||
|
* This is used for documentation and validation.
|
||||||
|
*
|
||||||
|
* @param array $spec description of fields supported by this API call
|
||||||
|
*
|
||||||
|
* @see https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
|
||||||
|
*/
|
||||||
|
function _civicrm_api3_twingle_form_Create_spec(array &$spec) {
|
||||||
|
$spec['id'] = [
|
||||||
|
'name' => 'id',
|
||||||
|
'title' => E::ts('TwingleProject ID'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 1,
|
||||||
|
'description' => E::ts('ID of the TwingleProject campaign'),
|
||||||
|
];
|
||||||
|
$spec['page'] = [
|
||||||
|
'name' => 'page',
|
||||||
|
'title' => E::ts('TwingleProject Page URL'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 1,
|
||||||
|
'description' => E::ts('URL of the TwingleProject Page'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwingleForm.Create API
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* API result descriptor
|
||||||
|
*
|
||||||
|
* @throws CiviCRM_API3_Exception
|
||||||
|
* @see civicrm_api3_create_success
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function civicrm_api3_twingle_form_Create(array $params): array {
|
||||||
|
|
||||||
|
// filter parameters
|
||||||
|
$allowed_params = [];
|
||||||
|
_civicrm_api3_twingle_form_Create_spec($allowed_params);
|
||||||
|
$params = array_intersect_key($params, $allowed_params);
|
||||||
|
|
||||||
|
$result = civicrm_api3('TwingleProject', 'create', $params);
|
||||||
|
|
||||||
|
if ($result['is_error'] != 1) {
|
||||||
|
return civicrm_api3_create_success($result,$params,'TwingleForm', 'create',);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return civicrm_api3_create_error(
|
||||||
|
'Could not create TwingleForm: ' . $result['error_message']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
53
tests/phpunit/api/v3/TwingleForm/CreateTest.php
Normal file
53
tests/phpunit/api/v3/TwingleForm/CreateTest.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Civi\Test\HeadlessInterface;
|
||||||
|
use Civi\Test\HookInterface;
|
||||||
|
use Civi\Test\TransactionalInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwingleForm.Create API Test Case
|
||||||
|
* This is a generic test class implemented with PHPUnit.
|
||||||
|
* @group headless
|
||||||
|
*/
|
||||||
|
class api_v3_TwingleForm_CreateTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface, TransactionalInterface {
|
||||||
|
use \Civi\Test\Api3TestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up for headless tests.
|
||||||
|
*
|
||||||
|
* Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
|
||||||
|
*
|
||||||
|
* See: https://docs.civicrm.org/dev/en/latest/testing/phpunit/#civitest
|
||||||
|
*/
|
||||||
|
public function setUpHeadless() {
|
||||||
|
return \Civi\Test::headless()
|
||||||
|
->installMe(__DIR__)
|
||||||
|
->apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setup() method is executed before the test is executed (optional).
|
||||||
|
*/
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tearDown() method is executed after the test was executed (optional)
|
||||||
|
* This can be used for cleanup.
|
||||||
|
*/
|
||||||
|
public function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple example test case.
|
||||||
|
*
|
||||||
|
* Note how the function name begins with the word "test".
|
||||||
|
*/
|
||||||
|
public function testApiExample() {
|
||||||
|
$result = civicrm_api3('TwingleForm', 'Create', array('magicword' => 'sesame'));
|
||||||
|
$this->assertEquals('Twelve', $result['values'][12]['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue