summaryrefslogtreecommitdiff
path: root/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock
diff options
context:
space:
mode:
Diffstat (limited to 'www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock')
-rw-r--r--www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/Action/MockArrayEntity/Get.php53
-rw-r--r--www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/MockArrayEntity.php21
-rw-r--r--www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/Api4/MockBasicEntity.php94
-rw-r--r--www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockEntityDataStorage.php31
-rw-r--r--www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionBase.php22
-rw-r--r--www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionChild.php16
-rw-r--r--www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionGrandchild.php17
7 files changed, 254 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__);
+ }
+
+}
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockEntityDataStorage.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockEntityDataStorage.php
new file mode 100644
index 00000000..fbb10465
--- /dev/null
+++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockEntityDataStorage.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Civi\Test\Api4\Mock;
+
+/**
+ * Simple data backend for mock basic api.
+ */
+class MockEntityDataStorage {
+
+ private static $data = [];
+
+ private static $nextId = 1;
+
+ public static function get() {
+ return self::$data;
+ }
+
+ public static function write($record) {
+ if (empty($record['id'])) {
+ $record['id'] = self::$nextId++;
+ }
+ self::$data[$record['id']] = $record;
+ return $record;
+ }
+
+ public static function delete($record) {
+ unset(self::$data[$record['id']]);
+ return $record;
+ }
+
+}
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionBase.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionBase.php
new file mode 100644
index 00000000..e46272d2
--- /dev/null
+++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionBase.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace Civi\Test\Api4\Mock;
+
+/**
+ * Class TestV4ReflectionBase
+ *
+ * This is the base class.
+ *
+ * @internal
+ */
+class MockV4ReflectionBase {
+ /**
+ * This is the foo property.
+ *
+ * In general, you can do nothing with it.
+ *
+ * @var array
+ */
+ public $foo = [];
+
+}
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionChild.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionChild.php
new file mode 100644
index 00000000..83966b5c
--- /dev/null
+++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionChild.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Civi\Test\Api4\Mock;
+
+/**
+ * @inheritDoc
+ */
+class MockV4ReflectionChild extends MockV4ReflectionBase {
+ /**
+ * @inheritDoc
+ *
+ * In the child class, foo has been barred.
+ */
+ public $foo = ['bar' => 1];
+
+}
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionGrandchild.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionGrandchild.php
new file mode 100644
index 00000000..a2a93a4f
--- /dev/null
+++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Mock/MockV4ReflectionGrandchild.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace Civi\Test\Api4\Mock;
+
+
+/**
+ * Grandchild class
+ *
+ * This is an extended description.
+ *
+ * There is a line break in this description.
+ *
+ * @inheritdoc
+ */
+class MockV4ReflectionGrandchild extends MockV4ReflectionChild {
+
+}