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,81 @@
<?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\unit\Espo\Core\Api;
use Espo\Core\Api\ControllerActionProcessor;
use Espo\Core\Api\RequestWrapper;
use Espo\Core\Api\ResponseWrapper;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\ClassFinder;
use PHPUnit\Framework\TestCase;
use tests\unit\testClasses\Controllers\TestController;
class ActionProcessorTest extends TestCase
{
/**
* @noinspection PhpUnhandledExceptionInspection
*/
public function testAction1()
{
$classFinder = $this->createMock(ClassFinder::class);
$injectableFactory = $this->createMock(InjectableFactory::class);
$request = $this->createMock(RequestWrapper::class);
$response = $this->createMock(ResponseWrapper::class);
$actionProcessor = new ControllerActionProcessor($injectableFactory, $classFinder);
$controller = $this->getMockBuilder(TestController::class)->disableOriginalConstructor()->getMock();
$classFinder
->expects($this->once())
->method('find')
->with('Controllers', 'Test')
->willReturn(TestController::class);
$request
->expects($this->once())
->method('getMethod')
->willReturn('POST');
$injectableFactory
->expects($this->once())
->method('createWith')
->with(TestController::class, ['name' => 'Test'])
->willReturn($controller);
$controller
->expects($this->once())
->method('postActionHello')
->with($request, $response);
$actionProcessor->process('Test', 'hello', $request, $response);
}
}

View File

