diff --git a/Application/InstallerAbstract.php b/Application/InstallerAbstract.php index 61347d46c..318464559 100644 --- a/Application/InstallerAbstract.php +++ b/Application/InstallerAbstract.php @@ -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. * diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 0d3c4547e..e88f5c566 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -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']) diff --git a/Event/EventManager.php b/Event/EventManager.php index 60fdb1f67..4528cd8ab 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -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) { diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index 5d0e832dd..1e68e93a0 100644 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -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; } diff --git a/tests/Application/ApplicationInfoTest.php b/tests/Application/ApplicationInfoTest.php index 162109db5..6152c224a 100644 --- a/tests/Application/ApplicationInfoTest.php +++ b/tests/Application/ApplicationInfoTest.php @@ -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()); } diff --git a/tests/Application/ApplicationManagerTest.php b/tests/Application/ApplicationManagerTest.php index f2d2e1386..8df0fc9c5 100644 --- a/tests/Application/ApplicationManagerTest.php +++ b/tests/Application/ApplicationManagerTest.php @@ -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(); - } } diff --git a/tests/Application/Testapp/Admin/Install/Application/Hooks.php b/tests/Application/Testapp/Admin/Install/Application/Hooks.php new file mode 100644 index 000000000..beb77a656 --- /dev/null +++ b/tests/Application/Testapp/Admin/Install/Application/Hooks.php @@ -0,0 +1,19 @@ + [ + 'callback' => ['\phpOMS\tess\Application\Apps\Testapp\Controller\Controller:testHook'], + ] +]; diff --git a/tests/Application/Testapp/Admin/Install/Application/Routes.php b/tests/Application/Testapp/Admin/Install/Application/Routes.php new file mode 100644 index 000000000..99034c94c --- /dev/null +++ b/tests/Application/Testapp/Admin/Install/Application/Routes.php @@ -0,0 +1,28 @@ + [ + [ + 'dest' => '\phpOMS\tess\Application\Apps\Testapp\Controller\Controller:testEndpoint', + 'verb' => RouteVerb::GET, + 'permission' => [ + 'type' => 1, + 'state' => 2, + ], + ], + ], +]; diff --git a/tests/Application/Testapp/Admin/Install/db.json b/tests/Application/Testapp/Admin/Install/db.json new file mode 100644 index 000000000..7622c9bc3 --- /dev/null +++ b/tests/Application/Testapp/Admin/Install/db.json @@ -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 + } + } + } +} \ No newline at end of file diff --git a/tests/Application/Testapp/Controller/Controller.php b/tests/Application/Testapp/Controller/Controller.php new file mode 100644 index 000000000..3d522f21b --- /dev/null +++ b/tests/Application/Testapp/Controller/Controller.php @@ -0,0 +1,29 @@ +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'); diff --git a/tests/Module/ModuleAbstractTest.php b/tests/Module/ModuleAbstractTest.php index 8536739bc..93bd9f06d 100644 --- a/tests/Module/ModuleAbstractTest.php +++ b/tests/Module/ModuleAbstractTest.php @@ -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 + * @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 @@ -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(); } } diff --git a/tests/Module/ModuleManagerTest.php b/tests/Module/ModuleManagerTest.php index d6e7a705a..faca88c90 100644 --- a/tests/Module/ModuleManagerTest.php +++ b/tests/Module/ModuleManagerTest.php @@ -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')); } diff --git a/tests/Module/Test/Theme/Mytheme/Lang/en.lang.php b/tests/Module/Test/Theme/Mytheme/Lang/en.lang.php new file mode 100644 index 000000000..d6f238bdb --- /dev/null +++ b/tests/Module/Test/Theme/Mytheme/Lang/en.lang.php @@ -0,0 +1,18 @@ + [ + 'Key' => 'Value', +] +]; \ No newline at end of file diff --git a/tests/Utils/IO/Zip/TarTest.php b/tests/Utils/IO/Zip/TarTest.php index 671b0bc3e..13004e015 100644 --- a/tests/Utils/IO/Zip/TarTest.php +++ b/tests/Utils/IO/Zip/TarTest.php @@ -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'); diff --git a/tests/Utils/IO/Zip/ZipTest.php b/tests/Utils/IO/Zip/ZipTest.php index 8d247f03e..f552ec567 100644 --- a/tests/Utils/IO/Zip/ZipTest.php +++ b/tests/Utils/IO/Zip/ZipTest.php @@ -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'); diff --git a/tests/Views/ViewTest.php b/tests/Views/ViewTest.php index 78c782d1d..77d24cf46 100644 --- a/tests/Views/ViewTest.php +++ b/tests/Views/ViewTest.php @@ -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('Test', $view->build()); } diff --git a/tests/Views/testReturnTemplate.tpl.php b/tests/Views/testReturnTemplate.tpl.php new file mode 100644 index 000000000..edc000a60 --- /dev/null +++ b/tests/Views/testReturnTemplate.tpl.php @@ -0,0 +1,2 @@ +Test';