From 012dc3c27d3d26ed67b10691535d2f04af704896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 13 Apr 2026 12:34:47 +0200 Subject: [PATCH] Add `StoredObjectEditorDecisionManager` with tests and interface for editability decisions - Implemented `StoredObjectEditorDecisionManager` to assess editability of stored objects based on lock status and methods. - Created `StoredObjectEditorDecisionManagerInterface` to define the contract for decision logic. - Added comprehensive test suite `StoredObjectEditorDecisionManagerTest` to validate scenarios including lock absence, conflicting lock methods, and compatible WOPI locks. --- .../StoredObjectEditorDecisionManager.php | 31 +++++++ ...edObjectEditorDecisionManagerInterface.php | 37 ++++++++ .../StoredObjectEditorDecisionManagerTest.php | 87 +++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 src/Bundle/ChillDocStoreBundle/Service/Lock/StoredObjectEditorDecisionManager.php create mode 100644 src/Bundle/ChillDocStoreBundle/Service/Lock/StoredObjectEditorDecisionManagerInterface.php create mode 100644 src/Bundle/ChillDocStoreBundle/Tests/Service/Lock/StoredObjectEditorDecisionManagerTest.php diff --git a/src/Bundle/ChillDocStoreBundle/Service/Lock/StoredObjectEditorDecisionManager.php b/src/Bundle/ChillDocStoreBundle/Service/Lock/StoredObjectEditorDecisionManager.php new file mode 100644 index 000000000..52d13b23b --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/Service/Lock/StoredObjectEditorDecisionManager.php @@ -0,0 +1,31 @@ +lockManager->hasLock($storedObject)) { + return true; + } + + $lock = $this->lockManager->getLock($storedObject); + + return StoredObjectLockMethodEnum::WOPI === $lockMethodEnum && StoredObjectLockMethodEnum::WOPI === $lock->getMethod(); + } +} diff --git a/src/Bundle/ChillDocStoreBundle/Service/Lock/StoredObjectEditorDecisionManagerInterface.php b/src/Bundle/ChillDocStoreBundle/Service/Lock/StoredObjectEditorDecisionManagerInterface.php new file mode 100644 index 000000000..339c9a22a --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/Service/Lock/StoredObjectEditorDecisionManagerInterface.php @@ -0,0 +1,37 @@ +lockManager = $this->prophesize(StoredObjectLockManager::class); + $this->decisionManager = new StoredObjectEditorDecisionManager($this->lockManager->reveal()); + } + + public function testCanEditReturnsTrueIfNoLock(): void + { + $storedObject = $this->prophesize(StoredObject::class)->reveal(); + $this->lockManager->hasLock($storedObject)->willReturn(false); + + $this->assertTrue($this->decisionManager->canEdit($storedObject, StoredObjectLockMethodEnum::WEBDAV)); + $this->assertTrue($this->decisionManager->canEdit($storedObject, StoredObjectLockMethodEnum::WOPI)); + } + + public function testCanEditReturnsFalseIfExistingLockIsWebdav(): void + { + $storedObject = $this->prophesize(StoredObject::class)->reveal(); + $lock = $this->prophesize(StoredObjectLock::class); + $lock->getMethod()->willReturn(StoredObjectLockMethodEnum::WEBDAV); + + $this->lockManager->hasLock($storedObject)->willReturn(true); + $this->lockManager->getLock($storedObject)->willReturn($lock->reveal()); + + // Always false if existing lock is Webdav + $this->assertFalse($this->decisionManager->canEdit($storedObject, StoredObjectLockMethodEnum::WEBDAV)); + $this->assertFalse($this->decisionManager->canEdit($storedObject, StoredObjectLockMethodEnum::WOPI)); + } + + public function testCanEditReturnsTrueIfBothAreWopi(): void + { + $storedObject = $this->prophesize(StoredObject::class)->reveal(); + $lock = $this->prophesize(StoredObjectLock::class); + $lock->getMethod()->willReturn(StoredObjectLockMethodEnum::WOPI); + + $this->lockManager->hasLock($storedObject)->willReturn(true); + $this->lockManager->getLock($storedObject)->willReturn($lock->reveal()); + + $this->assertTrue($this->decisionManager->canEdit($storedObject, StoredObjectLockMethodEnum::WOPI)); + } + + public function testCanEditReturnsFalseIfExistingLockIsWopiButRequestedIsWebdav(): void + { + $storedObject = $this->prophesize(StoredObject::class)->reveal(); + $lock = $this->prophesize(StoredObjectLock::class); + $lock->getMethod()->willReturn(StoredObjectLockMethodEnum::WOPI); + + $this->lockManager->hasLock($storedObject)->willReturn(true); + $this->lockManager->getLock($storedObject)->willReturn($lock->reveal()); + + $this->assertFalse($this->decisionManager->canEdit($storedObject, StoredObjectLockMethodEnum::WEBDAV)); + } +}