@@ -0,0 +1,272 @@
<?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\unit\Espo\Core\Api;
use Espo\Core\Api\Auth;
use Espo\Core\Api\Method;
use Espo\Core\Api\RequestWrapper;
use Espo\Core\Api\Response;
use Espo\Core\Api\Route\ContentType;
use Espo\Core\Authentication\Authentication;
use Espo\Core\Authentication\AuthenticationData;
use Espo\Core\Authentication\HeaderKey;
use Espo\Core\Authentication\Login\MethodResolver;
use Espo\Core\Authentication\Result;
use Espo\Core\Authentication\Result\Data;
use Espo\Core\Utils\Json;
use Espo\Core\Utils\Log;
use Espo\Entities\User;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use RuntimeException;
use Slim\Psr7\Factory\RequestFactory;
use Slim\Psr7\Factory\StreamFactory;
class AuthTest extends TestCase
{
/**
* @noinspection PhpUnhandledExceptionInspection
*/
public function testProcessNoAuth(): void
{
$request = $this->createRequestInstance();
$response = $this->createMock(Response::class);
$authentication = $this->createMock(Authentication::class);
$authentication
->expects(self::once())
->method('login')
->willReturn(
Result::secondStepRequired($this->createMock(User::class), Data::create())
);
$auth = new Auth(
log: $this->createMock(Log::class),
authentication: $authentication,
methodResolver: $this->createMock(MethodResolver::class),
authRequired: false,
);
$result = $auth->process($request, $response);
$this->assertTrue($result->isResolvedUseNoAuth());
}
/**
* @noinspection PhpUnhandledExceptionInspection
*/
public function testProcessAuthFail(): void
{
$request = $this->createRequestInstance();
$response = $this->createMock(Response::class);
$authentication = $this->createMock(Authentication::class);
$authentication
->expects(self::once())
->method('login')
->willReturn(
Result::fail()
);
$auth = new Auth(
log: $this->createMock(Log::class),
authentication: $authentication,
methodResolver: $this->createMock(MethodResolver::class),
);
$result = $auth->process($request, $response);
$this->assertFalse($result->isResolved());
$this->assertFalse($result->isResolvedUseNoAuth());
}
/**
* @noinspection PhpUnhandledExceptionInspection
*/
public function testCgiHeader(): void
{
$request = $this->createRequest(
method: Method::GET,
headers: [
'Http-Espo-Cgi-Auth' => 'Basic ' . base64_encode('test:1'),
],
);
$response = $this->createMock(Response::class);
$authentication = $this->createMock(Authentication::class);
$authentication
->expects(self::once())
->method('login')
->with(
AuthenticationData::create()
->withUsername('test')
->withPassword('1')
)
->willReturn(
Result::success($this->createMock(User::class))
);
$auth = new Auth(
log: $this->createMock(Log::class),
authentication: $authentication,
methodResolver: $this->createMock(MethodResolver::class),
authRequired: true,
);
$result = $auth->process($request, $response);
$this->assertTrue($result->isResolved());
}
/**
* @noinspection PhpUnhandledExceptionInspection
*/
public function testCookie(): void
{
$request = $this->createRequest(
method: Method::GET,
cookieParams: [
'auth-token' => '001',
],
);
$response = $this->createMock(Response::class);
$authentication = $this->createMock(Authentication::class);
$authentication
->expects(self::once())
->method('login')
->with(
AuthenticationData::create()
->withPassword('001')
->withByTokenOnly(true)
)
->willReturn(
Result::success($this->createMock(User::class))
);
$auth = new Auth(
log: $this->createMock(Log::class),
authentication: $authentication,
methodResolver: $this->createMock(MethodResolver::class),
authRequired: true,
);
$result = $auth->process($request, $response);
$this->assertTrue($result->isResolved());
}
/**
* @noinspection PhpUnhandledExceptionInspection
*/
public function testIgnoreCookie(): void
{
$request = $this->createRequest(
method: Method::POST,
headers: [
'Sec-Fetch-Mode' => 'navigate',
'Content-Type' => ContentType::MULTIPART_FORM_DATA . '; charset=utf-8'
],
cookieParams: [
'auth-token' => '001',
]
);
$response = $this->createMock(Response::class);
$authentication = $this->createMock(Authentication::class);
$authentication
->expects(self::never())
->method('login');
$auth = new Auth(
log: $this->createMock(Log::class),
authentication: $authentication,
methodResolver: $this->createMock(MethodResolver::class),
authRequired: true,
);
$result = $auth->process($request, $response);
$this->assertFalse($result->isResolved());
}
/**
* @param array<string, string> $headers
* @param array<string, string> $queryParams
* @param array<string, string> $cookieParams
*/
public static function createRequest(
string $method,
array $queryParams = [],
array $headers = [],
?string $body = null,
array $cookieParams = [],
): RequestWrapper {
$request = (new RequestFactory())
->createRequest($method, 'http://localhost/?' . http_build_query($queryParams));
if (!$request instanceof ServerRequestInterface) {
throw new RuntimeException();
}
foreach ($headers as $name => $value) {
$request = $request->withHeader($name, $value);
}
$request = $request->withCookieParams($cookieParams);
if ($body) {
$request = $request->withBody(
(new StreamFactory)->createStream($body)
);
}
return new RequestWrapper($request, '', []);
}
private function createRequestInstance(): RequestWrapper
{
return $this->createRequest(
method: 'POST',
headers: [
'Content-Type' => 'application/json',
HeaderKey::AUTHORIZATION => base64_encode('test:1'),
],
body: Json::encode((object) []),
);
}
}

View File

@@ -0,0 +1,95 @@
<?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\unit\Espo\Core\Api;
use Espo\Core\Api\ConfigDataProvider;
use Espo\Core\Api\ErrorOutput;
use Espo\Core\Api\Request;
use Espo\Core\Api\Response;
use Espo\Core\Utils\Log;
use PHPUnit\Framework\TestCase;
use RuntimeException;
class ErrorOutputTest extends TestCase
{
public function testExceptionNotExposed(): void
{
$e = new RuntimeException();
$errorOutput = $this->createErrorOutput(exposeExceptions: false);
$request = $this->createMock(Request::class);
$response = $this->createMock(Response::class);
$response->expects(self::never())
->method('setHeader')
->with(ErrorOutput::HEADER_STATUS_REASON);
$errorOutput->process($request, $response, $e);
}
public function testExceptionExposed(): void
{
$e = new RuntimeException("Test.");
$errorOutput = $this->createErrorOutput(exposeExceptions: true);
$request = $this->createMock(Request::class);
$response = $this->createMock(Response::class);
$response->expects(self::once())
->method('setHeader')
->with(ErrorOutput::HEADER_STATUS_REASON);
$errorOutput->process($request, $response, $e);
}
/**
* @return ConfigDataProvider
*/
private function createConfig(bool $exposeExceptions): ConfigDataProvider
{
$config = $this->createMock(ConfigDataProvider::class);
$config
->expects(self::any())
->method('exposeExceptions')
->willReturn($exposeExceptions);
return $config;
}
private function createErrorOutput(bool $exposeExceptions): ErrorOutput
{
return new ErrorOutput(
log: $this->createMock(Log::class),
config: $this->createConfig(exposeExceptions: $exposeExceptions),
);
}
}

