From fe505aea1e9ce77b3801078fe3f3a58c93a67f8c Mon Sep 17 00:00:00 2001 From: Yurii Date: Wed, 11 Mar 2026 10:04:16 +0200 Subject: [PATCH] stream test --- application/Espo/Entities/Note.php | 10 ++ tests/integration/Espo/Stream/RecordTest.php | 109 +++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 tests/integration/Espo/Stream/RecordTest.php diff --git a/application/Espo/Entities/Note.php b/application/Espo/Entities/Note.php index b184d952a1..f1ea175a5b 100644 --- a/application/Espo/Entities/Note.php +++ b/application/Espo/Entities/Note.php @@ -351,6 +351,16 @@ class Note extends Entity return $this; } + /** + * @since 9.4.0 + */ + public function setIsInternal(bool $isInternal): self + { + $this->set('isInternal', $isInternal); + + return $this; + } + public function getParent(): ?OrmEntity { return $this->relations->getOne(Field::PARENT); diff --git a/tests/integration/Espo/Stream/RecordTest.php b/tests/integration/Espo/Stream/RecordTest.php new file mode 100644 index 0000000000..eb3d0edb9e --- /dev/null +++ b/tests/integration/Espo/Stream/RecordTest.php @@ -0,0 +1,109 @@ +. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU Affero General Public License version 3. + * + * In accordance with Section 7(b) of the GNU Affero General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +namespace tests\integration\Espo\Stream; + +use Espo\Core\Acl\Table; +use Espo\Core\ORM\Repository\Option\SaveOption; +use Espo\Core\Select\SearchParams; +use Espo\Entities\Note; +use Espo\Entities\Portal; +use Espo\Modules\Crm\Entities\CaseObj; +use Espo\Tools\Stream\RecordService; +use tests\integration\Core\BaseTestCase; + +class RecordTest extends BaseTestCase +{ + /** + * @noinspection PhpUnhandledExceptionInspection + */ + public function testPortal(): void + { + $em = $this->getEntityManager(); + + $portal = $em->createEntity(Portal::ENTITY_TYPE, ['name' => 'Test']); + + $portalUser = $this->createUser([ + 'userName' => 'test', + 'portalsIds' => [$portal->getId()], + ], [ + 'data' => [ + CaseObj::ENTITY_TYPE => [ + Table::ACTION_READ => Table::LEVEL_OWN, + Table::ACTION_STREAM => Table::LEVEL_OWN, + ] + ], + ], isPortal: true); + + $case = $em->createEntity(CaseObj::ENTITY_TYPE, [ + 'name' => 'Test', + ], [SaveOption::CREATED_BY_ID => $portalUser->getId(), SaveOption::SILENT => true]); + + $note = $em->getRDBRepositoryByClass(Note::class)->getNew(); + $note->setParent($case); + $note->setType(Note::TYPE_POST); + $em->saveEntity($note); + + $notePinned = $em->getRDBRepositoryByClass(Note::class)->getNew(); + $notePinned->setParent($case); + $notePinned->setType(Note::TYPE_POST); + $notePinned->setIsPinned(true); + $em->saveEntity($notePinned); + + $noteInternal = $em->getRDBRepositoryByClass(Note::class)->getNew(); + $noteInternal->setParent($case); + $noteInternal->setType(Note::TYPE_POST); + $noteInternal->setIsInternal(true); + $em->saveEntity($noteInternal); + + $noteInternalPinned = $em->getRDBRepositoryByClass(Note::class)->getNew(); + $noteInternalPinned->setParent($case); + $noteInternalPinned->setType(Note::TYPE_POST); + $noteInternalPinned->setIsPinned(true); + $noteInternalPinned->setIsInternal(true); + $em->saveEntity($noteInternalPinned); + + $this->auth('test', portalId: $portal->getId()); + + $app = $this->createApplication(portalId: $portal->getId()); + $this->setApplication($app); + + $service = $this->getInjectableFactory()->create(RecordService::class); + + $collection = $service->find(CaseObj::ENTITY_TYPE, $case->getId(), SearchParams::create())->getCollection(); + $pinnedCollection = $service->getPinned(CaseObj::ENTITY_TYPE, $case->getId()); + + $this->assertCount(2, $collection); + $this->assertEquals($note->getId(), $collection[1]->getId()); + $this->assertEquals($notePinned->getId(), $collection[0]->getId()); + + $this->assertCount(1, $pinnedCollection); + $this->assertEquals($notePinned->getId(), $collection[0]->getId()); + } +}