impl. tests

This commit is contained in:
Dennis Eichhorn 2021-09-30 22:14:37 +02:00
parent 4accb7b716
commit a4e7957dbb
20 changed files with 216 additions and 61 deletions

View File

@ -45,7 +45,6 @@ abstract class InstallerAbstract
public static function install(DatabasePool $dbPool, ApplicationInfo $info, SettingsInterface $cfgHandler) : void public static function install(DatabasePool $dbPool, ApplicationInfo $info, SettingsInterface $cfgHandler) : void
{ {
self::createTables($dbPool, $info); self::createTables($dbPool, $info);
self::installSettings($dbPool, $info, $cfgHandler);
self::activate($dbPool, $info); self::activate($dbPool, $info);
self::installTheme(static::PATH . '/..', 'Default'); 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. * Create tables for app.
* *

View File

@ -757,7 +757,7 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @since 1.0.0 * @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'])) { if (!isset(static::$hasMany[$member]) || !isset(static::$hasMany[$member]['external'])) {
return false; return false;
@ -1364,7 +1364,7 @@ class DataMapperAbstract implements DataMapperInterface
return; return;
} }
foreach ($objsIds as $key => $src) { foreach ($objsIds as $src) {
$relQuery = new Builder(self::$db); $relQuery = new Builder(self::$db);
$relQuery->delete() $relQuery->delete()
->from(static::$hasMany[$propertyName]['table']) ->from(static::$hasMany[$propertyName]['table'])

View File

@ -126,7 +126,7 @@ final class EventManager implements \Countable
* @return void * @return void
* @since 1.0.0 * @since 1.0.0
*/ */
public function clear() : bool public function clear() : void
{ {
$this->groups = []; $this->groups = [];
$this->callbacks = []; $this->callbacks = [];
@ -271,7 +271,7 @@ final class EventManager implements \Countable
private function reset(string $group) : void private function reset(string $group) : void
{ {
if (!isset($this->groups[$group])) { if (!isset($this->groups[$group])) {
return; return; // @codeCoverageIgnore
} }
foreach ($this->groups[$group] as $id => $ok) { foreach ($this->groups[$group] as $id => $ok) {
@ -291,7 +291,7 @@ final class EventManager implements \Countable
private function hasOutstanding(string $group) : bool private function hasOutstanding(string $group) : bool
{ {
if (!isset($this->groups[$group])) { if (!isset($this->groups[$group])) {
return false; return false; // @codeCoverageIgnore
} }
foreach ($this->groups[$group] as $id => $ok) { foreach ($this->groups[$group] as $id => $ok) {

View File

@ -121,7 +121,7 @@ abstract class ModuleAbstract
public static function getLocalization(string $language, string $destination) : array public static function getLocalization(string $language, string $destination) : array
{ {
$lang = []; $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 */ /** @noinspection PhpIncludeInspection */
return include $oldPath; return include $oldPath;
} }

View File

@ -45,6 +45,7 @@ class ApplicationInfoTest extends \PHPUnit\Framework\TestCase
self::assertEquals($jarray['dependencies'], $info->getDependencies()); self::assertEquals($jarray['dependencies'], $info->getDependencies());
self::assertEquals($jarray['directory'], $info->getDirectory()); self::assertEquals($jarray['directory'], $info->getDirectory());
self::assertEquals($jarray['version'], $info->getVersion()); self::assertEquals($jarray['version'], $info->getVersion());
self::assertEquals($jarray['providing'], $info->getProviding());
self::assertEquals(__DIR__ . '/info-test.json', $info->getPath()); self::assertEquals(__DIR__ . '/info-test.json', $info->getPath());
} }

View File

@ -75,6 +75,8 @@ class ApplicationManagerTest extends \PHPUnit\Framework\TestCase
/** /**
* @covers phpOMS\Application\ApplicationManager * @covers phpOMS\Application\ApplicationManager
* @covers phpOMS\Application\InstallerAbstract
* @covers phpOMS\Application\StatusAbstract
* @group framework * @group framework
*/ */
public function testInstall() : void 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($this->appManager->install(__DIR__ . '/Testapp', __DIR__ . '/Apps/Testapp'));
self::assertTrue(\is_dir(__DIR__ . '/Apps/Testapp')); self::assertTrue(\is_dir(__DIR__ . '/Apps/Testapp'));
self::assertTrue(\is_file(__DIR__ . '/Apps/Testapp/css/styles.css')); 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'); 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')); self::assertFalse($this->appManager->install(__DIR__, __DIR__ . '/newapp', __DIR__ . '/Apps/newapp'));
} }
/**
* @covers phpOMS\Application\ApplicationManager
* @group framework
*/
public function testInstallFromModules() : void
{
self::markTestIncomplete();
}
} }

View File

@ -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'],
]
];

View File

@ -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,
],
],
],
];

