92 lines
3.0 KiB
PHP
92 lines
3.0 KiB
PHP
<?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\Tools\Lock;
|
||
|
||
use Espo\Core\Action\ActionFactory;
|
||
use Espo\Core\Action\Data;
|
||
use Espo\Core\Action\Params;
|
||
use Espo\Core\Name\Field;
|
||
use Espo\Modules\Crm\Entities\Account;
|
||
use Espo\ORM\Exceptions\ValidationException;
|
||
use tests\integration\Core\BaseTestCase;
|
||
|
||
class LockTest extends BaseTestCase
|
||
{
|
||
/** @noinspection PhpUnhandledExceptionInspection */
|
||
public function testLock1(): void
|
||
{
|
||
$em = $this->getEntityManager();
|
||
|
||
$account = $em->getRDBRepositoryByClass(Account::class)->getNew();
|
||
$account->setName('Test');
|
||
$em->saveEntity($account);
|
||
|
||
$account->set(Field::IS_LOCKED, true);
|
||
$em->saveEntity($account);
|
||
|
||
$this->expectException(ValidationException::class);
|
||
|
||
$account->setName('Test 1');
|
||
$em->saveEntity($account);
|
||
|
||
//
|
||
|
||
$actionFactory = $this->getInjectableFactory()->create(ActionFactory::class);
|
||
|
||
$actionFactory->create('Unlock', Account::ENTITY_TYPE)->process(
|
||
params: new Params(
|
||
entityType: Account::ENTITY_TYPE,
|
||
id: $account->getId(),
|
||
),
|
||
data: Data::fromRaw((object) [])
|
||
);
|
||
|
||
|
||
$em->refreshEntity($account);
|
||
|
||
$this->assertFalse($account->get(Field::IS_LOCKED));
|
||
|
||
//
|
||
|
||
$actionFactory->create('Lock', Account::ENTITY_TYPE)->process(
|
||
params: new Params(
|
||
entityType: Account::ENTITY_TYPE,
|
||
id: $account->getId(),
|
||
),
|
||
data: Data::fromRaw((object) [])
|
||
);
|
||
|
||
|
||
$em->refreshEntity($account);
|
||
|
||
$this->assertTrue($account->get(Field::IS_LOCKED));
|
||
}
|
||
}
|