mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-04 10:14:13 +08:00
Create a UnitTester bootstrap and update existing tests
- Add UnitTester to hook into codeception login when executing tests. - Create _beforeSuite and _before methods to reduce code duplication and improve performance. - Add static closures where possible for better scoping and performance. - Fix missing typehints/PHPDocs. Signed-off-by: Dillon-Brown <dillon.brown@salesagility.com>
This commit is contained in:
parent
6d976caac7
commit
9197335343
22 changed files with 265 additions and 226 deletions
|
@ -1,10 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Helper;
|
||||
|
||||
// here you can define custom actions
|
||||
// all public methods declared in helper class will be available in $I
|
||||
use Codeception\Module;
|
||||
use Codeception\TestInterface;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
|
||||
class Unit extends \Codeception\Module
|
||||
class Unit extends Module
|
||||
{
|
||||
/**
|
||||
* @var LegacyScopeState
|
||||
*/
|
||||
static public $legacyScope;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
static public $projectDir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
static public $legacyDir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
static public $legacySessionName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
static public $defaultSessionName;
|
||||
|
||||
public function _beforeSuite($settings = []): void
|
||||
{
|
||||
self::$projectDir = codecept_root_dir();
|
||||
self::$legacyDir = self::$projectDir . '/legacy';
|
||||
self::$legacySessionName = 'LEGACYSESSID';
|
||||
self::$defaultSessionName = 'PHPSESSID';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TestInterface $test
|
||||
*/
|
||||
public function _before(TestInterface $test): void
|
||||
{
|
||||
self::$legacyScope = new legacyScopeState;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Tests\Helper\Unit as Tester;
|
||||
use Codeception\Actor;
|
||||
use Codeception\Lib\Friend;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
|
@ -12,15 +18,49 @@ namespace App\Tests;
|
|||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
* @method Friend haveFriend($name, $actorClass = null)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor
|
||||
*/
|
||||
class UnitTester extends Actor
|
||||
{
|
||||
use _generated\UnitTesterActions;
|
||||
/**
|
||||
* @return LegacyScopeState
|
||||
*/
|
||||
public function getLegacyScope(): LegacyScopeState
|
||||
{
|
||||
return Tester::$legacyScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProjectDir(): string
|
||||
{
|
||||
return Tester::$projectDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLegacyDir(): string
|
||||
{
|
||||
return Tester::$legacyDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLegacySessionName(): string
|
||||
{
|
||||
return Tester::$legacySessionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultSessionName(): string
|
||||
{
|
||||
return Tester::$defaultSessionName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
actor: UnitTester
|
||||
modules:
|
||||
enabled:
|
||||
- Asserts
|
||||
- \App\Tests\Helper\Unit
|
||||
enabled:
|
||||
- Asserts
|
||||
- \App\Tests\Helper\Unit
|
||||
|
||||
bootstrap: bootstrap.php
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use ApiPlatform\Core\Exception\ItemNotFoundException;
|
||||
use App\Entity\AppListStrings;
|
||||
use Codeception\Test\Unit;
|
||||
use SuiteCRM\Core\Legacy\AppListStringsHandler;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
|
||||
class AppListStringsHandlerTest extends Unit
|
||||
{
|
||||
|
@ -20,18 +21,12 @@ class AppListStringsHandlerTest extends Unit
|
|||
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
$legacyScope = new LegacyScopeState();
|
||||
|
||||
$this->handler = new AppListStringsHandler(
|
||||
$projectDir,
|
||||
$legacyDir,
|
||||
$legacySessionName,
|
||||
$defaultSessionName,
|
||||
$legacyScope
|
||||
$this->tester->getProjectDir(),
|
||||
$this->tester->getLegacyDir(),
|
||||
$this->tester->getlegacySessionName(),
|
||||
$this->tester->getdefaultSessionName(),
|
||||
$this->tester->getLegacyScope()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -72,5 +67,4 @@ class AppListStringsHandlerTest extends Unit
|
|||
static::assertIsArray($appStrings->getItems()[$listKey]);
|
||||
static::assertNotEmpty($appStrings->getItems()[$listKey][$labelKey]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use ApiPlatform\Core\Exception\ItemNotFoundException;
|
||||
use App\Entity\AppStrings;
|
||||
use Codeception\Test\Unit;
|
||||
use SuiteCRM\Core\Legacy\AppStringsHandler;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
|
||||
class AppStringsHandlerTest extends Unit
|
||||
{
|
||||
|
@ -20,18 +21,12 @@ class AppStringsHandlerTest extends Unit
|
|||
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
$legacyScope = new LegacyScopeState();
|
||||
|
||||
$this->handler = new AppStringsHandler(
|
||||
$projectDir,
|
||||
$legacyDir,
|
||||
$legacySessionName,
|
||||
$defaultSessionName,
|
||||
$legacyScope
|
||||
$this->tester->getProjectDir(),
|
||||
$this->tester->getLegacyDir(),
|
||||
$this->tester->getlegacySessionName(),
|
||||
$this->tester->getdefaultSessionName(),
|
||||
$this->tester->getLegacyScope()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -77,4 +72,4 @@ class AppStringsHandlerTest extends Unit
|
|||
static::assertNotEmpty($appStrings->getItems()[$key]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use Codeception\Test\Unit;
|
||||
use SuiteCRM\Core\Legacy\ClassicViewRoutingExclusionsHandler;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
|
||||
class ClassicViewRoutingExclusionsHandlerTest extends Unit
|
||||
{
|
||||
|
@ -18,12 +17,11 @@ class ClassicViewRoutingExclusionsHandlerTest extends Unit
|
|||
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
$projectDir = $this->tester->getProjectDir();
|
||||
$legacyDir = $this->tester->getLegacyDir();
|
||||
$legacySessionName = $this->tester->getlegacySessionName();
|
||||
$defaultSessionName = $this->tester->getdefaultSessionName();
|
||||
$legacyScope = $this->tester->getLegacyScope();
|
||||
|
||||
$this->handler = new ClassicViewRoutingExclusionsHandler(
|
||||
$projectDir,
|
||||
|
@ -48,8 +46,8 @@ class ClassicViewRoutingExclusionsHandlerTest extends Unit
|
|||
static::assertNotEmpty($exclusions);
|
||||
static::assertArrayHasKey('any', $exclusions);
|
||||
|
||||
static::assertNotNull( $exclusions['any']);
|
||||
static::assertIsArray( $exclusions['any']);
|
||||
static::assertNotEmpty( $exclusions['any']);
|
||||
static::assertNotNull($exclusions['any']);
|
||||
static::assertIsArray($exclusions['any']);
|
||||
static::assertNotEmpty($exclusions['any']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Entity\FieldDefinition;
|
||||
use Codeception\Test\Unit;
|
||||
use SuiteCRM\Core\Legacy\FieldDefinitionsHandler;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
|
||||
final class FieldDefinitionHandlerTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @var UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* @var FieldDefinitionsHandler
|
||||
|
@ -20,20 +23,15 @@ final class FieldDefinitionHandlerTest extends Unit
|
|||
*/
|
||||
protected $fieldDefinition;
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
$legacyScope = new LegacyScopeState();
|
||||
|
||||
$this->fieldDefinitionsHandler = new FieldDefinitionsHandler($projectDir, $legacyDir, $legacySessionName,
|
||||
$defaultSessionName, $legacyScope);
|
||||
$this->fieldDefinitionsHandler = new FieldDefinitionsHandler(
|
||||
$this->tester->getProjectDir(),
|
||||
$this->tester->getLegacyDir(),
|
||||
$this->tester->getlegacySessionName(),
|
||||
$this->tester->getdefaultSessionName(),
|
||||
$this->tester->getLegacyScope()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetUserVardef(): void
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use ApiPlatform\Core\Exception\ItemNotFoundException;
|
||||
use App\Entity\ModStrings;
|
||||
use Codeception\Test\Unit;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
use SuiteCRM\Core\Legacy\ModStringsHandler;
|
||||
use SuiteCRM\Core\Legacy\ModuleNameMapperHandler;
|
||||
use SuiteCRM\Core\Legacy\ModuleRegistryHandler;
|
||||
|
@ -22,12 +23,11 @@ class ModStringsHandlerTest extends Unit
|
|||
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
$projectDir = $this->tester->getProjectDir();
|
||||
$legacyDir = $this->tester->getLegacyDir();
|
||||
$legacySessionName = $this->tester->getlegacySessionName();
|
||||
$defaultSessionName = $this->tester->getdefaultSessionName();
|
||||
$legacyScope = $this->tester->getLegacyScope();
|
||||
|
||||
$moduleNameMapper = new ModuleNameMapperHandler(
|
||||
$projectDir,
|
||||
|
@ -105,4 +105,4 @@ class ModStringsHandlerTest extends Unit
|
|||
static::assertNotEmpty($modStrings->getItems()[$module][$key]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php namespace App\Tests;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
use SuiteCRM\Core\Legacy\ModuleRegistryHandler;
|
||||
|
||||
class ModuleRegistryHandlerTest extends Unit
|
||||
|
@ -18,12 +17,11 @@ class ModuleRegistryHandlerTest extends Unit
|
|||
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
$projectDir = $this->tester->getProjectDir();
|
||||
$legacyDir = $this->tester->getLegacyDir();
|
||||
$legacySessionName = $this->tester->getlegacySessionName();
|
||||
$defaultSessionName = $this->tester->getdefaultSessionName();
|
||||
$legacyScope = $this->tester->getLegacyScope();
|
||||
|
||||
$excludedModules = [
|
||||
'EmailText',
|
||||
|
@ -56,4 +54,4 @@ class ModuleRegistryHandlerTest extends Unit
|
|||
static::assertContainsEquals('Alert', $modules);
|
||||
static::assertContainsEquals('EmailMan', $modules);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Entity\Navbar;
|
||||
use AspectMock\Test;
|
||||
use Codeception\Test\Unit;
|
||||
use SuiteCRM\Core\Legacy\ActionNameMapperHandler;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
use SuiteCRM\Core\Legacy\ModuleNameMapperHandler;
|
||||
use SuiteCRM\Core\Legacy\ModuleRegistryHandler;
|
||||
use SuiteCRM\Core\Legacy\NavbarHandler;
|
||||
|
@ -15,9 +14,9 @@ use SuiteCRM\Core\Legacy\RouteConverterHandler;
|
|||
final class NavbarTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @var NavbarHandler
|
||||
* @var UnitTester
|
||||
*/
|
||||
private $navbarHandler;
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* @var Navbar
|
||||
|
@ -25,14 +24,17 @@ final class NavbarTest extends Unit
|
|||
protected $navbar;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @var NavbarHandler
|
||||
*/
|
||||
protected function _before()
|
||||
private $navbarHandler;
|
||||
|
||||
/** @noinspection StaticClosureCanBeUsedInspection */
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
$projectDir = $this->tester->getProjectDir();
|
||||
$legacyDir = $this->tester->getLegacyDir();
|
||||
$legacySessionName = $this->tester->getlegacySessionName();
|
||||
$defaultSessionName = $this->tester->getdefaultSessionName();
|
||||
|
||||
$menuItemMap = [
|
||||
'default' => [
|
||||
|
@ -76,7 +78,7 @@ final class NavbarTest extends Unit
|
|||
],
|
||||
];
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
$legacyScope = $this->tester->getLegacyScope();
|
||||
|
||||
$moduleNameMapper = new ModuleNameMapperHandler(
|
||||
$projectDir,
|
||||
|
@ -186,7 +188,8 @@ final class NavbarTest extends Unit
|
|||
$excludedModules
|
||||
);
|
||||
|
||||
$this->navbarHandler = new NavbarHandler($projectDir,
|
||||
$this->navbarHandler = new NavbarHandler(
|
||||
$projectDir,
|
||||
$legacyDir,
|
||||
$legacySessionName,
|
||||
$defaultSessionName,
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use ApiPlatform\Core\Exception\ItemNotFoundException;
|
||||
use Codeception\Test\Unit;
|
||||
use SuiteCRM\Core\Legacy\ActionNameMapperHandler;
|
||||
use SuiteCRM\Core\Legacy\ClassicViewRoutingExclusionsHandler;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
use SuiteCRM\Core\Legacy\ModuleNameMapperHandler;
|
||||
use SuiteCRM\Core\Legacy\SystemConfigHandler;
|
||||
|
||||
|
@ -22,6 +23,12 @@ class SystemConfigHandlerTest extends Unit
|
|||
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = $this->tester->getProjectDir();
|
||||
$legacyDir = $this->tester->getLegacyDir();
|
||||
$legacySessionName = $this->tester->getlegacySessionName();
|
||||
$defaultSessionName = $this->tester->getdefaultSessionName();
|
||||
$legacyScope = $this->tester->getLegacyScope();
|
||||
|
||||
$exposedSystemConfigs = [
|
||||
'default_language' => true,
|
||||
'passwordsetting' => [
|
||||
|
@ -38,13 +45,6 @@ class SystemConfigHandlerTest extends Unit
|
|||
'action_name_map' => true
|
||||
];
|
||||
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
|
||||
$moduleMapper = new ModuleNameMapperHandler(
|
||||
$projectDir,
|
||||
$legacyDir,
|
||||
|
@ -174,4 +174,4 @@ class SystemConfigHandlerTest extends Unit
|
|||
static::assertArrayHasKey('DetailView', $actionNameMap->getItems());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use ApiPlatform\Core\Exception\ItemNotFoundException;
|
||||
use AspectMock\Test;
|
||||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
use SuiteCRM\Core\Legacy\UserPreferenceHandler;
|
||||
use User;
|
||||
|
||||
|
@ -20,11 +20,15 @@ class UserPreferencesHandlerTest extends Unit
|
|||
*/
|
||||
protected $handler;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
/** @noinspection StaticClosureCanBeUsedInspection */
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = $this->tester->getProjectDir();
|
||||
$legacyDir = $this->tester->getLegacyDir();
|
||||
$legacySessionName = $this->tester->getlegacySessionName();
|
||||
$defaultSessionName = $this->tester->getdefaultSessionName();
|
||||
$legacyScope = $this->tester->getLegacyScope();
|
||||
|
||||
$exposedUserPreferences = [
|
||||
'global' => [
|
||||
'timezone' => true
|
||||
|
@ -46,7 +50,7 @@ class UserPreferencesHandlerTest extends Unit
|
|||
User::class,
|
||||
[
|
||||
'id' => '123',
|
||||
'getPreference' => static function ($name, $category = 'global') use ($self, $mockPreferences) {
|
||||
'getPreference' => function ($name, $category = 'global') use ($self, $mockPreferences) {
|
||||
return $mockPreferences[$category][$name];
|
||||
},
|
||||
]
|
||||
|
@ -60,13 +64,6 @@ class UserPreferencesHandlerTest extends Unit
|
|||
}
|
||||
]);
|
||||
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
|
||||
$this->handler = new UserPreferenceHandler(
|
||||
$projectDir,
|
||||
$legacyDir,
|
||||
|
@ -111,4 +108,4 @@ class UserPreferencesHandlerTest extends Unit
|
|||
|
||||
static::assertEquals('UTC', $userPreferences['timezone']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
|
||||
use ApiPlatform\Core\Metadata\Resource\Factory\AnnotationResourceFilterMetadataFactory;
|
||||
|
@ -107,12 +109,12 @@ class LegacySessionDenyAccessListenerTest extends Unit
|
|||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @noinspection StaticClosureCanBeUsedInspection
|
||||
*/
|
||||
protected function _before(): void
|
||||
{
|
||||
$self = $this;
|
||||
|
||||
|
||||
test::double(ResourceMetadata::class,
|
||||
[
|
||||
'getOperationAttribute' => function (
|
||||
|
@ -215,8 +217,6 @@ class LegacySessionDenyAccessListenerTest extends Unit
|
|||
[
|
||||
'invalidate' => function () use ($self) {
|
||||
$self->invalidateCalled = true;
|
||||
|
||||
return;
|
||||
},
|
||||
]
|
||||
);
|
||||
|
@ -599,4 +599,4 @@ class LegacySessionDenyAccessListenerTest extends Unit
|
|||
$this->checkSessionCalled = false;
|
||||
$this->invalidateCalled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Security\LegacySessionLogoutHandler;
|
||||
use AspectMock\Test;
|
||||
|
@ -6,7 +8,6 @@ use AuthenticationController;
|
|||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
use SuiteCRM\Core\Legacy\Authentication;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
|
@ -15,7 +16,7 @@ use Symfony\Component\Security\Http\Logout\SessionLogoutHandler;
|
|||
class LegacySessionLogoutHandlerTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @var \App\Tests\UnitTester
|
||||
* @var UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
@ -44,16 +45,10 @@ class LegacySessionLogoutHandlerTest extends Unit
|
|||
*/
|
||||
public $closeCalled = false;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _before()
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
/** @noinspection StaticClosureCanBeUsedInspection */
|
||||
protected function _before(): void
|
||||
{
|
||||
$self = $this;
|
||||
|
||||
test::double(Authentication::class, [
|
||||
|
@ -62,7 +57,7 @@ class LegacySessionLogoutHandlerTest extends Unit
|
|||
return $self->make(
|
||||
AuthenticationController::class,
|
||||
[
|
||||
'logout' => static function (bool $redirect = true) use ($self) {
|
||||
'logout' => function () use ($self) {
|
||||
$self->logoutCalled = true;
|
||||
|
||||
return true;
|
||||
|
@ -84,26 +79,22 @@ class LegacySessionLogoutHandlerTest extends Unit
|
|||
[
|
||||
'logout' => static function (Request $request, Response $response, TokenInterface $token) use ($self) {
|
||||
$self->decoratedCalled = true;
|
||||
|
||||
return;
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
|
||||
$originalHandler = new Authentication(
|
||||
$projectDir,
|
||||
$legacyDir,
|
||||
$legacySessionName,
|
||||
$defaultSessionName,
|
||||
$legacyScope
|
||||
$this->tester->getProjectDir(),
|
||||
$this->tester->getLegacyDir(),
|
||||
$this->tester->getlegacySessionName(),
|
||||
$this->tester->getdefaultSessionName(),
|
||||
$this->tester->getLegacyScope()
|
||||
);
|
||||
|
||||
$this->handler = new LegacySessionLogoutHandler($sessionLogoutHandler, $originalHandler);
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
protected function _after(): void
|
||||
{
|
||||
$this->logoutCalled = false;
|
||||
$this->initCalled = false;
|
||||
|
@ -122,6 +113,7 @@ class LegacySessionLogoutHandlerTest extends Unit
|
|||
$request = new Request();
|
||||
$response = new Response();
|
||||
$token = $this->makeEmpty(TokenInterface::class, []);
|
||||
/** @var TokenInterface $token */
|
||||
$this->handler->logout($request, $response, $token);
|
||||
|
||||
static::assertTrue($this->logoutCalled);
|
||||
|
@ -129,4 +121,4 @@ class LegacySessionLogoutHandlerTest extends Unit
|
|||
static::assertTrue($this->logoutCalled);
|
||||
static::assertTrue($this->decoratedCalled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
|
||||
use ApiPlatform\Core\GraphQl\Resolver\Stage\SecurityStage;
|
||||
|
@ -8,7 +10,6 @@ use ApiPlatform\Core\Security\ResourceAccessCheckerInterface;
|
|||
use App\Security\LegacySessionSecurityStage;
|
||||
use AspectMock\Test;
|
||||
use Codeception\Test\Unit;
|
||||
use Doctrine\Common\Annotations\AnnotationException;
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Exception;
|
||||
use GraphQL\Error\Error;
|
||||
|
@ -98,8 +99,8 @@ class LegacySessionSecurityStageTest extends Unit
|
|||
|
||||
/**
|
||||
* Before test hook
|
||||
* @throws AnnotationException
|
||||
* @throws Exception
|
||||
* @noinspection StaticClosureCanBeUsedInspection
|
||||
*/
|
||||
protected function _before(): void
|
||||
{
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Service\ActionNameMapperInterface;
|
||||
use \Codeception\Test\Unit;
|
||||
use Codeception\Test\Unit;
|
||||
use SuiteCRM\Core\Legacy\ActionNameMapperHandler;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
|
||||
class ActionNameMapperTest extends Unit
|
||||
{
|
||||
|
@ -12,27 +13,19 @@ class ActionNameMapperTest extends Unit
|
|||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
/**
|
||||
* @var ActionNameMapperInterface
|
||||
*/
|
||||
private $actionMapper;
|
||||
|
||||
protected function _before()
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
|
||||
$this->actionMapper = new ActionNameMapperHandler(
|
||||
$projectDir,
|
||||
$legacyDir,
|
||||
$legacySessionName,
|
||||
$defaultSessionName,
|
||||
$legacyScope
|
||||
$this->tester->getProjectDir(),
|
||||
$this->tester->getLegacyDir(),
|
||||
$this->tester->getlegacySessionName(),
|
||||
$this->tester->getdefaultSessionName(),
|
||||
$this->tester->getLegacyScope()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -91,4 +84,4 @@ class ActionNameMapperTest extends Unit
|
|||
static::assertEquals('fake-action', $action);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Service\LegacyApiRedirectHandler;
|
||||
use Codeception\Test\Unit;
|
||||
|
@ -11,7 +13,6 @@ class LegacyApiRedirectHandlerTest extends Unit
|
|||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
/**
|
||||
* @var LegacyApiRedirectHandler
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Service\LegacyAssetRedirectHandler;
|
||||
use \Codeception\Test\Unit;
|
||||
use Codeception\Test\Unit;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class LegacyAssetRedirectHandlerTest extends Unit
|
||||
|
@ -11,7 +13,6 @@ class LegacyAssetRedirectHandlerTest extends Unit
|
|||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
/**
|
||||
* @var LegacyAssetRedirectHandler
|
||||
*/
|
||||
|
@ -118,4 +119,4 @@ class LegacyAssetRedirectHandlerTest extends Unit
|
|||
|
||||
static::assertEquals($resultingRoute, $route);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Service\LegacyNonViewActionRedirectHandler;
|
||||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
use SuiteCRM\Core\Legacy\ActionNameMapperHandler;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
use SuiteCRM\Core\Legacy\ModuleNameMapperHandler;
|
||||
use SuiteCRM\Core\Legacy\RouteConverterHandler;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -28,12 +29,11 @@ class LegacyNonViewActionRedirectHandlerTest extends Unit
|
|||
*/
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
$projectDir = $this->tester->getProjectDir();
|
||||
$legacyDir = $this->tester->getLegacyDir();
|
||||
$legacySessionName = $this->tester->getlegacySessionName();
|
||||
$defaultSessionName = $this->tester->getdefaultSessionName();
|
||||
$legacyScope = $this->tester->getLegacyScope();
|
||||
|
||||
$moduleMapper = new ModuleNameMapperHandler(
|
||||
$projectDir,
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Service\ModuleNameMapperInterface;
|
||||
use \Codeception\Test\Unit;
|
||||
use Codeception\Test\Unit;
|
||||
use InvalidArgumentException;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
use SuiteCRM\Core\Legacy\ModuleNameMapperHandler;
|
||||
|
||||
class ModuleNameMapperTest extends Unit
|
||||
|
@ -13,27 +14,19 @@ class ModuleNameMapperTest extends Unit
|
|||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
/**
|
||||
* @var ModuleNameMapperInterface
|
||||
*/
|
||||
private $moduleMapper;
|
||||
|
||||
protected function _before()
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
|
||||
$this->moduleMapper = new ModuleNameMapperHandler(
|
||||
$projectDir,
|
||||
$legacyDir,
|
||||
$legacySessionName,
|
||||
$defaultSessionName,
|
||||
$legacyScope
|
||||
$this->tester->getProjectDir(),
|
||||
$this->tester->getLegacyDir(),
|
||||
$this->tester->getlegacySessionName(),
|
||||
$this->tester->getdefaultSessionName(),
|
||||
$this->tester->getLegacyScope()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -93,4 +86,4 @@ class ModuleNameMapperTest extends Unit
|
|||
$this->moduleMapper->toCore('FakeModule');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Service\RouteConverterInterface;
|
||||
use \Codeception\Test\Unit;
|
||||
use Codeception\Test\Unit;
|
||||
use InvalidArgumentException;
|
||||
use SuiteCRM\Core\Legacy\ActionNameMapperHandler;
|
||||
use SuiteCRM\Core\Legacy\LegacyScopeState;
|
||||
use SuiteCRM\Core\Legacy\ModuleNameMapperHandler;
|
||||
use SuiteCRM\Core\Legacy\RouteConverterHandler;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -22,14 +23,13 @@ class RouteConverterTest extends Unit
|
|||
*/
|
||||
private $routeConverter;
|
||||
|
||||
protected function _before()
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
$legacyScope = new LegacyScopeState();
|
||||
$projectDir = $this->tester->getProjectDir();
|
||||
$legacyDir = $this->tester->getLegacyDir();
|
||||
$legacySessionName = $this->tester->getlegacySessionName();
|
||||
$defaultSessionName = $this->tester->getdefaultSessionName();
|
||||
$legacyScope = $this->tester->getLegacyScope();
|
||||
|
||||
$moduleMapper = new ModuleNameMapperHandler(
|
||||
$projectDir,
|
||||
|
@ -81,7 +81,7 @@ class RouteConverterTest extends Unit
|
|||
'PHP_SELF' => '/suiteinstance/index.php',
|
||||
];
|
||||
|
||||
$request = new Request($queryParams,[],[],[],[], $serverParams);
|
||||
$request = new Request($queryParams, [], [], [], [], $serverParams);
|
||||
|
||||
$valid = $this->routeConverter->isLegacyViewRoute($request);
|
||||
|
||||
|
@ -112,7 +112,7 @@ class RouteConverterTest extends Unit
|
|||
'PHP_SELF' => '/suiteinstance/index.php'
|
||||
];
|
||||
|
||||
$request = new Request($queryParams,[],[],[],[], $serverParams);
|
||||
$request = new Request($queryParams, [], [], [], [], $serverParams);
|
||||
|
||||
$valid = $this->routeConverter->isLegacyViewRoute($request);
|
||||
|
||||
|
@ -284,4 +284,4 @@ class RouteConverterTest extends Unit
|
|||
$this->routeConverter->convert($request);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php namespace App\Tests;
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Service\ThemeImageFinder;
|
||||
use App\Service\ThemeImageService;
|
||||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
|
||||
class ThemeImageServiceTest extends Unit
|
||||
|
@ -18,10 +19,7 @@ class ThemeImageServiceTest extends Unit
|
|||
*/
|
||||
protected $themeImageService;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _before()
|
||||
protected function _before(): void
|
||||
{
|
||||
$themeImagePaths = [
|
||||
'legacy/themes/default/images',
|
||||
|
@ -80,10 +78,6 @@ class ThemeImageServiceTest extends Unit
|
|||
);
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the format of the returned items is the expected
|
||||
*/
|
||||
|
@ -137,4 +131,4 @@ class ThemeImageServiceTest extends Unit
|
|||
|
||||
static::assertEquals($images->getItems(), $expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue