diff options
Diffstat (limited to 'www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4')
3 files changed, 168 insertions, 0 deletions
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/Action/MockArrayEntity/Get.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/Action/MockArrayEntity/Get.php new file mode 100644 index 00000000..f276baf6 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/Action/MockArrayEntity/Get.php @@ -0,0 +1,53 @@ +<?php + +namespace Civi\Api4\Action\MockArrayEntity; + +/** + * This class demonstrates how the getRecords method of Basic\Get can be overridden. + */ +class Get extends \Civi\Api4\Generic\BasicGetAction { + + public function getRecords() { + return [ + [ + 'field1' => 1, + 'field2' => 'zebra', + 'field3' => NULL, + 'field4' => [1, 2, 3], + 'field5' => 'apple', + ], + [ + 'field1' => 2, + 'field2' => 'yack', + 'field3' => 0, + 'field4' => [2, 3, 4], + 'field5' => 'banana', + 'field6' => '', + ], + [ + 'field1' => 3, + 'field2' => 'x ray', + 'field4' => [3, 4, 5], + 'field5' => 'banana', + 'field6' => 0, + ], + [ + 'field1' => 4, + 'field2' => 'wildebeest', + 'field3' => 1, + 'field4' => [4, 5, 6], + 'field5' => 'apple', + 'field6' => '0', + ], + [ + 'field1' => 5, + 'field2' => 'vole', + 'field3' => 1, + 'field4' => [4, 5, 6], + 'field5' => 'apple', + 'field6' => 0, + ], + ]; + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/MockArrayEntity.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/MockArrayEntity.php new file mode 100644 index 00000000..371df50e --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/MockArrayEntity.php @@ -0,0 +1,21 @@ +<?php + +namespace Civi\Api4; +use Civi\Api4\Generic\BasicGetFieldsAction; + +/** + * MockArrayEntity entity. + * + * @method Generic\BasicGetAction get() + * + * @package Civi\Api4 + */ +class MockArrayEntity extends Generic\AbstractEntity { + + public static function getFields() { + return new BasicGetFieldsAction(static::class, __FUNCTION__, function() { + return []; + }); + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/MockBasicEntity.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/MockBasicEntity.php new file mode 100644 index 00000000..aed11e45 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/MockBasicEntity.php @@ -0,0 +1,94 @@ +<?php + +namespace Civi\Api4; + +/** + * MockBasicEntity entity. + * + * @package Civi\Api4 + */ +class MockBasicEntity extends Generic\AbstractEntity { + + const STORAGE_CLASS = '\\Civi\\Test\\Api4\\Mock\\MockEntityDataStorage'; + + /** + * @return Generic\BasicGetFieldsAction + */ + public static function getFields() { + return new Generic\BasicGetFieldsAction(static::class, __FUNCTION__, function() { + return [ + [ + 'name' => 'id', + 'type' => 'Integer', + ], + [ + 'name' => 'group', + 'options' => [ + 'one' => 'One', + 'two' => 'Two', + ] + ], + [ + 'name' => 'color', + ], + [ + 'name' => 'shape', + ], + [ + 'name' => 'size', + ], + [ + 'name' => 'weight', + ], + ]; + }); + } + + /** + * @return Generic\BasicGetAction + */ + public static function get() { + return new Generic\BasicGetAction('MockBasicEntity', __FUNCTION__, [self::STORAGE_CLASS, 'get']); + } + + /** + * @return Generic\BasicCreateAction + */ + public static function create() { + return new Generic\BasicCreateAction(static::class, __FUNCTION__, [self::STORAGE_CLASS, 'write']); + } + + /** + * @return Generic\BasicUpdateAction + */ + public static function update() { + return new Generic\BasicUpdateAction(self::getEntityName(), __FUNCTION__, 'id', [self::STORAGE_CLASS, 'write']); + } + + /** + * @return Generic\BasicBatchAction + */ + public static function delete() { + return new Generic\BasicBatchAction('MockBasicEntity', __FUNCTION__, 'id', [self::STORAGE_CLASS, 'delete']); + } + + /** + * @return Generic\BasicBatchAction + */ + public static function batchFrobnicate() { + return new Generic\BasicBatchAction('MockBasicEntity', __FUNCTION__, ['id', 'number'], function ($item) { + return [ + 'id' => $item['id'], + 'frobnication' => $item['number'] * $item['number'], + ]; + }); + } + + /** + * @return Generic\BasicReplaceAction + */ + public static function replace() { + return new Generic\BasicReplaceAction('MockBasicEntity', __FUNCTION__); + } + +} |