View File

@@ -0,0 +1,229 @@
<?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\unit\Espo\Core\Api;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface as Psr7Request;
use Psr\Http\Message\StreamInterface;
use Slim\Psr7\Factory\RequestFactory;
use Espo\Core\Api\RequestWrapper;
class RequestTest extends TestCase
{
private $request;
protected function setUp(): void
{
$this->request = $this->getMockBuilder(Psr7Request::class)->disableOriginalConstructor()->getMock();
}
protected function createRequest(array $queryParams, array $routeParams = []) : RequestWrapper
{
$this->request
->expects($this->any())
->method('getQueryParams')
->willReturn($queryParams);
return new RequestWrapper($this->request, '', $routeParams);
}
public function testHasQueryParam()
{
$request = $this->createRequest([
'id' => '1',
]);
$this->assertTrue($request->hasQueryParam('id'));
$this->assertFalse($request->hasQueryParam('test'));
}
public function testHasRouteParam()
{
$request = $this->createRequest(
[
],
[
'id' => '1',
]
);
$this->assertTrue($request->hasRouteParam('id'));
$this->assertFalse($request->hasRouteParam('test'));
}
public function testGetQueryParam()
{
$request = $this->createRequest([
'id' => '1',
]);
$this->assertEquals('1', $request->getQueryParam('id'));
}
public function testGetRouteParam()
{
$request = $this->createRequest(
[
],
[
'id' => '1',
]
);
$this->assertEquals('1', $request->getRouteParam('id'));
}
public function testGet()
{
$request = $this->createRequest(
[
'id' => '1',
],
[
'id' => '2',
]
);
$this->assertEquals('2', $request->get('id'));
}
protected function createRequestWithBody(string $contents) : RequestWrapper
{
$body = $this->createMock(StreamInterface::class);
$body
->expects($this->any())
->method('getContents')
->willReturn($contents);
$this->request
->expects($this->any())
->method('getBody')
->willReturn($body);
$this->request
->expects($this->any())
->method('hasHeader')
->with('Content-Type')
->willReturn(true);
$this->request
->expects($this->any())
->method('getHeader')
->with('Content-Type')
->willReturn(['application/json']);
return new RequestWrapper($this->request);
}
public function testGetParsedBody()
{
$original = (object) [
'key1' => '1',
'key2' => (object) [
'key21' => [
'211',
'212',
(object) [
'2111' => '1',
],
],
],
'key3' => [
'31',
'32',
null,
],
'key4' => null,
];
$contents = json_encode($original);
$request = $this->createRequestWithBody($contents);
$parsed = $request->getParsedBody();
$anotherParsed = $request->getParsedBody();
$this->assertEquals($parsed, $original);
$this->assertEquals($parsed, $anotherParsed);
$this->assertNotSame($parsed, $anotherParsed);
$this->assertNotSame($parsed->key2, $anotherParsed->key2);
$this->assertNotSame($parsed->key2->key21[2], $anotherParsed->key2->key21[2]);
}
public function testContentType1(): void
{
$request = (new RequestFactory())
->createRequest('POST', 'http://localhost/?')
->withHeader('Content-Type', 'application/json; charset=utf-8');
$requestWrapped = new RequestWrapper($request);
$this->assertEquals('application/json', $requestWrapped->getContentType());
}
public function testContentType2(): void
{
$request = (new RequestFactory())
->createRequest('POST', 'http://localhost/?')
->withHeader('Content-Type', 'application/json');
$requestWrapped = new RequestWrapper($request);
$this->assertEquals('application/json', $requestWrapped->getContentType());
}
public function testContentTypeEmpty(): void
{
$request = (new RequestFactory())
->createRequest('POST', 'http://localhost/?');
$requestWrapped = new RequestWrapper($request);
$this->assertEquals(null, $requestWrapped->getContentType());
}
public function testHeaderAsArray(): void
{
$request = (new RequestFactory())
->createRequest('POST', 'http://localhost/?')
->withAddedHeader('Test', '1')
->withAddedHeader('Test', '2');
$requestWrapped = new RequestWrapper($request);
$this->assertEquals(['1', '2'], $requestWrapped->getHeaderAsArray('Test'));
}
}

