mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
impl. tests
This commit is contained in:
parent
4accb7b716
commit
a4e7957dbb
|
|
@ -45,7 +45,6 @@ abstract class InstallerAbstract
|
|||
public static function install(DatabasePool $dbPool, ApplicationInfo $info, SettingsInterface $cfgHandler) : void
|
||||
{
|
||||
self::createTables($dbPool, $info);
|
||||
self::installSettings($dbPool, $info, $cfgHandler);
|
||||
self::activate($dbPool, $info);
|
||||
self::installTheme(static::PATH . '/..', 'Default');
|
||||
}
|
||||
|
|
@ -84,31 +83,6 @@ abstract class InstallerAbstract
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Install app settings.
|
||||
*
|
||||
* @param DatabasePool $dbPool Database instance
|
||||
* @param ApplicationInfo $info App info
|
||||
* @param SettingsInterface $cfgHandler Settings/Configuration handler
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function installSettings(DatabasePool $dbPool, ApplicationInfo $info, SettingsInterface $cfgHandler) : void
|
||||
{
|
||||
$path = static::PATH . '/Install/Settings.install.php';
|
||||
if (!\is_file($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = include $path;
|
||||
|
||||
foreach ($settings as $setting) {
|
||||
$cfgHandler->create($setting);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create tables for app.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -757,7 +757,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function delteRelation(string $member, mixed $id1, mixed $id2) : bool
|
||||
public static function deleteRelation(string $member, mixed $id1, mixed $id2) : bool
|
||||
{
|
||||
if (!isset(static::$hasMany[$member]) || !isset(static::$hasMany[$member]['external'])) {
|
||||
return false;
|
||||
|
|
@ -1364,7 +1364,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
return;
|
||||
}
|
||||
|
||||
foreach ($objsIds as $key => $src) {
|
||||
foreach ($objsIds as $src) {
|
||||
$relQuery = new Builder(self::$db);
|
||||
$relQuery->delete()
|
||||
->from(static::$hasMany[$propertyName]['table'])
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ final class EventManager implements \Countable
|
|||
* @return void
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function clear() : bool
|
||||
public function clear() : void
|
||||
{
|
||||
$this->groups = [];
|
||||
$this->callbacks = [];
|
||||
|
|
@ -271,7 +271,7 @@ final class EventManager implements \Countable
|
|||
private function reset(string $group) : void
|
||||
{
|
||||
if (!isset($this->groups[$group])) {
|
||||
return;
|
||||
return; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
foreach ($this->groups[$group] as $id => $ok) {
|
||||
|
|
@ -291,7 +291,7 @@ final class EventManager implements \Countable
|
|||
private function hasOutstanding(string $group) : bool
|
||||
{
|
||||
if (!isset($this->groups[$group])) {
|
||||
return false;
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
foreach ($this->groups[$group] as $id => $ok) {
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ abstract class ModuleAbstract
|
|||
public static function getLocalization(string $language, string $destination) : array
|
||||
{
|
||||
$lang = [];
|
||||
if (\is_file($oldPath = self::PATH . static::NAME . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) {
|
||||
if (\is_file($oldPath = static::PATH . static::NAME . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
return include $oldPath;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class ApplicationInfoTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($jarray['dependencies'], $info->getDependencies());
|
||||
self::assertEquals($jarray['directory'], $info->getDirectory());
|
||||
self::assertEquals($jarray['version'], $info->getVersion());
|
||||
self::assertEquals($jarray['providing'], $info->getProviding());
|
||||
self::assertEquals(__DIR__ . '/info-test.json', $info->getPath());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ class ApplicationManagerTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
/**
|
||||
* @covers phpOMS\Application\ApplicationManager
|
||||
* @covers phpOMS\Application\InstallerAbstract
|
||||
* @covers phpOMS\Application\StatusAbstract
|
||||
* @group framework
|
||||
*/
|
||||
public function testInstall() : void
|
||||
|
|
@ -82,7 +84,15 @@ class ApplicationManagerTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertTrue($this->appManager->install(__DIR__ . '/Testapp', __DIR__ . '/Apps/Testapp'));
|
||||
self::assertTrue(\is_dir(__DIR__ . '/Apps/Testapp'));
|
||||
self::assertTrue(\is_file(__DIR__ . '/Apps/Testapp/css/styles.css'));
|
||||
|
||||
$apps = $this->appManager->getInstalledApplications(false, __DIR__ . '/Apps');
|
||||
self::assertTrue(isset($apps['Testapp']));
|
||||
|
||||
$providing = $this->appManager->getProvidingForModule('Navigation');
|
||||
Directory::delete(__DIR__ . '/Apps/Testapp');
|
||||
|
||||
self::assertTrue(isset($providing['Testapp']));
|
||||
self::assertTrue(\in_array('Navigation', $providing['Testapp']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -103,13 +113,4 @@ class ApplicationManagerTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
self::assertFalse($this->appManager->install(__DIR__, __DIR__ . '/newapp', __DIR__ . '/Apps/newapp'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers phpOMS\Application\ApplicationManager
|
||||
* @group framework
|
||||
*/
|
||||
public function testInstallFromModules() : void
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package \phpOMS\tess\Application\Apps\Testapp
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
return [
|
||||
'/POST:App:Testapp.*?\-create/' => [
|
||||
'callback' => ['\phpOMS\tess\Application\Apps\Testapp\Controller\Controller:testHook'],
|
||||
]
|
||||
];
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use phpOMS\Router\RouteVerb;
|
||||
|
||||
return [
|
||||
'^.*/testapp.*$' => [
|
||||
[
|
||||
'dest' => '\phpOMS\tess\Application\Apps\Testapp\Controller\Controller:testEndpoint',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'type' => 1,
|
||||
'state' => 2,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
19
tests/Application/Testapp/Admin/Install/db.json
Normal file
19
tests/Application/Testapp/Admin/Install/db.json
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"test_app": {
|
||||
"name": "test_app",
|
||||
"fields": {
|
||||
"test_app_id": {
|
||||
"name": "test_app_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"test_app_title": {
|
||||
"name": "test_app_title",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
tests/Application/Testapp/Controller/Controller.php
Normal file
29
tests/Application/Testapp/Controller/Controller.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Web\Backend
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tess\Application\Apps\Testapp\Controller;
|
||||
|
||||
use phpOMS\Module\ModuleAbstract;
|
||||
|
||||
/**
|
||||
* Home class.
|
||||
*
|
||||
* @package Web\Backend
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class Controller extends ModuleAbstract
|
||||
{
|
||||
}
|
||||
|
|
@ -16,5 +16,8 @@
|
|||
},
|
||||
"description": "The administration module.",
|
||||
"directory": "Admin",
|
||||
"providing": {
|
||||
"Navigation": "*"
|
||||
},
|
||||
"dependencies": []
|
||||
}
|
||||
|
|
@ -16,5 +16,8 @@
|
|||
},
|
||||
"description": "The administration module.",
|
||||
"directory": "Admin",
|
||||
"providing": {
|
||||
"Navigation": "*"
|
||||
},
|
||||
"dependencies": []
|
||||
}
|
||||
|
|
@ -67,6 +67,20 @@ class EventManagerTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(1, $this->event->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Events can be cleared
|
||||
* @covers phpOMS\Event\EventManager
|
||||
* @group framework
|
||||
*/
|
||||
public function testClear() : void
|
||||
{
|
||||
self::assertTrue($this->event->attach('group', function() { return true; }, false, false));
|
||||
self::assertEquals(1, $this->event->count());
|
||||
$this->event->clear();
|
||||
|
||||
self::assertEquals(0, $this->event->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Multiple callbacks can be added to an event
|
||||
* @covers phpOMS\Event\EventManager
|
||||
|
|
@ -196,7 +210,7 @@ class EventManagerTest extends \PHPUnit\Framework\TestCase
|
|||
* @covers phpOMS\Event\EventManager
|
||||
* @group framework
|
||||
*/
|
||||
public function testNoeReset() : void
|
||||
public function testNoReset() : void
|
||||
{
|
||||
self::assertTrue($this->event->attach('group', function() { return true; }, false, false));
|
||||
$this->event->addGroup('group', 'id1');
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$this->module = new class() extends ModuleAbstract
|
||||
{
|
||||
public const PATH = __DIR__ . '/';
|
||||
|
||||
const VERSION = '1.2.3';
|
||||
|
||||
const NAME = 'Test';
|
||||
|
|
@ -74,6 +76,20 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
$this->createModel(1, $model, BaseModelMapper::class, '', '127.0.0.1');
|
||||
}
|
||||
|
||||
public function createMultiple() : void
|
||||
{
|
||||
$models = [];
|
||||
|
||||
$models[] = new BaseModel();
|
||||
$models[0]->hasManyRelations = [];
|
||||
|
||||
$models[] = new BaseModel();
|
||||
$models[1]->hasManyRelations = [];
|
||||
|
||||
|
||||
$this->createModels(1, $models, BaseModelMapper::class, '', '127.0.0.1');
|
||||
}
|
||||
|
||||
public function createRelationModel() : void
|
||||
{
|
||||
$model = new ManyToManyRelModel();
|
||||
|
|
@ -88,6 +104,14 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
$this->createModelRelation(1, $model1->id, $model2->id, BaseModelMapper::class, 'hasManyRelations', '', '127.0.0.1');
|
||||
}
|
||||
|
||||
public function deleteRelationDB() : void
|
||||
{
|
||||
$model1 = BaseModelMapper::get(1);
|
||||
$model2 = ManyToManyRelModelMapper::get(1);
|
||||
|
||||
$this->deleteModelRelation(1, $model1->id, $model2->id, BaseModelMapper::class, 'hasManyRelations', '', '127.0.0.1');
|
||||
}
|
||||
|
||||
public function creates() : void
|
||||
{
|
||||
$model1 = new BaseModel();
|
||||
|
|
@ -166,6 +190,16 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertTrue(\in_array('Test2', $this->module->getReceiving()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid language or theme returns in an empty localization/language dataset
|
||||
* @covers phpOMS\Module\ModuleAbstract<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testLocalization() : void
|
||||
{
|
||||
self::assertEquals(['Test' => ['Key' => 'Value']], $this->module::getLocalization('en', 'Mytheme'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid language or theme returns in an empty localization/language dataset
|
||||
* @covers phpOMS\Module\ModuleAbstract<extended>
|
||||
|
|
@ -334,8 +368,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$this->dbSetup();
|
||||
|
||||
$this->module->create();
|
||||
$this->module->create();
|
||||
$this->module->createMultiple();
|
||||
self::assertCount(2, BaseModelMapper::getAll());
|
||||
|
||||
$this->dbTeardown();
|
||||
|
|
@ -391,6 +424,13 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
$model = BaseModelMapper::get(1);
|
||||
self::assertCount(1, $model->hasManyRelations);
|
||||
|
||||
BaseModelMapper::clearCache();
|
||||
$this->module->deleteRelationDB();
|
||||
BaseModelMapper::clearCache();
|
||||
|
||||
$model = BaseModelMapper::get(1);
|
||||
self::assertCount(0, $model->hasManyRelations);
|
||||
|
||||
$this->dbTeardown();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,6 +211,7 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
|
|||
/**
|
||||
* @testdox A module can be re-initialized
|
||||
* @covers phpOMS\Module\ModuleManager
|
||||
* @covers phpOMS\Module\StatusAbstract
|
||||
* @group framework
|
||||
*/
|
||||
public function testReInit() : void
|
||||
|
|
@ -282,6 +283,11 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
|
|||
$this->moduleManager->uninstall('TestModule');
|
||||
|
||||
self::assertFalse($this->moduleManager->uninstall('TestModule'));
|
||||
|
||||
$module = ModuleMapper::get('TestModule');
|
||||
ModuleMapper::delete($module);
|
||||
ModuleMapper::clearCache();
|
||||
|
||||
self::assertFalse($this->moduleManager->isActive('TestModule'));
|
||||
self::assertFalse($this->moduleManager->isRunning('TestModule'));
|
||||
}
|
||||
|
|
|
|||
18
tests/Module/Test/Theme/Mytheme/Lang/en.lang.php
Normal file
18
tests/Module/Test/Theme/Mytheme/Lang/en.lang.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\Localization
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
return ['Test' => [
|
||||
'Key' => 'Value',
|
||||
]
|
||||
];
|
||||
|
|
@ -83,22 +83,21 @@ class TarTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
\unlink(__DIR__ . '/test.tar');
|
||||
|
||||
/* @todo: fix this, this is not working "cannot open test.tar"
|
||||
/* @todo not working, somehow it cannot open the test.tar
|
||||
// second test
|
||||
self::assertTrue(Tar::pack(
|
||||
[__DIR__ . '/test' => 'test'],
|
||||
__DIR__ . '/test',
|
||||
__DIR__ . '/test.tar'
|
||||
));
|
||||
|
||||
self::assertTrue(Tar::unpack(__DIR__ . '/test.tar', __DIR__ . '/new_dir'));
|
||||
self::assertFileExists(__DIR__ . '/new_dir/test');
|
||||
self::assertEquals($c, \file_get_contents(__DIR__ . '/new_dir/test/test c.txt'));
|
||||
self::assertFileExists(__DIR__ . '/new_dir');
|
||||
self::assertEquals($c, \file_get_contents(__DIR__ . '/new_dir/test c.txt'));
|
||||
|
||||
\unlink(__DIR__ . '/new_dir/test/test c.txt');
|
||||
\unlink(__DIR__ . '/new_dir/test/test d.txt');
|
||||
\unlink(__DIR__ . '/new_dir/test/sub/test e.txt');
|
||||
\rmdir(__DIR__ . '/new_dir/test/sub');
|
||||
\rmdir(__DIR__ . '/new_dir/test');
|
||||
\unlink(__DIR__ . '/new_dir/test c.txt');
|
||||
\unlink(__DIR__ . '/new_dir/test d.txt');
|
||||
\unlink(__DIR__ . '/new_dir/sub/test e.txt');
|
||||
\rmdir(__DIR__ . '/new_dir/sub');
|
||||
\rmdir(__DIR__ . '/new_dir');
|
||||
|
||||
\unlink(__DIR__ . '/test.tar');
|
||||
|
|
|
|||
|
|
@ -91,14 +91,13 @@ class ZipTest extends \PHPUnit\Framework\TestCase
|
|||
));
|
||||
|
||||
self::assertTrue(Zip::unpack(__DIR__ . '/test.zip', __DIR__ . '/new_dir'));
|
||||
self::assertFileExists(__DIR__ . '/new_dir/test');
|
||||
self::assertEquals($c, \file_get_contents(__DIR__ . '/new_dir/test/test c.txt'));
|
||||
self::assertFileExists(__DIR__ . '/new_dir');
|
||||
self::assertEquals($c, \file_get_contents(__DIR__ . '/new_dir/test c.txt'));
|
||||
|
||||
\unlink(__DIR__ . '/new_dir/test/test c.txt');
|
||||
\unlink(__DIR__ . '/new_dir/test/test d.txt');
|
||||
\unlink(__DIR__ . '/new_dir/test/sub/test e.txt');
|
||||
\rmdir(__DIR__ . '/new_dir/test/sub');
|
||||
\rmdir(__DIR__ . '/new_dir/test');
|
||||
\unlink(__DIR__ . '/new_dir/test c.txt');
|
||||
\unlink(__DIR__ . '/new_dir/test d.txt');
|
||||
\unlink(__DIR__ . '/new_dir/sub/test e.txt');
|
||||
\rmdir(__DIR__ . '/new_dir/sub');
|
||||
\rmdir(__DIR__ . '/new_dir');
|
||||
|
||||
\unlink(__DIR__ . '/test.zip');
|
||||
|
|
|
|||
|
|
@ -398,7 +398,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$view = new View();
|
||||
|
||||
$view->setTemplate('/phpOMS/tests/Views/testTemplate');
|
||||
$view->setTemplate('/phpOMS/tests/Views/testReturnTemplate');
|
||||
self::assertEquals('<strong>Test</strong>', $view->build());
|
||||
}
|
||||
|
||||
|
|
|
|||
2
tests/Views/testReturnTemplate.tpl.php
Normal file
2
tests/Views/testReturnTemplate.tpl.php
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
return '<strong>Test</strong>';
|
||||
Loading…
Reference in New Issue
Block a user