snapshot of https://github.com/espocrm/espocrm.git (master, 2026-09-18; blobs > 131072B omitted)
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 0s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-18 04:19:15 +05:00
commit 7cc7e6b4f3
10077 changed files with 900756 additions and 0 deletions

View File

@@ -0,0 +1,152 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* 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 <https://www.gnu.org/licenses/>.
*
* 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\Exceptions\Forbidden;
use Espo\Core\Record\CreateParams;
use Espo\Core\Record\ServiceContainer;
use Espo\Core\Record\UpdateParams;
use Espo\Core\Select\SearchParams;
use Espo\Entities\Note;
use Espo\Modules\Crm\Entities\KnowledgeBaseArticle;
use Espo\Tools\Stream\RecordService;
use tests\integration\Core\BaseTestCase;
class AuditTest extends BaseTestCase
{
public function testAudit1(): void
{
$this->createUser('test1', [
'auditPermission' => Table::LEVEL_YES,
'data' => [
KnowledgeBaseArticle::ENTITY_TYPE => [
'create' => Table::LEVEL_NO,
'read' => Table::LEVEL_ALL,
],
]
]);
$this->createUser('test2', [
'auditPermission' => Table::LEVEL_NO,
'data' => [
KnowledgeBaseArticle::ENTITY_TYPE => [
'create' => Table::LEVEL_NO,
'read' => Table::LEVEL_ALL,
],
]
]);
$this->createUser('test3', [
'auditPermission' => Table::LEVEL_NO,
'data' => [
KnowledgeBaseArticle::ENTITY_TYPE => [
'create' => Table::LEVEL_NO,
'read' => Table::LEVEL_NO,
],
]
]);
$this->getMetadata()->set('entityDefs', KnowledgeBaseArticle::ENTITY_TYPE, [
'fields' => [
'publishDate' => [
'audited' => true,
],
],
]);
$this->getMetadata()->save();
$service = $this->getContainer()
->getByClass(ServiceContainer::class)
->getByClass(KnowledgeBaseArticle::class);
/** @noinspection PhpUnhandledExceptionInspection */
$article = $service->create((object) [
'name' => 'Test 1',
'publishDate' => '2025-01-01',
], CreateParams::create())->getEntity();
/** @noinspection PhpUnhandledExceptionInspection */
$service->update($article->getId(), (object) [
'publishDate' => '2025-01-02',
], UpdateParams::create());
$em = $this->getEntityManager();
$note = $em->getRDBRepositoryByClass(Note::class)
->where([
'parentId' => $article->getId(),
'parentType' => $article->getEntityType(),
'type' => Note::TYPE_UPDATE,
])
->findOne();
$this->assertNotNull($note);
$this->assertEquals(['publishDate'], $note->getData()?->fields);
$searchParams = SearchParams::create();
$this->authenticate('test1');
$service = $this->getInjectableFactory()->create(RecordService::class);
/** @noinspection PhpUnhandledExceptionInspection */
$recordCollection = $service->findUpdates(KnowledgeBaseArticle::ENTITY_TYPE, $article->getId(), $searchParams);
$this->assertCount(1, $recordCollection->getCollection()->getValueMapList());
$this->authenticate('test2');
$isThrown = false;
try {
$service = $this->getInjectableFactory()->create(RecordService::class);
/** @noinspection PhpUnhandledExceptionInspection */
$service->findUpdates(KnowledgeBaseArticle::ENTITY_TYPE, $article->getId(), $searchParams);
} catch (Forbidden) {
$isThrown = true;
}
$this->assertTrue($isThrown);
$this->authenticate('test3');
$isThrown = false;
try {
$service = $this->getInjectableFactory()->create(RecordService::class);
/** @noinspection PhpUnhandledExceptionInspection */
$service->findUpdates(KnowledgeBaseArticle::ENTITY_TYPE, $article->getId(), $searchParams);
} catch (Forbidden) {
$isThrown = true;
}
$this->assertTrue($isThrown);
}
}

View File