View File

@@ -0,0 +1,61 @@
<?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\unit\Espo\Core\Api;
use Slim\Psr7\Factory\ResponseFactory;
use Espo\Core\Api\ResponseWrapper;
class ResponseTest extends \PHPUnit\Framework\TestCase
{
public function testHeaderAsArray(): void
{
$response = (new ResponseFactory())
->createResponse()
->withAddedHeader('Test', '1')
->withAddedHeader('Test', '2');
$wrapped = new ResponseWrapper($response);
$this->assertEquals(['1', '2'], $wrapped->getHeaderAsArray('Test'));
}
public function testGetHeaderNames(): void
{
$response = (new ResponseFactory())
->createResponse()
->withAddedHeader('Test', '1')
->withAddedHeader('Test', '2')
->withAddedHeader('Content-Type', 'application/json');
$wrapped = new ResponseWrapper($response);
$this->assertEquals(['Test', 'Content-Type'], $wrapped->getHeaderNames());
}
}

View File

@@ -0,0 +1,109 @@
<?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\unit\Espo\Core\Api;
use Espo\Core\Api\AuthBuilderFactory;
use Espo\Core\Api\ControllerActionProcessor;
use Espo\Core\Api\ErrorOutput;
use Espo\Core\Api\Method;
use Espo\Core\Api\MiddlewareProvider;
use Espo\Core\Api\ProcessData;
use Espo\Core\Api\Route;
use Espo\Core\Api\Route\ContentType;
use Espo\Core\Api\RouteProcessor;
use Espo\Core\ApplicationUser;
use Espo\Core\Authentication\AuthenticationFactory;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Log;
use PHPUnit\Framework\TestCase;
use Slim\Psr7\Factory\ResponseFactory;
class RouteProcessorTest extends TestCase
{
public function testConsumesFail(): void
{
$request = AuthTest::createRequest(
method: Method::POST,
headers: [
'Content-Type' => ContentType::TEXT_PLAIN,
],
);
$route = new Route(
method: Method::POST,
route: '/test',
adjustedRoute: '/test',
params: [],
noAuth: false,
consumes: [
ContentType::APPLICATION_JSON,
],
actionClassName: null,
);
$errorOutput = $this->createMock(ErrorOutput::class);
$processor = new RouteProcessor(
authenticationFactory: $this->createMock(AuthenticationFactory::class),
authBuilderFactory: $this->createMock(AuthBuilderFactory::class),
errorOutput: $errorOutput,
config: $this->createMock(Config::class),
log: $this->createMock(Log::class),
applicationUser: $this->createMock(ApplicationUser::class),
actionProcessor: $this->createMock(ControllerActionProcessor::class),
middlewareProvider: $this->createMock(MiddlewareProvider::class),
injectableFactory: $this->createMock(InjectableFactory::class),
);
$response = (new ResponseFactory())->createResponse();
$errorOutput->expects(self::once())
->method('process')
->with(
self::anything(),
self::anything(),
$this->callback(function ($e) {
return $e instanceof BadRequest;
})
);
$processor->process(
processData: new ProcessData(
route: $route,
basePath: '',
routeParams: [],
),
request: $request->toPsr7(),
response: $response,
);
}
}