summaryrefslogtreecommitdiffstats
path: root/apps/workflowengine
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2019-08-09 13:24:48 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2019-09-09 22:56:01 +0200
commit804d4fe69feb1853846ad7a4b92f01cc637daf71 (patch)
tree94bf50f1c1cdde15a823cf6ab699b697bef4b521 /apps/workflowengine
parent9a6f7cc8cb5aef8d0c9dfb29fbed4a02e331e647 (diff)
downloadnextcloud-server-804d4fe69feb1853846ad7a4b92f01cc637daf71.tar.gz
nextcloud-server-804d4fe69feb1853846ad7a4b92f01cc637daf71.zip
introducing Entity interfaces and a File one as first implementation
also adds admin settings that pass entities as initial state Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/workflowengine')
-rw-r--r--apps/workflowengine/composer/composer/autoload_classmap.php4
-rw-r--r--apps/workflowengine/composer/composer/autoload_static.php4
-rw-r--r--apps/workflowengine/lib/AppInfo/Application.php8
-rw-r--r--apps/workflowengine/lib/Entity/File.php68
-rw-r--r--apps/workflowengine/lib/Entity/GenericEntityEmitterEvent.php59
-rw-r--r--apps/workflowengine/lib/Entity/IEntityEmitterEvent.php34
-rw-r--r--apps/workflowengine/lib/Manager.php56
-rw-r--r--apps/workflowengine/lib/Settings/Admin.php126
-rw-r--r--apps/workflowengine/templates/admin.php20
-rw-r--r--apps/workflowengine/tests/ManagerTest.php71
10 files changed, 423 insertions, 27 deletions
diff --git a/apps/workflowengine/composer/composer/autoload_classmap.php b/apps/workflowengine/composer/composer/autoload_classmap.php
index 14fca1fce4d..86a77375473 100644
--- a/apps/workflowengine/composer/composer/autoload_classmap.php
+++ b/apps/workflowengine/composer/composer/autoload_classmap.php
@@ -20,7 +20,11 @@ return array(
'OCA\\WorkflowEngine\\Controller\\FlowOperations' => $baseDir . '/../lib/Controller/FlowOperations.php',
'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => $baseDir . '/../lib/Controller/GlobalWorkflowsController.php',
'OCA\\WorkflowEngine\\Controller\\RequestTime' => $baseDir . '/../lib/Controller/RequestTime.php',
+ 'OCA\\WorkflowEngine\\Entity\\File' => $baseDir . '/../lib/Entity/File.php',
+ 'OCA\\WorkflowEngine\\Entity\\GenericEntityEmitterEvent' => $baseDir . '/../lib/Entity/GenericEntityEmitterEvent.php',
+ 'OCA\\WorkflowEngine\\Entity\\IEntityEmitterEvent' => $baseDir . '/../lib/Entity/IEntityEmitterEvent.php',
'OCA\\WorkflowEngine\\Manager' => $baseDir . '/../lib/Manager.php',
'OCA\\WorkflowEngine\\Migration\\Version2019Date20190808074233' => $baseDir . '/../lib/Migration/Version2019Date20190808074233.php',
+ 'OCA\\WorkflowEngine\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
'OCA\\WorkflowEngine\\Settings\\Section' => $baseDir . '/../lib/Settings/Section.php',
);
diff --git a/apps/workflowengine/composer/composer/autoload_static.php b/apps/workflowengine/composer/composer/autoload_static.php
index 7af16f53701..d13578448cf 100644
--- a/apps/workflowengine/composer/composer/autoload_static.php
+++ b/apps/workflowengine/composer/composer/autoload_static.php
@@ -35,8 +35,12 @@ class ComposerStaticInitWorkflowEngine
'OCA\\WorkflowEngine\\Controller\\FlowOperations' => __DIR__ . '/..' . '/../lib/Controller/FlowOperations.php',
'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => __DIR__ . '/..' . '/../lib/Controller/GlobalWorkflowsController.php',
'OCA\\WorkflowEngine\\Controller\\RequestTime' => __DIR__ . '/..' . '/../lib/Controller/RequestTime.php',
+ 'OCA\\WorkflowEngine\\Entity\\File' => __DIR__ . '/..' . '/../lib/Entity/File.php',
+ 'OCA\\WorkflowEngine\\Entity\\GenericEntityEmitterEvent' => __DIR__ . '/..' . '/../lib/Entity/GenericEntityEmitterEvent.php',
+ 'OCA\\WorkflowEngine\\Entity\\IEntityEmitterEvent' => __DIR__ . '/..' . '/../lib/Entity/IEntityEmitterEvent.php',
'OCA\\WorkflowEngine\\Manager' => __DIR__ . '/..' . '/../lib/Manager.php',
'OCA\\WorkflowEngine\\Migration\\Version2019Date20190808074233' => __DIR__ . '/..' . '/../lib/Migration/Version2019Date20190808074233.php',
+ 'OCA\\WorkflowEngine\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
'OCA\\WorkflowEngine\\Settings\\Section' => __DIR__ . '/..' . '/../lib/Settings/Section.php',
);
diff --git a/apps/workflowengine/lib/AppInfo/Application.php b/apps/workflowengine/lib/AppInfo/Application.php
index 3fee0c3bb8e..358353b6623 100644
--- a/apps/workflowengine/lib/AppInfo/Application.php
+++ b/apps/workflowengine/lib/AppInfo/Application.php
@@ -27,8 +27,10 @@ use OCA\WorkflowEngine\Controller\FlowOperations;
class Application extends \OCP\AppFramework\App {
+ const APP_ID = 'workflowengine';
+
public function __construct() {
- parent::__construct('workflowengine');
+ parent::__construct(self::APP_ID);
$this->getContainer()->registerAlias('FlowOperationsController', FlowOperations::class);
$this->getContainer()->registerAlias('RequestTimeController', RequestTime::class);
@@ -47,7 +49,7 @@ class Application extends \OCP\AppFramework\App {
class_exists(Template::class, true);
}
- style('workflowengine', [
+ style(self::APP_ID, [
'admin',
]);
@@ -59,7 +61,7 @@ class Application extends \OCP\AppFramework\App {
'systemtags/systemtagscollection',
]);
- script('workflowengine', [
+ script(self::APP_ID, [
'workflowengine',
]);
},
diff --git a/apps/workflowengine/lib/Entity/File.php b/apps/workflowengine/lib/Entity/File.php
new file mode 100644
index 00000000000..0ba3502450a
--- /dev/null
+++ b/apps/workflowengine/lib/Entity/File.php
@@ -0,0 +1,68 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\WorkflowEngine\Entity;
+
+use OCP\Files\IRootFolder;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\WorkflowEngine\IEntity;
+
+class File implements IEntity {
+
+ /** @var IL10N */
+ protected $l10n;
+ /** @var IURLGenerator */
+ protected $urlGenerator;
+
+ public function __construct(IL10N $l10n, IURLGenerator $urlGenerator) {
+ $this->l10n = $l10n;
+ $this->urlGenerator = $urlGenerator;
+ }
+
+ public function getId(): string {
+ return 'WorkflowEngine_Entity_File';
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('File');
+ }
+
+ public function getIcon(): string {
+ return $this->urlGenerator->imagePath('core', 'categories/files.svg');
+ }
+
+ public function getEvents(): array {
+ $emitterClass = IRootFolder::class;
+ $slot = '\OC\Files';
+ return [
+ new GenericEntityEmitterEvent($emitterClass, $slot, 'postCreate', $this->l10n->t('File created')),
+ new GenericEntityEmitterEvent($emitterClass, $slot, 'postWrite', $this->l10n->t('File updated')),
+ new GenericEntityEmitterEvent($emitterClass, $slot, 'postRename', $this->l10n->t('File renamed')),
+ new GenericEntityEmitterEvent($emitterClass, $slot, 'postDelete', $this->l10n->t('File deleted')),
+ new GenericEntityEmitterEvent($emitterClass, $slot, 'postTouch', $this->l10n->t('File accessed')),
+ new GenericEntityEmitterEvent($emitterClass, $slot, 'postCopy', $this->l10n->t('File copied')),
+ ];
+ }
+}
diff --git a/apps/workflowengine/lib/Entity/GenericEntityEmitterEvent.php b/apps/workflowengine/lib/Entity/GenericEntityEmitterEvent.php
new file mode 100644
index 00000000000..60b238432c9
--- /dev/null
+++ b/apps/workflowengine/lib/Entity/GenericEntityEmitterEvent.php
@@ -0,0 +1,59 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\WorkflowEngine\Entity;
+
+class GenericEntityEmitterEvent implements IEntityEmitterEvent {
+ /** @var string */
+ private $emitterClassName;
+ /** @var string */
+ private $eventName;
+ /** @var string */
+ private $displayName;
+ /** @var string */
+ private $slot;
+
+ public function __construct(string $emitterClassName, string $slot, string $eventName, string $displayName) {
+ $this->emitterClassName = $emitterClassName;
+ $this->eventName = $eventName;
+ $this->displayName = $displayName;
+ $this->slot = $slot;
+ }
+
+ public function getEmitterClassName(): string {
+ return $this->emitterClassName;
+ }
+
+ public function getSlot(): string {
+ return $this->slot;
+ }
+
+ public function getDisplayName(): string {
+ return $this->displayName;
+ }
+
+ public function getEventName(): string {
+ return $this->eventName;
+ }
+}
diff --git a/apps/workflowengine/lib/Entity/IEntityEmitterEvent.php b/apps/workflowengine/lib/Entity/IEntityEmitterEvent.php
new file mode 100644
index 00000000000..7e2c802fe76
--- /dev/null
+++ b/apps/workflowengine/lib/Entity/IEntityEmitterEvent.php
@@ -0,0 +1,34 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\WorkflowEngine\Entity;
+
+
+use OCP\WorkflowEngine\IEntityEvent;
+
+interface IEntityEmitterEvent extends IEntityEvent {
+ public function getEmitterClassName(): string;
+
+ public function getSlot(): string;
+}
diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php
index 23f62da4f8f..3a382f20dcd 100644
--- a/apps/workflowengine/lib/Manager.php
+++ b/apps/workflowengine/lib/Manager.php
@@ -23,6 +23,7 @@ namespace OCA\WorkflowEngine;
use OC\Files\Storage\Wrapper\Jail;
+use OCA\WorkflowEngine\Entity\File;
use OCP\AppFramework\QueryException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Storage\IStorage;
@@ -31,9 +32,12 @@ use OCP\IL10N;
use OCP\ILogger;
use OCP\IServerContainer;
use OCP\WorkflowEngine\ICheck;
+use OCP\WorkflowEngine\IEntity;
use OCP\WorkflowEngine\IEntityAware;
use OCP\WorkflowEngine\IManager;
use OCP\WorkflowEngine\IOperation;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\EventDispatcher\GenericEvent;
class Manager implements IManager, IEntityAware {
@@ -61,15 +65,32 @@ class Manager implements IManager, IEntityAware {
/** @var IL10N */
protected $l;
+ /** @var EventDispatcherInterface */
+ protected $eventDispatcher;
+
+ /** @var IEntity[] */
+ protected $registeredEntities = [];
+
+ /** @var ILogger */
+ protected $logger;
+
/**
* @param IDBConnection $connection
* @param IServerContainer $container
* @param IL10N $l
*/
- public function __construct(IDBConnection $connection, IServerContainer $container, IL10N $l) {
+ public function __construct(
+ IDBConnection $connection,
+ IServerContainer $container,
+ IL10N $l,
+ EventDispatcherInterface $eventDispatcher,
+ ILogger $logger
+ ) {
$this->connection = $connection;
$this->container = $container;
$this->l = $l;
+ $this->eventDispatcher = $eventDispatcher;
+ $this->logger = $logger;
}
/**
@@ -414,4 +435,37 @@ class Manager implements IManager, IEntityAware {
}
$this->entity = $entity;
}
+
+ /**
+ * @return IEntity[]
+ */
+ public function getEntitiesList() {
+ $this->eventDispatcher->dispatch('OCP\WorkflowEngine::registerEntities', new GenericEvent($this));
+
+ return array_merge($this->getBuildInEntities(), $this->registeredEntities);
+ }
+
+ /**
+ * Listen to 'OCP/WorkflowEngine::registerEntities' at the EventDispatcher
+ * for registering your entities
+ *
+ * @since 18.0.0
+ */
+ public function registerEntity(IEntity $entity): void {
+ $this->registeredEntities[$entity->getId()] = $entity;
+ }
+
+ /**
+ * @return IEntity[]
+ */
+ protected function getBuildInEntities(): array {
+ try {
+ return [
+ $this->container->query(File::class),
+ ];
+ } catch (QueryException $e) {
+ $this->logger->logException($e);
+ return [];
+ }
+ }
}
diff --git a/apps/workflowengine/lib/Settings/Admin.php b/apps/workflowengine/lib/Settings/Admin.php
new file mode 100644
index 00000000000..8ffd8533d3b
--- /dev/null
+++ b/apps/workflowengine/lib/Settings/Admin.php
@@ -0,0 +1,126 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\WorkflowEngine\Settings;
+
+use OCA\WorkflowEngine\AppInfo\Application;
+use OCA\WorkflowEngine\Manager;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IInitialStateService;
+use OCP\IL10N;
+use OCP\Settings\ISettings;
+use OCP\WorkflowEngine\IEntity;
+use OCP\WorkflowEngine\IEntityEvent;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+
+class Admin implements ISettings {
+
+ /** @var IL10N */
+ private $l10n;
+
+ /** @var string */
+ private $appName;
+
+ /** @var EventDispatcherInterface */
+ private $eventDispatcher;
+
+ /** @var Manager */
+ private $manager;
+
+ /** @var IInitialStateService */
+ private $initialStateService;
+
+ /**
+ * @param string $appName
+ * @param IL10N $l
+ * @param EventDispatcherInterface $eventDispatcher
+ */
+ public function __construct(
+ $appName,
+ IL10N $l,
+ EventDispatcherInterface $eventDispatcher,
+ Manager $manager,
+ IInitialStateService $initialStateService
+ ) {
+ $this->appName = $appName;
+ $this->l10n = $l;
+ $this->eventDispatcher = $eventDispatcher;
+ $this->manager = $manager;
+ $this->initialStateService = $initialStateService;
+ }
+
+ /**
+ * @return TemplateResponse
+ */
+ public function getForm() {
+ $this->eventDispatcher->dispatch('OCP\WorkflowEngine::loadAdditionalSettingScripts');
+
+ $entities = $this->manager->getEntitiesList();
+
+ $this->initialStateService->provideInitialState(
+ Application::APP_ID,
+ 'entities',
+ $this->entitiesToArray($entities)
+ );
+
+ return new TemplateResponse(Application::APP_ID, 'admin', [], 'blank');
+ }
+
+ /**
+ * @return string the section ID, e.g. 'sharing'
+ */
+ public function getSection() {
+ return 'workflow';
+ }
+
+ /**
+ * @return int whether the form should be rather on the top or bottom of
+ * the admin section. The forms are arranged in ascending order of the
+ * priority values. It is required to return a value between 0 and 100.
+ *
+ * E.g.: 70
+ */
+ public function getPriority() {
+ return 0;
+ }
+
+ private function entitiesToArray(array $entities) {
+ return array_map(function (IEntity $entity) {
+ $events = array_map(function(IEntityEvent $entityEvent) {
+ return [
+ 'eventName' => $entityEvent->getEventName(),
+ 'displayName' => $entityEvent->getDisplayName()
+ ];
+ }, $entity->getEvents());
+
+ return [
+ 'id' => $entity->getId(),
+ 'icon' => $entity->getIcon(),
+ 'name' => $entity->getName(),
+ 'events' => $events,
+ ];
+ }, $entities);
+ }
+
+}
diff --git a/apps/workflowengine/templates/admin.php b/apps/workflowengine/templates/admin.php
index d3faace71f6..04f43bb2573 100644
--- a/apps/workflowengine/templates/admin.php
+++ b/apps/workflowengine/templates/admin.php
@@ -22,22 +22,4 @@
/** @var array $_ */
/** @var \OCP\IL10N $l */
?>
-<div id="<?php p($_['appid']); ?>" class="section workflowengine">
- <h2 class="inlineblock"><?php p($_['heading']); ?></h2>
- <?php if (!empty($_['docs'])): ?>
- <a target="_blank" rel="noreferrer noopener" class="icon-info svg"
- title="<?php p($l->t('Open documentation'));?>"
- href="<?php p(link_to_docs($_['docs'])); ?>">
- </a>
- <?php endif; ?>
-
- <?php if (!empty($_['settings-hint'])): ?>
- <p class="settings-hint"><?php p($_['settings-hint']); ?></p>
- <?php endif; ?>
-
- <?php if (!empty($_['description'])): ?>
- <p><?php p($_['description']); ?></p>
- <?php endif; ?>
-
- <div class="rules"><span class="icon-loading-small"></span> <?php p($l->t('Loading…')); ?></div>
-</div>
+<div id="<?php p($_['appid']); ?>" class="<? p(\OCA\WorkflowEngine\AppInfo\Application::APP_ID); ?>"></div>
diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php
index 9136bf0e7cd..ecfc92713a0 100644
--- a/apps/workflowengine/tests/ManagerTest.php
+++ b/apps/workflowengine/tests/ManagerTest.php
@@ -22,10 +22,15 @@
namespace OCA\WorkflowEngine\Tests;
+use OCA\WorkflowEngine\Entity\File;
use OCA\WorkflowEngine\Manager;
use OCP\IDBConnection;
use OCP\IL10N;
+use OCP\ILogger;
use OCP\IServerContainer;
+use OCP\WorkflowEngine\IEntity;
+use PHPUnit\Framework\MockObject\MockObject;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
/**
@@ -38,24 +43,36 @@ class ManagerTest extends TestCase {
/** @var Manager */
protected $manager;
- /** @var IDBConnection */
+ /** @var MockObject|IDBConnection */
protected $db;
+ /** @var \PHPUnit\Framework\MockObject\MockObject|ILogger */
+ protected $logger;
+ /** @var \PHPUnit\Framework\MockObject\MockObject|EventDispatcherInterface */
+ protected $eventDispatcher;
+ /** @var MockObject|IServerContainer */
+ protected $container;
protected function setUp() {
parent::setUp();
$this->db = \OC::$server->getDatabaseConnection();
- $container = $this->createMock(IServerContainer::class);
+ $this->container = $this->createMock(IServerContainer::class);
+ /** @var IL10N|MockObject $l */
$l = $this->createMock(IL10N::class);
$l->method('t')
->will($this->returnCallback(function($text, $parameters = []) {
return vsprintf($text, $parameters);
}));
+ $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->logger = $this->createMock(ILogger::class);
+
$this->manager = new Manager(
\OC::$server->getDatabaseConnection(),
- $container,
- $l
+ $this->container,
+ $l,
+ $this->eventDispatcher,
+ $this->logger
);
$this->clearChecks();
}
@@ -91,4 +108,50 @@ class ManagerTest extends TestCase {
$this->assertArrayNotHasKey($check1, $data);
$this->assertArrayHasKey($check2, $data);
}
+
+ public function testGetEntitiesListBuildInOnly() {
+ $fileEntityMock = $this->createMock(File::class);
+
+ $this->container->expects($this->once())
+ ->method('query')
+ ->with(File::class)
+ ->willReturn($fileEntityMock);
+
+ $entities = $this->manager->getEntitiesList();
+
+ $this->assertCount(1, $entities);
+ $this->assertInstanceOf(IEntity::class, $entities[0]);
+ }
+
+ public function testGetEntitiesList() {
+ $fileEntityMock = $this->createMock(File::class);
+
+ $this->container->expects($this->once())
+ ->method('query')
+ ->with(File::class)
+ ->willReturn($fileEntityMock);
+
+ /** @var MockObject|IEntity $extraEntity */
+ $extraEntity = $this->createMock(IEntity::class);
+
+ $this->eventDispatcher->expects($this->once())
+ ->method('dispatch')
+ ->with('OCP\WorkflowEngine::registerEntities', $this->anything())
+ ->willReturnCallback(function() use ($extraEntity) {
+ $this->manager->registerEntity($extraEntity);
+ });
+
+ $entities = $this->manager->getEntitiesList();
+
+ $this->assertCount(2, $entities);
+
+ $entityTypeCounts = array_reduce($entities, function (array $carry, IEntity $entity) {
+ if($entity instanceof File) $carry[0]++;
+ else if($entity instanceof IEntity) $carry[1]++;
+ return $carry;
+ }, [0, 0]);
+
+ $this->assertSame(1, $entityTypeCounts[0]);
+ $this->assertSame(1, $entityTypeCounts[1]);
+ }
}