mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
fix test bugs
This commit is contained in:
parent
51c9d71e02
commit
8fdf9f96e7
|
|
@ -38,6 +38,20 @@ final class NullCache extends ConnectionAbstract
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function increment(int|string $key, int $value = 1) : void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function decrement(int|string $key, int $value = 1) : void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -348,7 +348,7 @@ class MailHandler
|
|||
$mailerToolFmt = '%s -oi -t';
|
||||
}
|
||||
|
||||
$mailerTool = \sprintf($mailerToolFmt, \escapeshellcmd($this->sendmail), $mail->sender);
|
||||
$mailerTool = \sprintf($mailerToolFmt, \escapeshellcmd($this->mailerTool), $mail->sender);
|
||||
|
||||
$con = \popen($mailerTool, 'w');
|
||||
if ($con === false) {
|
||||
|
|
|
|||
|
|
@ -369,6 +369,7 @@ final class ModuleManager
|
|||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage();
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
|
@ -489,7 +490,7 @@ final class ModuleManager
|
|||
{
|
||||
$installed = $this->getInstalledModules(false);
|
||||
if (isset($installed[$module])) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!\is_file($this->modulePath . $module . '/Admin/Installer.php')) {
|
||||
|
|
|
|||
|
|
@ -40,163 +40,26 @@ abstract class UninstallerAbstract
|
|||
*/
|
||||
public static function uninstall(DatabasePool $dbPool, ModuleInfo $info) : void
|
||||
{
|
||||
self::uninitRoutes($info, $appInfo);
|
||||
self::uninitHooks($info, $appInfo);
|
||||
|
||||
self::deactivate($dbPool, $info);
|
||||
self::dropTables($dbPool, $info);
|
||||
self::unregisterFromDatabase($dbPool, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall routes.
|
||||
* Activate after install.
|
||||
*
|
||||
* @param string $destRoutePath Destination route path
|
||||
* @param string $srcRoutePath Source route path
|
||||
* @param DatabasePool $dbPool Database instance
|
||||
* @param ModuleInfo $info Module info
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function uninitRoutes(string $destRoutePath, string $srcRoutePath) : void
|
||||
protected static function deactivate(DatabasePool $dbPool, ModuleInfo $info) : void
|
||||
{
|
||||
$directories = new Directory(\dirname($info->getPath()) . '/Admin/Routes');
|
||||
|
||||
/** @var Directory|File $child */
|
||||
foreach ($directories as $child) {
|
||||
if ($child instanceof Directory) {
|
||||
foreach ($child as $file) {
|
||||
if (!\is_dir(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php'))
|
||||
|| ($appInfo !== null && \basename($file->getName(), '.php') !== $appInfo->getInternalName())
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
self::uninstallRoutes(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php') . '/Routes.php', $file->getPath());
|
||||
}
|
||||
} elseif ($child instanceof File) {
|
||||
if (!\is_dir(__DIR__ . '/../../' . $child->getName())
|
||||
|| ($appInfo !== null && \basename($child->getName(), '.php') !== $appInfo->getInternalName())
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
self::uninstallRoutes(__DIR__ . '/../../' . $child->getName() . '/Routes.php', $child->getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall routes.
|
||||
*
|
||||
* @param string $destRoutePath Destination route path
|
||||
* @param string $srcRoutePath Source route path
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws PermissionException
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static function uninstallRoutes(string $destRoutePath, string $srcRoutePath) : void
|
||||
{
|
||||
if (!\is_file($destRoutePath)
|
||||
|| !\is_file($srcRoutePath)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!\is_file($destRoutePath)) {
|
||||
throw new PathException($destRoutePath);
|
||||
}
|
||||
|
||||
if (!\is_writable($destRoutePath)) {
|
||||
throw new PermissionException($destRoutePath);
|
||||
}
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
$appRoutes = include $destRoutePath;
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
$moduleRoutes = include $srcRoutePath;
|
||||
|
||||
$appRoutes = ArrayUtils::array_diff_assoc_recursive($appRoutes, $moduleRoutes);
|
||||
|
||||
\file_put_contents($destRoutePath, '<?php return ' . ArrayParser::serializeArray($appRoutes) . ';', \LOCK_EX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall hooks.
|
||||
*
|
||||
* @param string $destHookPath Destination hook path
|
||||
* @param string $srcHookPath Source hook path
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function deactivateHooks(string $destHookPath, string $srcHookPath) : void
|
||||
{
|
||||
$directories = new Directory(\dirname($info->getPath()) . '/Admin/Hooks');
|
||||
|
||||
/** @var Directory|File $child */
|
||||
foreach ($directories as $child) {
|
||||
if ($child instanceof Directory) {
|
||||
foreach ($child as $file) {
|
||||
if (!\is_dir(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php'))
|
||||
|| ($appInfo !== null && \basename($file->getName(), '.php') !== $appInfo->getInternalName())
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
self::uninstallHooks(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php') . '/Hooks.php', $file->getPath());
|
||||
}
|
||||
} elseif ($child instanceof File) {
|
||||
if (!\is_dir(__DIR__ . '/../../' . $child->getName())
|
||||
|| ($appInfo !== null && \basename($child->getName(), '.php') !== $appInfo->getInternalName())
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
self::uninstallHooks(__DIR__ . '/../../' . $child->getName() . '/Hooks.php', $child->getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall hooks.
|
||||
*
|
||||
* @param string $destHookPath Destination hook path
|
||||
* @param string $srcHookPath Source hook path
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws PermissionException
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static function uninstallHooks(string $destHookPath, string $srcHookPath) : void
|
||||
{
|
||||
if (!\is_file($destHookPath)
|
||||
|| !\is_file($srcHookPath)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!\is_file($destHookPath)) {
|
||||
throw new PathException($destHookPath);
|
||||
}
|
||||
|
||||
if (!\is_writable($destHookPath)) {
|
||||
throw new PermissionException($destHookPath);
|
||||
}
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
$appHooks = include $destHookPath;
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
$moduleHooks = include $srcHookPath;
|
||||
|
||||
$appHooks = ArrayUtils::array_diff_assoc_recursive($appHooks, $moduleHooks);
|
||||
|
||||
\file_put_contents($destHookPath, '<?php return ' . ArrayParser::serializeArray($appHooks) . ';', \LOCK_EX);
|
||||
/** @var StatusAbstract $class */
|
||||
$class = '\Modules\\' . $info->getDirectory() . '\Admin\Status';
|
||||
$class::deactivate($dbPool, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -436,8 +436,8 @@ final class ArrayUtils
|
|||
{
|
||||
$diff = [];
|
||||
foreach ($values1 as $key => $value) {
|
||||
if (!\is_array($value)) {
|
||||
if (!array_key_exists($key, $value2) || !\is_array($values2[$key])) {
|
||||
if (\is_array($value)) {
|
||||
if (!array_key_exists($key, $values2) || !\is_array($values2[$key])) {
|
||||
$diff[$key] = $value;
|
||||
} else {
|
||||
$subDiff = self::array_diff_assoc_recursive($value, $values2[$key]);
|
||||
|
|
@ -445,8 +445,8 @@ final class ArrayUtils
|
|||
$diff[$key] = $subDiff;
|
||||
}
|
||||
}
|
||||
} elseif ($values[$key] !== $value || !\array_key_exists($key, $values2)) {
|
||||
$diff[$key] == $value;
|
||||
} elseif (!\array_key_exists($key, $values2) || $values2[$key] !== $value) {
|
||||
$diff[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,4 +74,48 @@ class CsvSettings
|
|||
|
||||
return $results[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get csv string delimiter based on string content.
|
||||
*
|
||||
* @param string $content File content
|
||||
* @param int $checkLines Lines to check for evaluation
|
||||
* @param string[] $delimiters Potential delimiters
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getStringDelimiter(string $content, int $checkLines = 2, array $delimiters = [',', "\t", ';', '|', ':']) : string
|
||||
{
|
||||
$results = [];
|
||||
$lines = \explode("\n", $content);
|
||||
$i = 0;
|
||||
|
||||
do {
|
||||
$line = $lines[$i];
|
||||
foreach ($delimiters as $delimiter) {
|
||||
$regExp = '/[' . $delimiter . ']/';
|
||||
$fields = \preg_split($regExp, $line);
|
||||
|
||||
if ($fields === false) {
|
||||
return ';'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if (\count($fields) > 1) {
|
||||
if (!empty($results[$delimiter])) {
|
||||
++$results[$delimiter];
|
||||
} else {
|
||||
$results[$delimiter] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
++$i;
|
||||
} while ($i < $checkLines);
|
||||
|
||||
$results = \array_keys($results, \max($results));
|
||||
|
||||
return $results[0];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -247,7 +247,6 @@ abstract class ViewAbstract implements RenderableInterface
|
|||
} catch (\Throwable $e) {
|
||||
\ob_end_clean();
|
||||
$ob = '';
|
||||
echo $e->getMessage();
|
||||
} finally {
|
||||
return $ob;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ namespace phpOMS\tests\Message;
|
|||
|
||||
require_once __DIR__ . '/../../Autoloader.php';
|
||||
|
||||
use phpOMS\Message\Mail\Mail;
|
||||
use phpOMS\Message\Mail\MailHandler;
|
||||
use phpOMS\Message\Mail\SubmitType;
|
||||
use phpOMS\Message\Mail\Email;
|
||||
|
|
@ -30,17 +29,17 @@ use phpOMS\Message\Mail\Imap;
|
|||
class MailHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testSendTextWithMail() : void
|
||||
{/*
|
||||
{
|
||||
$mailer = new MailHandler();
|
||||
$mailer->setMailer(SubmitType::MAIL);
|
||||
|
||||
$mail = new Email();
|
||||
$mail->setFrom('d.eichhorn@orange-management.org', 'Dennis Eichhorn');
|
||||
$mail->addTo('coyle.maguire@googlemail.com', 'Donald Duck');
|
||||
$mail->setFrom('dennis.eichhorn@orange-management.org', 'Dennis Eichhorn');
|
||||
$mail->addTo('info@orange-management.org', 'Dennis Eichhorn');
|
||||
$mail->subject = 'Test email';
|
||||
$mail->body = 'This is some content';
|
||||
|
||||
self::assertTrue($mailer->send($mail));*/
|
||||
self::assertTrue($mailer->send($mail));
|
||||
}
|
||||
|
||||
public function testReceiveMailWithImap() : void
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user