mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-10 14:08:40 +00:00
package test and module abstract tests added
This commit is contained in:
parent
f890c78e83
commit
3e0a4f113f
|
|
@ -206,6 +206,10 @@ final class PackageManager
|
||||||
$fp = \fopen($this->basePath . '/' . $to, 'w+');
|
$fp = \fopen($this->basePath . '/' . $to, 'w+');
|
||||||
$ch = \curl_init(\str_replace(' ','%20', $from));
|
$ch = \curl_init(\str_replace(' ','%20', $from));
|
||||||
|
|
||||||
|
if ($ch === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
\curl_setopt($ch, \CURLOPT_TIMEOUT, 50);
|
\curl_setopt($ch, \CURLOPT_TIMEOUT, 50);
|
||||||
\curl_setopt($ch, \CURLOPT_FILE, $fp);
|
\curl_setopt($ch, \CURLOPT_FILE, $fp);
|
||||||
\curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, true);
|
\curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, true);
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ abstract class UpdaterAbstract
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public static function update(DatabasePool $dbPool, InfoManager $info) : void
|
public static function update(DatabasePool $dbPool, InfoManager $info) : void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,25 +16,74 @@ namespace phpOMS\tests\Module;
|
||||||
|
|
||||||
require_once __DIR__ . '/../Autoloader.php';
|
require_once __DIR__ . '/../Autoloader.php';
|
||||||
|
|
||||||
|
use phpOMS\Message\Http\Request;
|
||||||
|
use phpOMS\Message\Http\Response;
|
||||||
use phpOMS\Module\ModuleAbstract;
|
use phpOMS\Module\ModuleAbstract;
|
||||||
|
use phpOMS\Uri\Http;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
public function testModuleAbstract() : void
|
protected $module = null;
|
||||||
|
|
||||||
|
protected function setUp() : void
|
||||||
{
|
{
|
||||||
$moduleClass = new class(null) extends ModuleAbstract {
|
$this->module = new class(null) extends ModuleAbstract {
|
||||||
const MODULE_VERSION = '1.2.3';
|
const MODULE_VERSION = '1.2.3';
|
||||||
const MODULE_NAME = 'Test';
|
const MODULE_NAME = 'Test';
|
||||||
const MODULE_ID = 2;
|
const MODULE_ID = 2;
|
||||||
protected static array $dependencies = [1, 2];
|
protected static array $dependencies = [1, 2];
|
||||||
};
|
|
||||||
|
|
||||||
self::assertEquals([1, 2], $moduleClass->getDependencies());
|
public function fillJson(Request $request, Response $response, string $status, string $title, string $message, array $data) : void
|
||||||
self::assertEquals(2, $moduleClass::MODULE_ID);
|
{
|
||||||
self::assertEquals('1.2.3', $moduleClass::MODULE_VERSION);
|
$this->fillJsonResponse($request, $response, $status, $title, $message, $data);
|
||||||
self::assertEquals([], $moduleClass::getLocalization('invalid', 'invalid'));
|
}
|
||||||
|
|
||||||
|
public function fillJsonRaw(Request $request, Response $response, array $data) : void
|
||||||
|
{
|
||||||
|
$this->fillJsonRawResponse($request, $response, $data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testModuleAbstract() : void
|
||||||
|
{
|
||||||
|
self::assertEquals([1, 2], $this->module->getDependencies());
|
||||||
|
self::assertEquals(2, $this->module::MODULE_ID);
|
||||||
|
self::assertEquals('1.2.3', $this->module::MODULE_VERSION);
|
||||||
|
self::assertEquals([], $this->module::getLocalization('invalid', 'invalid'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFillJson() : void
|
||||||
|
{
|
||||||
|
$request = new Request(new Http(''));
|
||||||
|
$response = new Response();
|
||||||
|
|
||||||
|
$this->module->fillJson($request, $response, 'OK', 'Test Title', 'Test Message!', [1, 'test string', 'bool' => true]);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
[
|
||||||
|
'status' => 'OK',
|
||||||
|
'title' => 'Test Title',
|
||||||
|
'message' => 'Test Message!',
|
||||||
|
'response' => [1, 'test string', 'bool' => true],
|
||||||
|
],
|
||||||
|
$response->get('')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFillJsonRaw() : void
|
||||||
|
{
|
||||||
|
$request = new Request(new Http(''));
|
||||||
|
$response = new Response();
|
||||||
|
|
||||||
|
$this->module->fillJsonRaw($request, $response, [1, 'test string', 'bool' => true]);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
[1, 'test string', 'bool' => true],
|
||||||
|
$response->get('')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ namespace phpOMS\tests\Module;
|
||||||
require_once __DIR__ . '/../Autoloader.php';
|
require_once __DIR__ . '/../Autoloader.php';
|
||||||
|
|
||||||
use phpOMS\Module\PackageManager;
|
use phpOMS\Module\PackageManager;
|
||||||
|
use phpOMS\System\File\Ftp\File;
|
||||||
use phpOMS\System\File\Local\Directory;
|
use phpOMS\System\File\Local\Directory;
|
||||||
use phpOMS\Utils\IO\Zip\Zip;
|
use phpOMS\Utils\IO\Zip\Zip;
|
||||||
|
|
||||||
|
|
@ -81,6 +82,12 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
public function testPackageValidInstall() : void
|
public function testPackageValidInstall() : void
|
||||||
{
|
{
|
||||||
|
if (\file_exists(__DIR__ . '/dummyModule')) {
|
||||||
|
Directory::delete(__DIR__ . '/dummyModule');
|
||||||
|
}
|
||||||
|
|
||||||
|
Directory::copy(__DIR__ . '/testModule', __DIR__ . '/dummyModule');
|
||||||
|
|
||||||
$package = new PackageManager(
|
$package = new PackageManager(
|
||||||
__DIR__ . '/testPackage.zip',
|
__DIR__ . '/testPackage.zip',
|
||||||
__DIR__ . 'dummyModule/',
|
__DIR__ . 'dummyModule/',
|
||||||
|
|
@ -93,6 +100,10 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
$package->load();
|
$package->load();
|
||||||
$package->install();
|
$package->install();
|
||||||
|
|
||||||
|
if (\file_exists(__DIR__ . '/dummyModule')) {
|
||||||
|
Directory::delete(__DIR__ . '/dummyModule');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotExtractedLoad() : void
|
public function testNotExtractedLoad() : void
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user