View 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
}
}
}
}

View 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
{
}

View File

@ -16,5 +16,8 @@
}, },
"description": "The administration module.", "description": "The administration module.",
"directory": "Admin", "directory": "Admin",
"providing": {
"Navigation": "*"
},
"dependencies": [] "dependencies": []
} }

View File

@ -16,5 +16,8 @@
}, },
"description": "The administration module.", "description": "The administration module.",
"directory": "Admin", "directory": "Admin",
"providing": {
"Navigation": "*"
},
"dependencies": [] "dependencies": []
} }

View File

@ -67,6 +67,20 @@ class EventManagerTest extends \PHPUnit\Framework\TestCase
self::assertEquals(1, $this->event->count()); 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 * @testdox Multiple callbacks can be added to an event
* @covers phpOMS\Event\EventManager * @covers phpOMS\Event\EventManager
@ -196,7 +210,7 @@ class EventManagerTest extends \PHPUnit\Framework\TestCase
* @covers phpOMS\Event\EventManager * @covers phpOMS\Event\EventManager
* @group framework * @group framework
*/ */
public function testNoeReset() : void public function testNoReset() : void
{ {
self::assertTrue($this->event->attach('group', function() { return true; }, false, false)); self::assertTrue($this->event->attach('group', function() { return true; }, false, false));
$this->event->addGroup('group', 'id1'); $this->event->addGroup('group', 'id1');

View File

@ -43,6 +43,8 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
{ {
$this->module = new class() extends ModuleAbstract $this->module = new class() extends ModuleAbstract
{ {
public const PATH = __DIR__ . '/';
const VERSION = '1.2.3'; const VERSION = '1.2.3';
const NAME = 'Test'; const NAME = 'Test';
@ -74,6 +76,20 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
$this->createModel(1, $model, BaseModelMapper::class, '', '127.0.0.1'); $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 public function createRelationModel() : void
{ {
$model = new ManyToManyRelModel(); $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'); $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 public function creates() : void
{ {
$model1 = new BaseModel(); $model1 = new BaseModel();
@ -166,6 +190,16 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
self::assertTrue(\in_array('Test2', $this->module->getReceiving())); 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 * @testdox A invalid language or theme returns in an empty localization/language dataset
* @covers phpOMS\Module\ModuleAbstract<extended> * @covers phpOMS\Module\ModuleAbstract<extended>
@ -334,8 +368,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
{ {
$this->dbSetup(); $this->dbSetup();
$this->module->create(); $this->module->createMultiple();
$this->module->create();
self::assertCount(2, BaseModelMapper::getAll()); self::assertCount(2, BaseModelMapper::getAll());
$this->dbTeardown(); $this->dbTeardown();
@ -391,6 +424,13 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
$model = BaseModelMapper::get(1); $model = BaseModelMapper::get(1);
self::assertCount(1, $model->hasManyRelations); self::assertCount(1, $model->hasManyRelations);
BaseModelMapper::clearCache();
$this->module->deleteRelationDB();
BaseModelMapper::clearCache();
$model = BaseModelMapper::get(1);
self::assertCount(0, $model->hasManyRelations);
$this->dbTeardown(); $this->dbTeardown();
} }
} }

View File

@ -211,6 +211,7 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
/** /**
* @testdox A module can be re-initialized * @testdox A module can be re-initialized
* @covers phpOMS\Module\ModuleManager * @covers phpOMS\Module\ModuleManager
* @covers phpOMS\Module\StatusAbstract
* @group framework * @group framework
*/ */
public function testReInit() : void public function testReInit() : void
@ -282,6 +283,11 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
$this->moduleManager->uninstall('TestModule'); $this->moduleManager->uninstall('TestModule');
self::assertFalse($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->isActive('TestModule'));
self::assertFalse($this->moduleManager->isRunning('TestModule')); self::assertFalse($this->moduleManager->isRunning('TestModule'));
} }

View 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',
]
];

View File

@ -83,22 +83,21 @@ class TarTest extends \PHPUnit\Framework\TestCase
\unlink(__DIR__ . '/test.tar'); \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 // second test
self::assertTrue(Tar::pack( self::assertTrue(Tar::pack(
[__DIR__ . '/test' => 'test'], __DIR__ . '/test',
__DIR__ . '/test.tar' __DIR__ . '/test.tar'
)); ));
self::assertTrue(Tar::unpack(__DIR__ . '/test.tar', __DIR__ . '/new_dir')); self::assertTrue(Tar::unpack(__DIR__ . '/test.tar', __DIR__ . '/new_dir'));
self::assertFileExists(__DIR__ . '/new_dir/test'); self::assertFileExists(__DIR__ . '/new_dir');
self::assertEquals($c, \file_get_contents(__DIR__ . '/new_dir/test/test c.txt')); 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 c.txt');
\unlink(__DIR__ . '/new_dir/test/test d.txt'); \unlink(__DIR__ . '/new_dir/test d.txt');
\unlink(__DIR__ . '/new_dir/test/sub/test e.txt'); \unlink(__DIR__ . '/new_dir/sub/test e.txt');
\rmdir(__DIR__ . '/new_dir/test/sub'); \rmdir(__DIR__ . '/new_dir/sub');
\rmdir(__DIR__ . '/new_dir/test');
\rmdir(__DIR__ . '/new_dir'); \rmdir(__DIR__ . '/new_dir');
\unlink(__DIR__ . '/test.tar'); \unlink(__DIR__ . '/test.tar');

View File

@ -91,14 +91,13 @@ class ZipTest extends \PHPUnit\Framework\TestCase
)); ));
self::assertTrue(Zip::unpack(__DIR__ . '/test.zip', __DIR__ . '/new_dir')); self::assertTrue(Zip::unpack(__DIR__ . '/test.zip', __DIR__ . '/new_dir'));
self::assertFileExists(__DIR__ . '/new_dir/test'); self::assertFileExists(__DIR__ . '/new_dir');
self::assertEquals($c, \file_get_contents(__DIR__ . '/new_dir/test/test c.txt')); 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 c.txt');
\unlink(__DIR__ . '/new_dir/test/test d.txt'); \unlink(__DIR__ . '/new_dir/test d.txt');
\unlink(__DIR__ . '/new_dir/test/sub/test e.txt'); \unlink(__DIR__ . '/new_dir/sub/test e.txt');
\rmdir(__DIR__ . '/new_dir/test/sub'); \rmdir(__DIR__ . '/new_dir/sub');
\rmdir(__DIR__ . '/new_dir/test');
\rmdir(__DIR__ . '/new_dir'); \rmdir(__DIR__ . '/new_dir');
\unlink(__DIR__ . '/test.zip'); \unlink(__DIR__ . '/test.zip');

View File

@ -398,7 +398,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
{ {
$view = new View(); $view = new View();
$view->setTemplate('/phpOMS/tests/Views/testTemplate'); $view->setTemplate('/phpOMS/tests/Views/testReturnTemplate');
self::assertEquals('<strong>Test</strong>', $view->build()); self::assertEquals('<strong>Test</strong>', $view->build());
} }

View File

@ -0,0 +1,2 @@
<?php
return '<strong>Test</strong>';