Skip to content

Commit

Permalink
chore(tests): UT for Image
Browse files Browse the repository at this point in the history
Signed-off-by: Rubén D <[email protected]>
  • Loading branch information
nuxsmin committed Apr 28, 2024
1 parent e1dcf74 commit ce7d02f
Show file tree
Hide file tree
Showing 31 changed files with 386 additions and 311 deletions.
6 changes: 3 additions & 3 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand All @@ -26,15 +26,15 @@
use SP\Domain\Core\Bootstrap\BootstrapInterface;
use SP\Domain\Core\Bootstrap\ModuleInterface;
use SP\Modules\Api\Bootstrap;
use SP\Util\FileUtil;
use SP\Util\FileSystemUtil;

use function SP\processException;

const APP_ROOT = __DIR__;
const APP_MODULE = 'api';

try {
$dic = FileUtil::require(FileUtil::buildPath(APP_ROOT, 'lib', 'Base.php'), ContainerInterface::class);
$dic = FileSystemUtil::require(FileSystemUtil::buildPath(APP_ROOT, 'lib', 'Base.php'), ContainerInterface::class);

Bootstrap::run($dic->get(BootstrapInterface::class), $dic->get(ModuleInterface::class));
} catch (Throwable $e) {
Expand Down
10 changes: 5 additions & 5 deletions app/modules/web/Controllers/Account/ViewLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
use SP\Domain\Account\Services\PublicLink;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Crypt\VaultInterface;
use SP\Domain\Image\Ports\ImageService;
use SP\Http\Uri;
use SP\Mvc\Controller\WebControllerHelper;
use SP\Util\ErrorUtil;
use SP\Util\ImageUtil;
use SP\Util\ImageUtilInterface;
use SP\Util\Image;
use SP\Util\Serde;

/**
Expand All @@ -52,15 +52,15 @@ final class ViewLinkController extends AccountControllerBase
{
private AccountService $accountService;
private ThemeIcons $icons;
private PublicLink $publicLinkService;
private ImageUtil $imageUtil;
private PublicLink $publicLinkService;
private Image $imageUtil;

public function __construct(
Application $application,
WebControllerHelper $webControllerHelper,
AccountService $accountService,
PublicLinkService $publicLinkService,
ImageUtilInterface $imageUtil
ImageService $imageUtil
) {
parent::__construct(
$application,
Expand Down
6 changes: 3 additions & 3 deletions app/modules/web/Controllers/AccountFile/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand All @@ -31,7 +31,7 @@
use SP\Domain\Core\Exceptions\SPException;
use SP\Http\JsonMessage;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Util\FileUtil;
use SP\Util\FileSystemUtil;

/**
* Class ViewController
Expand Down Expand Up @@ -61,7 +61,7 @@ public function viewAction(int $id): bool

$this->view->addTemplate('file', 'itemshow');

if (FileUtil::isImage($fileData)) {
if (FileSystemUtil::isImage($fileData)) {
$this->view->assign('data', chunk_split(base64_encode($fileData->getContent())));
$this->view->assign('fileData', $fileData);
$this->view->assign('isImage', 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
use SP\Domain\Core\Exceptions\FileNotFoundException;
use SP\Domain\Crypt\Ports\MasterPassService;
use SP\Domain\Http\RequestInterface;
use SP\Domain\Image\Ports\ImageService;
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
use SP\Modules\Web\Controllers\Helpers\HelperBase;
use SP\Modules\Web\Controllers\Helpers\HelperException;
use SP\Mvc\View\TemplateInterface;
use SP\Util\ImageUtil;
use SP\Util\ImageUtilInterface;
use SP\Util\Image;

/**
* Class AccountPasswordHelper
Expand All @@ -53,16 +53,16 @@
*/
final class AccountPasswordHelper extends HelperBase
{
private Acl $acl;
private ImageUtil $imageUtil;
private Acl $acl;
private Image $imageUtil;
private MasterPassService $masterPassService;

public function __construct(
Application $application,
TemplateInterface $template,
RequestInterface $request,
AclInterface $acl,
ImageUtilInterface $imageUtil,
Application $application,
TemplateInterface $template,
RequestInterface $request,
AclInterface $acl,
ImageService $imageUtil,
MasterPassService $masterPassService
) {
parent::__construct($application, $template, $request);
Expand Down
10 changes: 5 additions & 5 deletions app/modules/web/Controllers/Helpers/LayoutHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use SP\Http\Uri;
use SP\Mvc\View\TemplateInterface;
use SP\Plugin\PluginManager;
use SP\Util\FileUtil;
use SP\Util\FileSystemUtil;
use SP\Util\VersionUtil;

use function SP\__;
Expand Down Expand Up @@ -171,7 +171,7 @@ protected function getResourcesLinks(): void
$jsUriTheme = new Uri($baseUrl);
$jsUriTheme->addParams(
[
'b' => FileUtil::buildPath($this->theme->getPath(), 'js'),
'b' => FileSystemUtil::buildPath($this->theme->getPath(), 'js'),
'f' => implode(',', $themeInfo['js'])
]
);
Expand Down Expand Up @@ -207,7 +207,7 @@ protected function getResourcesLinks(): void
$cssUriTheme = new Uri($baseUrl);
$cssUriTheme->addParams(
[
'b' => FileUtil::buildPath($this->theme->getPath(), 'css'),
'b' => FileSystemUtil::buildPath($this->theme->getPath(), 'css'),
'f' => implode(',', $themeInfo['css'])
]
);
Expand All @@ -228,7 +228,7 @@ protected function getResourcesLinks(): void
if (count($jsResources) > 0) {
$jsUriPlugin = new Uri($baseUrl);
$jsUriPlugin->addParams([
'b' => FileUtil::buildPath($base, 'js'),
'b' => FileSystemUtil::buildPath($base, 'js'),
'f' => implode(',', $jsResources)
]);

Expand All @@ -239,7 +239,7 @@ protected function getResourcesLinks(): void
$cssUriPlugin = new Uri($baseUrl);
$cssUriPlugin->addParams(
[
'b' => FileUtil::buildPath($base, 'css'),
'b' => FileSystemUtil::buildPath($base, 'css'),
'f' => implode(',', $cssResources)
]
);
Expand Down
10 changes: 5 additions & 5 deletions app/modules/web/Controllers/Resource/CssController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand All @@ -26,7 +26,7 @@

use SP\Http\Request as HttpRequest;
use SP\Infrastructure\File\FileHandler;
use SP\Util\FileUtil;
use SP\Util\FileSystemUtil;

/**
* Class CssController
Expand Down Expand Up @@ -57,11 +57,11 @@ public function cssAction(): void
->addFiles($files)
->getMinified();
} else {
$files = $this->buildFiles(FileUtil::buildPath(PUBLIC_PATH, 'vendor', 'css'), self::CSS_MIN_FILES);
$files = $this->buildFiles(FileSystemUtil::buildPath(PUBLIC_PATH, 'vendor', 'css'), self::CSS_MIN_FILES);

$this->minify->builder()
->addFiles($files, false)
->addFile(new FileHandler(FileUtil::buildPath(PUBLIC_PATH, 'css', 'fonts.min.css')), false)
->addFile(new FileHandler(FileSystemUtil::buildPath(PUBLIC_PATH, 'css', 'fonts.min.css')), false)
->getMinified();
}
}
Expand All @@ -77,7 +77,7 @@ private function buildFiles(string $base, array $files, bool $insecure = false):
$base = $insecure ? HttpRequest::getSecureAppPath($base) : $base;

return array_map(
fn(string $file) => new FileHandler(FileUtil::buildPath($base, $file)),
fn(string $file) => new FileHandler(FileSystemUtil::buildPath($base, $file)),
$files
);
}
Expand Down
13 changes: 8 additions & 5 deletions app/modules/web/Controllers/Resource/JsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand All @@ -26,7 +26,7 @@

use SP\Http\Request as HttpRequest;
use SP\Infrastructure\File\FileHandler;
use SP\Util\FileUtil;
use SP\Util\FileSystemUtil;

/**
* Class JsController
Expand Down Expand Up @@ -80,14 +80,17 @@ public function jsAction(): void
$this->minify
->builder()
->addFiles(
$this->buildFiles(FileUtil::buildPath(PUBLIC_PATH, 'vendor', 'js'), self::JS_MIN_FILES),
$this->buildFiles(FileSystemUtil::buildPath(PUBLIC_PATH, 'vendor', 'js'), self::JS_MIN_FILES),
false
)
->getMinified();
} elseif ($group === 1) {
$this->minify
->builder()
->addFiles($this->buildFiles(FileUtil::buildPath(PUBLIC_PATH, 'js'), self::JS_APP_MIN_FILES), false)
->addFiles(
$this->buildFiles(FileSystemUtil::buildPath(PUBLIC_PATH, 'js'), self::JS_APP_MIN_FILES),
false
)
->getMinified();
}
}
Expand All @@ -104,7 +107,7 @@ private function buildFiles(string $base, array $files, bool $insecure = false):
$base = $insecure ? HttpRequest::getSecureAppPath($base) : $base;

return array_map(
fn(string $file) => new FileHandler(FileUtil::buildPath($base, $file)),
fn(string $file) => new FileHandler(FileSystemUtil::buildPath($base, $file)),
$files
);
}
Expand Down
6 changes: 3 additions & 3 deletions cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand All @@ -24,7 +24,7 @@

use Psr\Container\ContainerInterface;
use SP\Domain\Core\Bootstrap\ModuleInterface;
use SP\Util\FileUtil;
use SP\Util\FileSystemUtil;

use function SP\logger;
use function SP\processException;
Expand All @@ -33,7 +33,7 @@
const APP_MODULE = 'cli';

try {
$dic = FileUtil::require(FileUtil::buildPath(APP_ROOT, 'lib', 'Base.php'), ContainerInterface::class);
$dic = FileSystemUtil::require(FileSystemUtil::buildPath(APP_ROOT, 'lib', 'Base.php'), ContainerInterface::class);

logger('------------');
logger('Boostrap:cli');
Expand Down
6 changes: 3 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand All @@ -26,15 +26,15 @@
use SP\Domain\Core\Bootstrap\BootstrapInterface;
use SP\Domain\Core\Bootstrap\ModuleInterface;
use SP\Modules\Web\Bootstrap;
use SP\Util\FileUtil;
use SP\Util\FileSystemUtil;

use function SP\processException;

const APP_ROOT = __DIR__;
const APP_MODULE = 'web';

try {
$dic = FileUtil::require(FileUtil::buildPath(APP_ROOT, 'lib', 'Base.php'), ContainerInterface::class);
$dic = FileSystemUtil::require(FileSystemUtil::buildPath(APP_ROOT, 'lib', 'Base.php'), ContainerInterface::class);

Bootstrap::run($dic->get(BootstrapInterface::class), $dic->get(ModuleInterface::class));
} catch (Throwable $e) {
Expand Down
6 changes: 3 additions & 3 deletions lib/BaseFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand All @@ -26,7 +26,7 @@

use Exception;
use SP\Domain\Core\Exceptions\SPException;
use SP\Util\FileUtil;
use SP\Util\FileSystemUtil;
use Throwable;

/**
Expand Down Expand Up @@ -252,7 +252,7 @@ function initModule(string $module): array
logger(sprintf('Initializing module: %s', $module));

try {
$definitions = FileUtil::require(FileUtil::buildPath(MODULES_PATH, $module, 'module.php'));
$definitions = FileSystemUtil::require(FileSystemUtil::buildPath(MODULES_PATH, $module, 'module.php'));

if (is_array($definitions)) {
return $definitions;
Expand Down
12 changes: 7 additions & 5 deletions lib/SP/Core/UI/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand All @@ -31,7 +31,7 @@
use SP\Domain\Core\UI\ThemeIconsInterface;
use SP\Domain\Core\UI\ThemeInterface;
use SP\Infrastructure\File\FileException;
use SP\Util\FileUtil;
use SP\Util\FileSystemUtil;

use function SP\processException;

Expand Down Expand Up @@ -70,8 +70,8 @@ public function getAvailable(): array
while (false !== ($themeDir = $directory->read())) {
if (is_dir($themeDir) && $themeDir !== '.' && $themeDir !== '..') {
try {
$themeInfo = FileUtil::require(
FileUtil::buildPath($this->themeContext->getViewsPath(), $themeDir, 'index.php')
$themeInfo = FileSystemUtil::require(
FileSystemUtil::buildPath($this->themeContext->getViewsPath(), $themeDir, 'index.php')
);

if (is_array($themeInfo) && isset($themeInfo['name'])) {
Expand Down Expand Up @@ -107,7 +107,9 @@ public function getViewsPath(): string
public function getInfo(): array
{
try {
$themeInfo = FileUtil::require(FileUtil::buildPath($this->themeContext->getFullPath(), 'index.php'));
$themeInfo = FileSystemUtil::require(
FileSystemUtil::buildPath($this->themeContext->getFullPath(), 'index.php')
);

if (is_array($themeInfo)) {
return $themeInfo;
Expand Down
Loading

0 comments on commit ce7d02f

Please sign in to comment.