@@ -0,0 +1,135 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* 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 <https://www.gnu.org/licenses/>.
*
* 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 integration\Espo\Stream;
use Espo\Core\Acl\Table;
use Espo\Core\Field\LinkMultiple;
use Espo\Core\Name\Field;
use Espo\Modules\Crm\Entities\Account;
use Espo\Modules\Crm\Entities\Contact;
use Espo\Modules\Crm\Entities\Meeting;
use Espo\Tools\EntityManager\EntityManager;
use Espo\Tools\Stream\Service;
use tests\integration\Core\BaseTestCase;
class FollowTest extends BaseTestCase
{
/**
* @noinspection PhpUnhandledExceptionInspection
*/
public function testFollow(): void
{
$roleData = [
Account::ENTITY_TYPE => [
'create' => Table::LEVEL_NO,
'read' => Table::LEVEL_ALL,
'stream' => Table::LEVEL_ALL,
],
Contact::ENTITY_TYPE => [
'create' => Table::LEVEL_NO,
'read' => Table::LEVEL_ALL,
'stream' => Table::LEVEL_ALL,
],
Meeting::ENTITY_TYPE => [
'create' => Table::LEVEL_NO,
'read' => Table::LEVEL_ALL,
'stream' => Table::LEVEL_ALL,
],
];
$user1 = $this->createUser('test-1', [
'data' => $roleData,
]);
$user2 = $this->createUser('test-2', [
'data' => $roleData,
]);
$user3 = $this->createUser('test-3', [
'data' => $roleData,
]);
$tool = $this->getInjectableFactory()->create(EntityManager::class);
/** @noinspection PhpArrayKeyDoesNotMatchArrayShapeInspection */
$tool->update(Contact::ENTITY_TYPE, ['assignedUsers' => true]);
$this->getDataManager()->rebuildMetadata();
$this->reCreateApplication(reuse: true);
$streamService = $this->getInjectableFactory()->create(Service::class);
$em = $this->getEntityManager();
//
$account = $em->getRepositoryByClass(Account::class)->getNew();
$account->setAssignedUser($user1);
$em->saveEntity($account);
$this->assertTrue($streamService->checkIsFollowed($account, $user1->getId()));
$account->setAssignedUser($user2);
$em->saveEntity($account);
$this->assertTrue($streamService->checkIsFollowed($account, $user2->getId()));
//
$contact = $em->getRepositoryByClass(Contact::class)->getNew();
$contact->setLinkMultipleIdList(Field::ASSIGNED_USERS, [$user1->getId()]);
$em->saveEntity($contact);
$this->assertTrue($streamService->checkIsFollowed($contact, $user1->getId()));
$contact->setLinkMultipleIdList(Field::ASSIGNED_USERS, [$user2->getId()]);
$em->saveEntity($contact);
$this->assertTrue($streamService->checkIsFollowed($contact, $user2->getId()));
//
$meeting = $em->getRepositoryByClass(Meeting::class)->getNew();
$meeting->setAssignedUser($user1);
$meeting->setUsers(LinkMultiple::create()->withAddedId($user2->getId()));
$em->saveEntity($meeting);
$this->assertTrue($streamService->checkIsFollowed($meeting, $user1->getId()));
$this->assertTrue($streamService->checkIsFollowed($meeting, $user2->getId()));
$meeting->setUsers(LinkMultiple::create()->withAddedId($user3->getId()));
$em->saveEntity($meeting);
$this->assertTrue($streamService->checkIsFollowed($meeting, $user3->getId()));
}
}

View File

@@ -0,0 +1,197 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* 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 <https://www.gnu.org/licenses/>.
*
* 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\Api\Request;
use Espo\Core\Exceptions\Forbidden;
use Espo\Entities\Note;
use Espo\Modules\Crm\Entities\Account;
use Espo\Tools\Stream\Api\DeleteMyReactions;
use Espo\Tools\Stream\Api\PostMyReactions;
use Espo\Tools\Stream\MassNotePreparator;
use tests\integration\Core\BaseTestCase;
class ReactionsTest extends BaseTestCase
{
private const REACTION_LIKE = 'Like';
public function testReactions(): void
{
$userTest = $this->createUser('test', [
'data' => [
Account::ENTITY_TYPE => [
'create' => Table::LEVEL_NO,
'read' => Table::LEVEL_ALL,
'stream' => Table::LEVEL_OWN,
],
]
]);
$em = $this->getEntityManager();
$account1 = $em->getRDBRepositoryByClass(Account::class)->getNew();
$account1->setAssignedUser($userTest);
$em->saveEntity($account1);
$account2 = $em->getRDBRepositoryByClass(Account::class)->getNew();
$em->saveEntity($account2);
$note1 = $this->getEntityManager()->getRDBRepositoryByClass(Note::class)->getNew();
$note1
->setType(Note::TYPE_POST)
->setParent($account1)
->setPost('Test');
$em->saveEntity($note1);
$note2 = $this->getEntityManager()->getRDBRepositoryByClass(Note::class)->getNew();
$note2
->setType(Note::TYPE_POST)
->setParent($account2)
->setPost('Test');
$em->saveEntity($note2);
$this->authenticate('test');
// Has access.
$request = $this->createMock(Request::class);
$request->expects($this->any())
->method('getRouteParam')
->willReturnMap([
['id', $note1->getId()],
['type', self::REACTION_LIKE],
]);
/** @noinspection PhpUnhandledExceptionInspection */
$this->getInjectableFactory()
->create(PostMyReactions::class)
->process($request);
$this->getInjectableFactory()->create(MassNotePreparator::class)->prepare([$note1]);
$this->assertEquals([self::REACTION_LIKE], $note1->get('myReactions'));
$this->assertEquals(1, $note1->get('reactionCounts')->{self::REACTION_LIKE});
// Un-react.
$request = $this->createMock(Request::class);
$request->expects($this->any())
->method('getRouteParam')
->willReturnMap([
['id', $note1->getId()],
['type', self::REACTION_LIKE],
]);
/** @noinspection PhpUnhandledExceptionInspection */
$this->getInjectableFactory()
->create(DeleteMyReactions::class)
->process($request);
$this->getInjectableFactory()->create(MassNotePreparator::class)->prepare([$note1]);
$this->assertEquals([], $note1->get('myReactions'));
$this->assertEquals(0, $note1->get('reactionCounts')->{self::REACTION_LIKE} ?? 0);
// No access to note.
$isThrown = false;
try {
$request = $this->createMock(Request::class);
$request->expects($this->any())
->method('getRouteParam')
->willReturnMap([
['id', $note2->getId()],
['type', self::REACTION_LIKE],
]);
/** @noinspection PhpUnhandledExceptionInspection */
$this->getInjectableFactory()
->create(PostMyReactions::class)
->process($request);
} catch (Forbidden) {
$isThrown = true;
}
$this->assertTrue($isThrown);
// No access to note to un-react.
$isThrown = false;
try {
$request = $this->createMock(Request::class);
$request->expects($this->any())
->method('getRouteParam')
->willReturnMap([
['id', $note2->getId()],
['type', self::REACTION_LIKE],
]);
/** @noinspection PhpUnhandledExceptionInspection */
$this->getInjectableFactory()
->create(DeleteMyReactions::class)
->process($request);
} catch (Forbidden) {
$isThrown = true;
}
$this->assertTrue($isThrown);
// Not allowed reaction.
$isThrown = false;
try {
$request = $this->createMock(Request::class);
$request->expects($this->any())
->method('getRouteParam')
->willReturnMap([
['id', $note1->getId()],
['type', 'Smile'],
]);
/** @noinspection PhpUnhandledExceptionInspection */
$this->getInjectableFactory()
->create(PostMyReactions::class)
->process($request);
} catch (Forbidden) {
$isThrown = true;
}
$this->assertTrue($isThrown);
}
}

View File

@@ -0,0 +1,116 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* 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 <https://www.gnu.org/licenses/>.
*
* 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(
userName: 'test',
portalId: $portal->getId(),
);
$app = $this->createApplication(
portalId: $portal->getId(),
reuse: true,
);
$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());
}
}